running two independant processes
Posted: Wed Dec 10, 2008 12:57 am
Hello all,
It seems like it should be easy to find examples of this, but I have yet to do so.
I did see somethng about state machines but the code that was being executed was very complicated and I could not sort out the basic method.
At any rate, I am using two LEDs to simulate the end process. I blink one LED continuously and am trying to control the blink of another LED independently.
I know how to do it if I want the duty cycle of the green LED to be 50% -- but that is not what I want. While the RED device is on for 10 seconds and off for 10 minutes, the GREEN device needs to be on for 1 hour and off for 6 hours (or any other vriationon tht basic scheme)
Maybe I've been working on it too long or maybe its too late at night, but I can't figure out why this doesn't work...
/* Two Process Experiment
*
* Blinks a red LED continuously while a green LED blinks at a different rate
*
*/
int RedLED = 7; // Red LED connected to digital pin 7
int GreenLED = 8; // Green LED connected to digital pin 8
long onTime = 5000; // green LED on time (ms)
long offTime = 1000; // green LED off time (ms)
long last = 0;
int Flag = 1; // 1 = green LED on, 0 = Green LED off
void setup()
{
pinMode(RedLED, OUTPUT); // sets the digital pin as output
pinMode(GreenLED, OUTPUT); // sets the digital pin as output
}
void loop()
{
BlinkRed(); // flash the red LED
if ( (Flag==1) && ((millis() - last) < onTime) )
digitalWrite(GreenLED, HIGH);
if( (millis() - last) > onTime)
{
Flag=0;
last=millis();
}
if ( (Flag==0) && ((millis() - last) < offTime) )
digitalWrite(GreenLED, LOW);
if( (millis() - last) > offTime)
{
Flag=1;
last=millis();
}
}// end loop
void BlinkRed()
{
digitalWrite(RedLED, HIGH);
delay(50);
digitalWrite(RedLED, LOW);
delay(50);
}
The red LED flashes.
The green LED turns on for 10 seconds and then goes off, but it never comes back on again.
Any suggestions or a better approach would be appreciated.
Thanks,
Phil...
It seems like it should be easy to find examples of this, but I have yet to do so.
I did see somethng about state machines but the code that was being executed was very complicated and I could not sort out the basic method.
At any rate, I am using two LEDs to simulate the end process. I blink one LED continuously and am trying to control the blink of another LED independently.
I know how to do it if I want the duty cycle of the green LED to be 50% -- but that is not what I want. While the RED device is on for 10 seconds and off for 10 minutes, the GREEN device needs to be on for 1 hour and off for 6 hours (or any other vriationon tht basic scheme)
Maybe I've been working on it too long or maybe its too late at night, but I can't figure out why this doesn't work...
/* Two Process Experiment
*
* Blinks a red LED continuously while a green LED blinks at a different rate
*
*/
int RedLED = 7; // Red LED connected to digital pin 7
int GreenLED = 8; // Green LED connected to digital pin 8
long onTime = 5000; // green LED on time (ms)
long offTime = 1000; // green LED off time (ms)
long last = 0;
int Flag = 1; // 1 = green LED on, 0 = Green LED off
void setup()
{
pinMode(RedLED, OUTPUT); // sets the digital pin as output
pinMode(GreenLED, OUTPUT); // sets the digital pin as output
}
void loop()
{
BlinkRed(); // flash the red LED
if ( (Flag==1) && ((millis() - last) < onTime) )
digitalWrite(GreenLED, HIGH);
if( (millis() - last) > onTime)
{
Flag=0;
last=millis();
}
if ( (Flag==0) && ((millis() - last) < offTime) )
digitalWrite(GreenLED, LOW);
if( (millis() - last) > offTime)
{
Flag=1;
last=millis();
}
}// end loop
void BlinkRed()
{
digitalWrite(RedLED, HIGH);
delay(50);
digitalWrite(RedLED, LOW);
delay(50);
}
The red LED flashes.
The green LED turns on for 10 seconds and then goes off, but it never comes back on again.
Any suggestions or a better approach would be appreciated.
Thanks,
Phil...