Saturday, September 19, 2009

Arduino: M rocks!

0. Starting wires, circuits and LED




1. Two LEDs controled by two signal inputs from Arduino

2. Smart surface!


3. Go blue!


4. Ready for M-rock?




5. Codes: the hardest part is timing

// This program follows the song We will rock you by Queen.
int redPin = 12; // Red LED connected to digital pin 12
int bluePin = 11; //blue LED connected to digital pin 11

void setup() // run once, when the sketch starts
{
pinMode(redPin, OUTPUT); // sets the digital pin as output
pinMode(bluePin, OUTPUT); // sets the digital pin as output
}

void loop() // run over and over again
{
delay(300);
digitalWrite(bluePin, HIGH); // sets the blue LED on
delay(400);
digitalWrite(bluePin, LOW); // sets the blue LED off
delay(350);
digitalWrite(bluePin, HIGH); // sets the blue LED on
delay(400);
digitalWrite(bluePin, LOW); // sets the blue LED off
delay(350);

digitalWrite(bluePin, HIGH); // sets the blue LED on
delay(400);
digitalWrite(bluePin, LOW); // sets the blue LED off
delay(350);
digitalWrite(bluePin, HIGH); // sets the blue LED on
delay(500);
digitalWrite(bluePin, LOW); // sets the blue LED off
delay(250);

digitalWrite(redPin, HIGH); // sets the red LED on
delay(200);
digitalWrite(redPin, LOW); // sets the red LED off
delay(350);
digitalWrite(redPin, HIGH); // sets the red LED on
delay(700);
digitalWrite(redPin, LOW); // sets the red LED off
delay(1500);
digitalWrite(bluePin, HIGH); // sets the blue LED on
delay(500);
digitalWrite(bluePin, LOW); // sets the blue LED off
delay(350);
digitalWrite(bluePin, HIGH); // sets the blue LED on
delay(500);
digitalWrite(bluePin, LOW); // sets the blue LED off
delay(350);

digitalWrite(bluePin, HIGH); // sets the blue LED on
delay(400);
digitalWrite(bluePin, LOW); // sets the blue LED off
delay(350);
digitalWrite(bluePin, HIGH); // sets the blue LED on
delay(500);
digitalWrite(bluePin, LOW); // sets the blue LED off
delay(250);

digitalWrite(redPin, HIGH); // sets the red LED on
delay(200);
digitalWrite(redPin, LOW); // sets the red LED off
delay(350);
digitalWrite(redPin, HIGH); // sets the red LED on
delay(700);
digitalWrite(redPin, LOW); // sets the red LED off
delay(1000);
digitalWrite(redPin, HIGH); // sets the red LED on
digitalWrite(bluePin, HIGH); // sets the blue LED on
delay(700);
digitalWrite(redPin, LOW); // sets the red LED off
digitalWrite(bluePin, LOW); // sets the blue LED off
}

No comments:

Post a Comment