Hi,
My project is making an RGB LED turn red when you get an email on Gmail. So far, that works. Now, I want to make the RGB LED cycle through colors while "scanning" for an email. I don't know how to merge both of these so that when an email comes, it will stop cycling through colors and blink in pin 13 to light up the red led.
Here is the code for the email(it also uses python but this is what I need to run constantly):
int val = 0; //value that is stored from Serial monitor
byte led = 13; //pin the led is connected to
void setup(){
Serial.begin(9600); //begins Serial monitor
pinMode(led, OUTPUT); //set led as an output
}
void loop(){
if(Serial.available()) //check to see if Serial data is available
val = Serial.read() - '0'; //store the numerical value
digitalWrite(led, val); //write the value to the led
}
and here is the RGB Cycle code:
int redPin = 11;
int greenPin = 10;
int bluePin = 9;
//uncomment this line if using a Common Anode LED
//#define COMMON_ANODE
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop()
{
setColor(255, 0, 0); // red
delay(1000);
setColor(0, 255, 0); // green
delay(1000);
setColor(0, 0, 255); // blue
delay(1000);
setColor(255, 255, 0); // yellow
delay(1000);
setColor(80, 0, 80); // purple
delay(1000);
setColor(0, 255, 255); // aqua
delay(1000);
}
void setColor(int red, int green, int blue)
{
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
I want both of these to run simultaneously. Any help would be appreciated.