//loop back to the top
}
Code to Note
int sensorValue;
A "variable" is a placeholder for values that may change in your code. You
must introduce, or "declare," variables before you use them; here you are
declaring a variable called sensorValue, of type "int" (integer). Don't forget
that variable names are case sensitive!
sensorValue = analogRead(sensorPin);
Use the
function to read the value on an analog pin.
analogRead()
takes one parameter, the analog pin you want to use
analogRead()
("sensorPin"), and returns a number ("sensorValue") between 0 (0 volts)
and 1023 (3.3 volts).
delay(sensorValue);
Microcontrollers are very fast, capable of running thousands of lines of code
each second. To slow it down so that we can see what it's doing, we'll often
insert delays into the code.
delay()
ms in one second.
What You Should See
You should see the LED blink faster or slower in accordance with your
potentiometer. If it isn't working, make sure you have assembled the circuit
correctly and verified and uploaded the code to your board, or see the
Troubleshooting section.
Troubleshooting
Sporadically Working
This is most likely due to a slightly dodgy connection with the
potentiometer's pins. This can usually be conquered by holding the
potentiometer down or moving the potentiometer circuit somewhere else on
your breadboard.
Not Working
Make sure you haven't accidentally connected the wiper (center pin), the
resistive element in the potentiometer, to digital pin 0 rather than analog pin
0 (the row of pins beneath the power pins).
LED Not Lighting Up
LEDs will only work in one direction. Double check your connections.
Experiment 3: Driving an RGB LED
Introduction
counts in milliseconds; there are 1,000
Page 14 of 63
Need help?
Do you have a question about the Tinker Kit and is the answer not in the manual?
Questions and answers