Page 36
Circuit 2
Arduino Code:
4
Troubleshooting:
Some LEDs Fail to Light
It is easy to insert an LED backwards. Check the LEDs
that aren't working and ensure they the right way
around.
Operating out of sequence
With eight wires it's easy to cross a couple. Double check
that the first LED is plugged into pin 2 and each pin
there after.
Starting Afresh
Its easy to accidentally misplace a wire without noticing.
Pulling everything out and starting with a fresh slate is
often easier than trying to track down the problem.
This is similar to circuit number one, but
instead of one LED, you should see all the
LEDs blink. If they aren't, make sure you
have assembled the circuit correctly and
verified and uploaded the code to your board
or see the troubleshooting tips below.
Code to Note:
Real World Application:
Scrolling marquee displays are generally used to spread
short segments of important information. They are built
out of many LEDs.
Open Arduino IDE
//
File > Examples > SIK Guide >
Circuit # 4
What you Should See:
IOREF
RES
ET
RESET
7-15V
SCL
SDA
AREF
GND
13
12
~11
~10
~9
8
7
~6
~5
4
~3
2
1
0
TX
RX
13
3.3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POWER
ANALOG IN
DIGIT
AL (PWM~)
ON
ISP
TX
RX
IOREF
RES
ET
RESET
7-15V
SCL
SDA
AREF
GND
13
12
~11
~10
~9
8
7
~6
~5
4
~3
2
1
0
TX
RX
13
3.3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POWER
ANALOG IN
DIGIT
AL (PWM~)
ON
ISP
TX
RX
LEARN. SHARE. HACK.
When you have to manage a lot of variables, an "array" is
a handy way to group them together. Here we're creating
an array of integers, called ledPins, with eight elements.
int ledPins[] = {2,3,4,5,6,7,8,9};
Computers like to do the same things each time they run. But sometimes
you want to do things randomly, such as simulating the roll of a dice. The
random() function is a great way to do this.
See
http://arduino.cc/en/reference/random
for more information.
index = random(8);
You refer to the elements in an array by their position.
The first element is at position 0, the second is at position
1, etc. You refer to an element using "ledPins[x]" where x
is the position. Here we're making digital pin 2 HIGH,
since the array element at position 0 is "2".
digitalWrite(ledPins[0], HIGH);
Summary of Contents for RedBoard
Page 13: ...Page 11...