EasyManua.ls Logo

SunFounder 3in1 Kit - Page 202

Default Icon
351 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SunFounder 3in1 Kit
light_control_led.
Or copy this code into Arduino IDE.
Now, shine some light on the photoresistor, and you will see several LEDs light up. Shine more light and you will see
more LEDs light up. When you place it in a dark environment, all the LEDs will go out.
How it works?
void loop()
{
sensorValue = analogRead(photocellPin); //read the value of A0
ledLevel = map(sensorValue, 300, 1023, 0, NbrLEDs); // map to the number of LEDs
for (int led = 0; led < NbrLEDs; led++)//
{
if (led < ledLevel ) //When led is smaller than ledLevel, run the following code.
{
digitalWrite(ledPins[led], HIGH); // turn on pins less than the level
}
else
{
digitalWrite(ledPins[led],LOW); // turn off pins higher than
}
}
}
By using the map() function, you can map the photoresistor value to the 8 LEDs, for example, if sensorValue is 560,
then ledLevel is 4, so at this point, ledPins[0] to ledPins[4] should be lit, and ledPins[5] to ledPins[7] should be off.
4.6.2 6.2 Digital Dice
Here we use button, 7-segment and 74hc595 to make an electronic dice. Each time the button is pressed, a random
number ranging from 1 to 6 is generated and displayed on the 7-segment Display.
Required Components
In this project, we need the following components.
Its definitely convenient to buy a whole kit, here’s the link:
Name ITEMS IN THIS KIT LINK
3 in 1 Starter Kit 380+
You can also buy them separately from the links below.
198 Chapter 4. Basic Projects

Related product manuals