ESP32 Starter Kit
Code
/*
keyestudio ESP32 Inventor Learning Kit
Project 20.2 Light Pillar
http://www.keyestudio.com
*/
#include "LedControl.h"
int DIN = 23;
int CLK = 18;
int CS = 15;
LedControl lc=LedControl(DIN,CLK,CS,1);
const byte IMAGES[8] = {0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF}; //Data of light pillar
int light = 34;
void setup() {
lc.shutdown(0,false);
// Set brightness to a medium value
lc.setIntensity(0,8);
// Clear the display
lc.clearDisplay(0);
pinMode(light,INPUT);
}
void loop(){
int value = analogRead(light);
int temp = map(value,0,4095,0,7); //Convert the range of analog values to 0-7
lc.setRow(0,3,IMAGES[temp]); //Display the value of the array IMAGES[temp] in␣
˓→column 3
lc.setRow(0,4,IMAGES[temp]); //Display the value of the array IMAGES[temp] in␣
˓→column 4
}
8.5.22 Project 21: Sound Controlled LED
1. Description
Sound controlled LED is a device used to detect sound in a way that controls the brightness of LED, which is composed
of a Arduino board and some components. It can connect to multiple sensors such as microphones. It converts sound
to changing voltage signal to be received by Arduino to control the LED on and off.
120 Chapter 8. Arduino Tutorial