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/dkpxbn )(and then copy the text and paste it into an empty Arduino Sketch)CIRC-02//LED Pin Variables* will then turn them offint ledPins[] = {2,3,4,5,6,7,8,9};//An array to hold thevoid oneAfterAnotherNoLoop(){//pin each LED is connected to int delayTime = 100;/ / i . e . L E D # 0 i s c o n n e c t e d t o p i n 2 / / t h e t i m e ( i n m i l l i s e c o n d s ) t o p a u s e//between LEDsvoid setup() digitalWrite(ledPins[0], HIGH); //Turns on LED #0{ //(connected to pin 2)for(int i = 0; i < 8; i++){ delay(delayTime); //waits delayTime milliseconds//this is a loop and will repeat eight times ...pinMode(ledPins[i],OUTPUT); ...//we use this to set LED pins to output digitalWrite(ledPins[7], HIGH); //Turns on LED #7} //(connected to pin 9)} delay(delayTime); //waits delayTime milliseconds//Turns Each LED Offvoid loop() // run over and over again digitalWrite(ledPins[7], LOW); //Turns off LED #7{ delay(delayTime); //waits delayTime millisecondsoneAfterAnotherNoLoop(); ...//this will turn on each LED one by//one then turn each oneoff-----more code in the downloadable version------//oneAfterAnotherLoop();//this does the same as onAfterAnotherNoLoop//but with much less typing//oneOnAtATime();//inAndOut();}/** oneAfterAnotherNoLoop() - Will light one then* delay for delayTime then light the next LED itNot Working? (3 things to try)Some LEDs Fail to LightIt is easy to insert an LEDbackwards. Check the LEDsthat aren't working and ensurethey the right way around.Operating out of sequenceWith eight wires it's easy to crossa couple. Double check that thefirst LED is plugged into pin 2 andeach pin there after.Starting AfreshIts easy to accidentallymisplace a wire withoutnoticing. Pulling everything outand starting with a fresh slateis often easier than trying totrack down the problem.Making it BetterSwitching to Loops:in the loop() function there are 4 lines. The lastthree all start with a '//' this means the line istreated as a comment (not run). To switch theprogram to use loops change the void loop()code to://oneAfterAnotherNoLoop();oneAfterAnotherLoop();//oneOnAtATime();//inAndOut();Upload the program, and notice that nothing haschanged. You can take a look at the twofunctions, each does the same thing, but usedifferent approaches (hint the second one uses afor loop)Extra Animations:Tired of this animation? Then try the other twosample animations. Uncomment their lines andupload the program to your board and enjoy the newlight animations. (delete the slashes in front of row 3 and then 4)Testing out your own Animations:Jump into the included code and start changingthings. The main point is to turn an LED on usedigitalWrite(pinNumber, HIGH); then toturn it off use digitalWrite(pinNumber,LOW); . Type away, regardless of what you changeyou won't break anything.More, More, More:More details, where to buy more parts, where to ask more questions.http://tinyurl.com/d2hrud11

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

Saved successfully!

Ooh no, something went wrong!