06 March 2010

Task 20 revised - ramping the LED rate UP then DOWN again

/*
* Project: Blink2-Task 20 revised
* Author: Jane-Maree Howard
* Date: Saturday 06/03/2010
* Platform: Arduino 18
* Purpose: To demonstrate variable blink times for external LEDs
* Operation: Sets up output pins (3 off) in setup() method;
* Declares pin definition variables (3 off)
* Defines loop() to perform various LED blinking & delay operations
* In this case, there is a varying blink rate of the Yellow LED,
* from 10ms up to 1 sec & 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 ylwLedPin = 12; // yellow LED connected to digital pin 12
int redLedPin = 11; // red LED connected to digital pin 11
int dLay = 10; // delay variable - now 10 milliseconds

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

// Loop turns yellow LED (pin12) off, red LED (pin 11) on, waits 2 seconds,
// turns red LED on (or off) & runs a 'for-loop' 100 times:
// turn yellow LED on & off, with varying delay each time loop runs, &..
// ..repeats endlessly while Arduino has power
void loop()
{
//Ramps delays UP - Red LED stays ON thru Yellow LED loop
digitalWrite(ylwLedPin, LOW); // turn yellow LED off
digitalWrite(redLedPin, HIGH); // turn red LED on & leave it ON
delay(200*dLay); // delay 2 seconds
for (int i=1; i<=100; i++ ) // now start 'YellowLED for-loop' { digitalWrite(ylwLedPin, HIGH); // NOW turn yellow LED on.. delay(i*dLay); // ..delay 10millisec * multiplier.. digitalWrite(ylwLedPin, LOW); // ..turn yellow LED off.. delay(i*dLay); // ..delay 10millisec * multiplier.. }//end for(i..) digitalWrite(redLedPin, LOW); // turn red LED off now //Ramps delays DOWN again - red LED blinks.. digitalWrite(ylwLedPin, LOW); // turn yellow LED off digitalWrite(redLedPin, HIGH); // turn red LED on delay(200*dLay); // delay 2 seconds digitalWrite(redLedPin, LOW); // First turn red LED off for (int i=100; i>1; i-- ) // now start 'YellowLED for-loop'
{
digitalWrite(ylwLedPin, HIGH); // NOW turn yellow LED on..
delay(i*dLay); // ..delay 10millisec * multiplier..
digitalWrite(ylwLedPin, LOW); // ..turn yellow LED off..
delay(i*dLay); // ..delay 10millisec * multiplier..
}//end for(i..)

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


I really do think this is closer to the mark..

2 comments:

  1. Yup - tho it IS a bit like watching paint drying...

    ReplyDelete
  2. I should probably revise Task 19 as well,
    ..but i'm HUNGRY & i wanna go home!!

    ReplyDelete