Download Arduino Starter Kit Manual PDF

TitleArduino Starter Kit Manual
LanguageEnglish
File Size8.1 MB
Total Pages101
Document Text Contents
Page 1

Earthshine Electronics

Arduino Starter Kit Manual
A Complete Beginners Guide to the Arduino

©2009 M.McRoberts - Earthshine Design www.EarthshineElectronics.com

www.EarthshineElectronics.com

http://www.EarthshineDesign.co.uk
http://www.EarthshineDesign.co.uk
http://www.EarthshineElectronics.com
http://www.EarthshineElectronics.com

Page 2

Earthshine Electronics Arduino Starters Kit Manual - A Complete Beginners Guide to the Arduino
www.EarthshineElectronics.com

2

Earthshine Design

Arduino Starters Kit Manual

A Complete Beginners guide to the Arduino

By Mike McRoberts

www.EarthshineElectronics.com

http://www.earthshineElectronics.com
http://www.earthshineElectronics.com
http://www.EarthshineElectronics.com
http://www.EarthshineElectronics.com

Page 50

Earthshine Design Arduino Starters Kit Manual - A Complete Beginners Guide to the Arduino

50

Project 8
Mood Lamp

Page 51

Earthshine Design Arduino Starters Kit Manual - A Complete Beginners Guide to the Arduino

51

Project 8 - Mood Lamp
In the last project we saw that we could adjust the
brightness of an LED using the PWM capabilities of
the Atmega chip. We will now take advantage of this
capability by using a red, green and blue LED and by
mixing their colours to create any colour we wish.
From that, we will create a mood lamp similar to the
kind you see for sale all over the place nowadays.

What you will need

Red Clear LED

Green Clear LED

Blue Clear LED

3 x 220Ω Resistor

Connect it up

Get a piece of paper about A5 size, roll it into a
cylinder then tape it so it remains that way. Then place
the cylinder over the top of the 3 LEDʼs.

Enter the code

When you run this you will see the colours slowly
change. Youʼve just made youʼre own mood lamp.

// Project 8 - Mood Lamp
float RGB1[3];
float RGB2[3];
float INC[3];

int red, green, blue;

int RedPin = 11;
int GreenPin = 10;
int BluePin = 9;

void setup()
{
Serial.begin(9600);
randomSeed(analogRead(0));

RGB1[0] = 0;
RGB1[1] = 0;
RGB1[2] = 0;

RGB2[0] = random(256);
RGB2[1] = random(256);
RGB2[2] = random(256);
}

void loop()
{
randomSeed(analogRead(0));

for (int x=0; x<3; x++) {
INC[x] = (RGB1[x] - RGB2[x]) / 256; }

for (int x=0; x<256; x++) {

red = int(RGB1[0]);
green = int(RGB1[1]);
blue = int(RGB1[2]);

analogWrite (RedPin, red);
analogWrite (GreenPin, green);
analogWrite (BluePin, blue);
delay(100);

RGB1[0] -= INC[0];
RGB1[1] -= INC[1];
RGB1[2] -= INC[2];
}
for (int x=0; x<3; x++) {
RGB2[x] = random(556)-300;
RGB2[x] = constrain(RGB2[x], 0, 255);
delay(1000);
}
}

Page 100

Earthshine Design Arduino Starters Kit Manual - A Complete Beginners Guide to the Arduino

100

We now have the screenUpdate function. This is the
function that the interrupt is activating every 100th of a
second. This whole routine is very important as it is
responsible for ensuring our LEDʼs in the DOt Matrix
array are lit correctly and displays the image we wish
to convey. It is a very simple but very effective
function.

void screenUpdate() {
uint8_t row = B00000001;
for (byte k = 0; k < 9; k++) {
// Open up the latch ready to receive
data
! digitalWrite(latchPin, LOW);
shiftIt(~row );
shiftIt(led[k] ); // LED array

// Close the latch, sending the data in
the registers out to the matrix
digitalWrite(latchPin, HIGH); row = row
<< 1;
}
}

An 8 bit integer called ʻrowʼ is declared and initialised
with the value B00000001.

uint8_t row = B00000001;

We now simply cycle through the led array and send
that data out to the Shift Registers preceded by the
row (which is processed with the bitwise NOT ~ to
make sure the row we want to display is turned off, or
grounded).

for (byte k = 0; k < 9; k++) {
// Open up the latch ready to receive
data
! digitalWrite(latchPin, LOW);
shiftIt(~row );
shiftIt(led[k] ); // LED array

Once we have shifted out that current rows 8 bits the
value in row is bitshifted left 1 place so that the next
row is displayed.

row = row << 1;

Remember from the hardware overview that the
multiplexing routine is only displaying one row at a
time, turning it off and then displaying the next row.
This is done at 100Hz which is too fast for the human
eye to see the flicker.

Finally, we have a ShiftOut function, the same as in
the previous Shift Register based projects, that sends
the data out to the 74HC595 chips.

void shiftIt(byte dataOut)

So, the basic concept here is that we have an interruot
routine that executes every 100th of a second. In that
routine we simply take a look at the contents of a
screen buffer array (in this case led[] ) and display it
on the dot matrix unit one row at a time, but do this so
fast that to the human eye it all seems to be lit at once.

The main loop of the program is simply changing the
contents of the screen buffer array and letting the ISR
do the rest.

The animation in this project is very simple, but by
manipulating the 1ʼs and 0ʼs in the buffer we can make
anything we like appear on the Dot Matrix unit from
shapes to scrolling text.

Page 101

Earthshine Design Arduino Starters Kit Manual - A Complete Beginners Guide to the Arduino

101

Brought to you by

www.EarthshineElectronics.com

The producer of the greatest
Arduino Starter Kits

on the planet.

[email protected]
© 2009

http://www.EarthshineElectronics.com
http://www.EarthshineElectronics.com
mailto:[email protected]
mailto:[email protected]

Similer Documents