08 March 2010

LED Project - due 12 March 2010 - software


/*
* Project: LED-Project_3-LED-blinks_12mar10
* Author: Jane-Maree Howard
* Date: Monday 08/03/2010
* Platform: Arduino 18
* Purpose: To demonstrate variable blink times for external 3-colour LED
* Operation: Sets up output pins (4 off) in setup() method;
* Declares pin definition variables (4 off)
* Defines loop() to perform various LED blinking & delay operations
* Here we use a 3-colour LED and first turn them all ON, then OFF.
* Then we successively blink the RED, GREEN & BLUE
* LEDs, each with the same delay time, which ramps
* from 10ms up to 200 millisec & back down again.
* Here we use two 'for-loops': one to ramp up the Delays, &
* the other to ramp them back down again
*/

int ledPin = 13; // on-board LED connected to digital pin 13
int redLedPin = 12; // RED LED connected to digital pin 12
int grnLedPin = 11; // GREEN LED connected to digital pin 11
int bluLedPin = 10; // BLUE LED connected to digital pin 10
// the variable delay is accomplished by..
int iMult; // ..the multiplier variable multiplied by..
int dLay = 10; // ..the delay variable, which is 10 milliseconds

// The setup() method runs once, when the sketch starts
void setup()
{
// initialize the 4 digital pins as outputs:
pinMode(ledPin, OUTPUT);
pinMode(redLedPin, OUTPUT); // Red LED output
pinMode(grnLedPin, OUTPUT); // Green LED output
pinMode(bluLedPin, OUTPUT); // Blue LED output
// turn on the on-board LED & wait 0.5 seconds
digitalWrite(ledPin, HIGH); // turn on-board LED on
delay(dLay*50); // delay 0.5 seconds (50 * 10ms)
}//end setup()

// Loop first turns all 3 LEDs on succesively, then turns them off again.
// Delay between each phase is about 100 milliseconds
// Loop now turns RED, GREEN & BLUE LEDs on & off cyclically
// with varying delay each time loop runs, &..
// ..repeats endlessly while Arduino has power

// At the half-way point the order of the LED-cycle is reversed;
// Viewers should try to spot this point! What indicates this?

void loop()
{
digitalWrite(redLedPin, HIGH); // turn red LED on
delay(50*dLay); // delay 500 milliseconds
digitalWrite(grnLedPin, HIGH); // turn green LED on
delay(50*dLay); // delay 500 milliseconds
digitalWrite(bluLedPin, HIGH); // turn blue LED on
delay(100*dLay); // delay 1 second
// Now turn them all off..
digitalWrite(redLedPin, LOW);
digitalWrite(grnLedPin, LOW);
digitalWrite(bluLedPin, LOW);
delay(50*dLay); // ..& wait 0.5 seconds

// Ramps delays UP - Red, Green & Blue LEDs each turn on, then off,
// with the delay time increasing with each for-loop cycle
// from 10 - 200 milliseconds
for (iMult=1; iMult<=20; iMult++ ) // now start 'increasing delay' for-loop { digitalWrite(redLedPin, HIGH); // turn red LED on.. delay(iMult*dLay); // ..delay 10millisec * multiplier.. digitalWrite(redLedPin, LOW); // ..turn red LED off &.. digitalWrite(grnLedPin, HIGH); // ..turn green LED on.. delay(iMult*dLay); // ..delay 10millisec * multiplier.. digitalWrite(grnLedPin, LOW); // ..turn green LED off &.. digitalWrite(bluLedPin, HIGH); // ..turn blue LED on.. delay(iMult*dLay); // ..delay 10millisec * multiplier.. digitalWrite(bluLedPin, LOW); // ..turn blue LED off delay(iMult*dLay); // ..delay 10millisec * multiplier. }//end for(iMult++) // Ramps delays DOWN again - Blue, Green & Red LEDs each turn on, then off, // with the delay time decreasing with each for-loop cycle // Note REVERSED ORDER now Blue-Green-Red for (iMult=20; iMult>=1; iMult-- ) // now start 'decreasing delay' for-loop
{
digitalWrite(bluLedPin, HIGH); // ..turn blue LED on..
delay(iMult*dLay); // ..delay 10millisec * multiplier..
digitalWrite(bluLedPin, LOW); // ..turn blue LED off
delay(iMult*dLay); // ..delay 10millisec * multiplier..
digitalWrite(grnLedPin, HIGH); // ..turn green LED on..
delay(iMult*dLay); // ..delay 10millisec * multiplier..
digitalWrite(grnLedPin, LOW); // ..turn green LED off &..
digitalWrite(redLedPin, HIGH); // ..turn red LED on..
delay(iMult*dLay); // ..delay 10millisec * multiplier..
digitalWrite(redLedPin, LOW); // ..turn red LED off &..
delay(iMult*dLay); // ..delay 10millisec * multiplier
}////end for(iMult--)

//..& repeat
}//end loop()


5 comments:

  1. I'm just a little worried about the buffer resistors (current-limiting).
    They're SO SMALL i can barely interpret the colour band coding!
    They seem (i THINK!!) to be about 100 Ohms..
    Dollar-1-2-3 store here-i-come for a cheap magnifying glass (maybe one of those Fresnel things)..
    ..plus a (cheap) digital multimeter (from DSE or sumwere :-$ )

    ReplyDelete
  2. That's enuf 4 1 day..
    ..going home..
    ..i'm HUNGRY & it's getting on 4 8pm!

    mayb i shd buy a (cheap) camera..
    ..neva bn in2 fotografy (use 2 h8 fotos of moi!)

    ReplyDelete
  3. The comment about the second delay-loop SHOULD (of course) read:
    //now start 'DECREASING delay' for-loop

    ReplyDelete
  4. i bought some more components:
    small el-cheapo digital multimeter;
    150 Ohm resistors, lotsa LEDs..

    As i suspected, those original resistors were 100 Ohms (2) & 470 Ohms.
    With a 5V supply & 100 Ohms, less about 1.5V across the LED, the current'd've been about 35 mA.
    Now it should be about 23 mA..

    i'm probably NOT gonna blow the LEDs but..

    ..they're still nice & bright - should make good pics!

    ReplyDelete