11.07.2015 Views

ARDX-experimenters-g.. - Oomlout

ARDX-experimenters-g.. - Oomlout

ARDX-experimenters-g.. - Oomlout

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Code (no need to type everything in just)Download the Code from ( http://tinyurl.com/cv4fjt )(copy the text and paste it into an empty Arduino Sketch)//Pin Definitions//The 74HC595 uses a protocol called SPI//Which has three pinsint data = 2;int clock = 3;int latch = 4;digitalWrite(latch, LOW);CIRC-05//Pulls the chips latch lowshiftOut(data, clock, MSBFIRST, value);void setup() //runs once //Shifts out 8 bits to the shift register{pinMode(data, OUTPUT);pinMode(clock, OUTPUT);digitalWrite(latch, HIGH);pinMode(latch, OUTPUT); } //Pulls the latch high displaying the data}void loop() // run over and over again{ ---------- More Code Online ----------int delayTime = 100;//delay between LED updatesfor(int i = 0; i < 256; i++){updateLEDs(i);delay(delayTime); }}/** updateLEDs() - sends the LED states set* in value to the 74HC595 sequence*/void updateLEDs(int value){Not Working? (3 things to try)The Arduino’s PowerLED goes outThis happened to us a coupleof times, it happens when thechip is inserted backwards. Ifyou fix it quickly nothing willbreak.Not Quite WorkingSorry to sound like a brokenrecord but it is probablysomething as simple as acrossed wire.Frustration?Shoot us an e-mail, this circuitis both simple and complex atthe same time. We want tohear about problems you haveso we can address them infuture editions.help@oomlout.comMaking it BetterDoing it the hard way:An Arduino makes rather complex actions very easy, shifting out datais one of these cases. However one of the nice features of anArduino is you can make things as easy or difficult as you like. Letstry an example of this. In your loop switch the line.updateLEDs(i) -> updateLEDsLong(i);Upload the program and notice nothing has changed. If you look atthe code you can see how we are communicating with the chip onebit at a time. (for more details http://tinyurl.com/3augzd )Controlling Individual LEDs:Time to start controlling the LEDs in a similar method as we did inCIRC02. As the eight LED states are stored in one byte (an 8 bitvalue) for details on how this works try http://tinyurl.com/6vz53. AnArduino is very good at manipulating bits and there are an entire setof operators that help us out. Details on bitwise maths (http://tinyurl.com/br8dd )Our implementation.Replace the loop() code withint delayTime = 100; //the number ofmilliseconds to delay//between LED updatesfor(int i = 0; i < 8; i++){changeLED(i,ON);delay(delayTime);}for(int i = 0; i < 8; i++){changeLED(i,OFF);delay(delayTime);}And upload this will cause the lights to light up one after another and thenoff in a similar manner. Check the code and wikipedia to see how it works,or shoot us an e-mail if you have questions.More Animations:Now things get more interesting. If you look back to the code from CIRC02(8 LED Fun) you see we change the LEDs using digitalWrite(led, state), thisis the same format as the routine we wrote changeLED(led, state). You canuse the animations you wrote for CIRC02 by copying the code into thissketch and changing all the digitalWrite()'s to changeLED()'s. Powerful?Very. (you'll also need to change a few other things but follow the compileerrors and it works itself out)More, More, More:More details, where to buy more parts, where to ask more questions.http://tinyurl.com/dkjno317

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!