Instructables

Arduino animatronics- make your awesome costumes more awesome!

FeaturedContest WinnerContest Winner

Step 5: Now let's have some fun!

Picture of Now let's have some fun!
Example1Arduino_bb.jpg
Example 1- LEDs
 
This is really simple- we're going to make two LEDs blink and another LED fade. The code will run over and over as soon as you apply power.

It's really easy to set up circuits like this using a breadboard. With each example I'll show how to wire everything up using either the servo board or an Arduino.

Copy and paste this sketch into your Arduino window-

/*
 * Example 1
 * LED Control
 * This example will blink two LEDs and then fade another LED
 * Honus 2010
 * Fading code created 1 Nov 2008 by David A. Mellis, modified 17 June 2009 by Tom Igoe
*/
  
 
   int ledPin1 = 13;  // control pin for LED 
   int ledPin2 = 12;
   int ledPin3 = 11;
  
 
 
   void setup() {
   pinMode(ledPin1, OUTPUT);  // sets the LED pin as output
   pinMode(ledPin2, OUTPUT);
   digitalWrite(ledPin1, LOW);  // sets the LED pin LOW (turns it off)
   digitalWrite(ledPin2, LOW);
  }
 
   void loop()
  {
 
   digitalWrite(ledPin1, HIGH);   // sets the LED pin HIGH (turns it on)
   delay(500);                    // waits 500 milliseconds
   digitalWrite(ledPin2, HIGH);
   delay(500);
   digitalWrite(ledPin1, LOW);    // sets the LED pin LOW (turns it off)
   delay(500);
   digitalWrite(ledPin2, LOW);
   delay(500);
 
  
   // fade in from min to max in increments of 5 points:
  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin3, fadeValue);        
    // wait for 30 milliseconds to see the dimming effect   
    delay(40);                           
  }

  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin3, fadeValue);        
    // wait for 30 milliseconds to see the dimming effect   
    delay(40);                           
  }
  delay (2000); // wait two seconds 
  }
 
 



 
Remove these adsRemove these ads by Signing Up