newbie trying to program led chaser using relay
hi there,
i got thrown arduino project yesterday.
here our hardware:
- arduino duemilanove atmega328
- electronic brick shield pro (extended com digital com ports)
- simple relay
what trying accomplish 3 led chaser using 3 relays control chaser.
the problem having in code lights go in sequence stay on until loop ends oppose led1 blink on/off -- led2 blink on/off --- led3 blink on/off
if try use delay or change time interval lights stay on longer.
here code tried use below:
-------------------------------------------------------------------------
/* blink multiple leds without delay
*
* turns on , off several light emitting diode(led) connected digital
* pin, without using delay() function. this means other code
* can run @ same time without being interrupted led code.
*/
int led1 = 0; // led connected digital pin 13
int led2 = 3;
int led3 = 7;
int value1 = low; // previous value of led
int value2 = low;
int value3 = low; // previous value of led
long time1 = millis();
long time2 = millis();
long time3 = millis();
long interval1 = 500; // interval @ blink (milliseconds)
long interval2 = 500;
long interval3 = 500;
void setup()
{
pinmode(led1, output); // sets digital pin output
pinmode(led2, output);
pinmode(led3, output);
}
void loop()
{
unsigned long m = millis();
if (m - time1 > interval1){
time1 = m;
if (value1 == low)
value1 = high;
else
value1 = low;
digitalwrite(led1, value1);
delay(500);
}
if (m - time2 > interval2){
time2 = m;
if (value2 == low)
value2 = high;
else
value2 = low;
digitalwrite(led2, value2);
delay(1000);
}
if (m - time3 > interval3){
time3 = m;
if (value3 == low)
value3 = high;
else
value3 = low;
digitalwrite(led3, value3);
}
}
-------------------------------------------------
any appreciated!
thx!
i got thrown arduino project yesterday.
here our hardware:
- arduino duemilanove atmega328
- electronic brick shield pro (extended com digital com ports)
- simple relay
what trying accomplish 3 led chaser using 3 relays control chaser.
the problem having in code lights go in sequence stay on until loop ends oppose led1 blink on/off -- led2 blink on/off --- led3 blink on/off
if try use delay or change time interval lights stay on longer.
here code tried use below:
-------------------------------------------------------------------------
/* blink multiple leds without delay
*
* turns on , off several light emitting diode(led) connected digital
* pin, without using delay() function. this means other code
* can run @ same time without being interrupted led code.
*/
int led1 = 0; // led connected digital pin 13
int led2 = 3;
int led3 = 7;
int value1 = low; // previous value of led
int value2 = low;
int value3 = low; // previous value of led
long time1 = millis();
long time2 = millis();
long time3 = millis();
long interval1 = 500; // interval @ blink (milliseconds)
long interval2 = 500;
long interval3 = 500;
void setup()
{
pinmode(led1, output); // sets digital pin output
pinmode(led2, output);
pinmode(led3, output);
}
void loop()
{
unsigned long m = millis();
if (m - time1 > interval1){
time1 = m;
if (value1 == low)
value1 = high;
else
value1 = low;
digitalwrite(led1, value1);
delay(500);
}
if (m - time2 > interval2){
time2 = m;
if (value2 == low)
value2 = high;
else
value2 = low;
digitalwrite(led2, value2);
delay(1000);
}
if (m - time3 > interval3){
time3 = m;
if (value3 == low)
value3 = high;
else
value3 = low;
digitalwrite(led3, value3);
}
}
-------------------------------------------------
any appreciated!
thx!
code: [select]
int led1 = 0; // led connected digital pin 13well, it? led connected pin 0 or pin 13? it's not idea use pin 0 unless absolutely necessary, 1 of serial port pins.
stop using that, , use can use serial.begin() in setup , serial.print() in loop() see happening.
using millis() determine when toggle pin great idea. using delay, too, not.
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > newbie trying to program led chaser using relay
arduino
Comments
Post a Comment