Hi there,
I am trying to adapt this LED arduino dimmer code http://www.arduino.cc/en/Tutorial/Dimmer to my project. I am having problems with syntax when I add multiple if... else statements. I am trying to have 3 LEDs respond to different ranges of an analog sensor value 0-255 and only have that particular LED lit during it's specified value range (but also have the dimming functioning within that range). Am I going about this the right way? Do I need booleans? Cases? It seems like it should be fairly simple, but I keep getting error messages.
Any help would be appreciated thanks,
Milena
*/
const int ledPin1 = 9; // the pin that the LED is attached to
const int ledPin2 = 10;
const int ledPin3 = 11;
void setup()
{
// initialize the serial communication:
Serial.begin(9600);
// initialize the ledPin as an output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}
void loop() {
byte brightness;
// check if data has been sent from the computer:
if (Serial.available())
// read the most recent byte (which will be from 0 to 255):
brightness = Serial.read();
// set the brightness of the LED:
if (brightness >= 0 && brightness <=85);{
analogWrite(ledPin1, brightness);}
else {analogWrite (ledPin1, 0);}
if (brightness >= 85 && brightness <= 177);{
analogWrite(ledPin2, brightness);
}
else {analogWrite (ledPin2, 0);}
if(brightness >= 177 && brightness <=255);{
analogWrite(ledPin3, brightness);
}else {analogWrite (ledPin3, 0);}