Programming for the Arduino Uno.
I'm new to programming, and am essentially amalgamating circuits 3 5 and 6.
Full program:
//Define RGB pin #s
const int RED_PIN = 9;
const int GREEN_PIN = 10;
const int BLUE_PIN = 11;
int colorIt = 0; //var for which color is being recorded//Define ID of sensor pin.
const int sensorPin = 0;
// Set up global vars for light level.
int lightLevel, high = 0, low = 1023;
//set consts for button pins
const int buttonPin = 2;
void setup()
{
//set pushpin to input
pinMode(buttonPin, INPUT);//set RGB pins to output
//set LED pins to outputpinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
}void loop()
{int buttonState; //var to hold button state
buttonState = digitalRead(buttonPin); //Read when button is pushed.
if (buttonState == LOW);//When the button is pushed
{
lightLevel = analogRead(sensorPin); //Read from the light sensorif (colorIt = 0); //First iteration
{
analogWrite(RED_PIN, lightLevel); //Light up the red
colorIt = colorIt + 1; //tell it to ready the next iteration
}
else
{
if (colorIt = 1); //Second iteration
{
analogWrite (BLUE_PIN, lightLevel); //Light up bluecolorIt = colorIt + 1;
}
}
else
{
if (colorIt = 2) //Third (final) iteration
}
{
analogWrite (GREEN_PIN, lightLevel);
}}
}
The part with the error is:
if (colorIt = 0); //First iteration
{
analogWrite(RED_PIN, lightLevel); //Light up the red
colorIt = colorIt + 1; //tell it to ready the next iteration
}
else
{
if (colorIt = 1); //Second iteration
{
analogWrite (BLUE_PIN, lightLevel); //Light up bluecolorIt = colorIt + 1;
}
It's telling me that that else doesn't have a preceding if, when it clearly (to my eyes) does.
Full error log:
sketch_feb02a.ino: In function 'void loop()':
sketch_feb02a:53: error: 'else' without a previous 'if'
sketch_feb02a:62: error: 'else' without a previous 'if'
sketch_feb02a:65: error: expected primary-expression before '}' token
sketch_feb02a:65: error: expected `;' before '}' token
A couple of those are housekeeping errors that I haven't taken the time to fix yet.
You can probably ignore those, unless you have an urge to tell me why they're there.
I'm mystified about this if..else thing. I've looked at the reference and the bit there
is identical to my code. Hopefully you see something I don't.
Thanks!