Reputation: 49
I got a problem with this code from Arduino Projects Book, a very simple code soryy if is very obvius.
This is the code I wrote:
const int greenLEDpin = 9;
const int redLEDpin = 10;
const int blueLEDpin = 11;
const int redSensorpin = A0;
const int greenSensorpin = A1;
const int blueSensorpin = A2;
int redValue = 0;
int greenValue = 0;
int blueValue = 0;
void setup() {
Serial.begin(9600);
pinMode(greenLEDpin,OUTPUT);
pinMode(redLEDpin,OUTPUT);
pinMode(blueLEDpin,OUTPUT);
}
void loop() {
redSensorValue = analogRead(redSensorpin);
delay (5);
greenSensorValue = analogRead(greenSensorpin);
delay(5);
blueSensorValue = analogRead(blueSensorpin);
Serial.print("Raw Sensor Values \t Red: ");
Serial.print(redSensorValue);
Serial.print("\t Green: ");
Serial.print(greenSensorValue);
Serial.print("\t Blue: ");
Serial.println(blueSensorValue);
redValue = redSensorValue/4;
greenValue = greenSensorValue/4;
blueValue = blueSensorValue/4;
Serial.print("Mapped Sensor Values \t ReD: ");
Serial.print(redValue);
Serial.print("\t Green: ");
Serial.print(greenValue);
Serial.print("\t Blue: ");
Serial.print(blueValue);
analogWrite(redLEDpin, redValue);
analogWrite(greenLEDpin, greenValue);
analogWrite(blueLEDpin, blueValue);
}
And here is the error: Arduino:1.7.10 (Windows 8.1), Placa:"Arduino Uno"
LED_tricolor.ino: In function 'void loop()':
LED_tricolor.ino:24:2: error: 'redSensorValue' was not declared in this scope
LED_tricolor.ino:26:2: error: 'greenSensorValue' was not declared in this scope
LED_tricolor.ino:28:2: error: 'blueSensorValue' was not declared in this scope
Someone knows whats happening here? I tried some things like puting the variables before, but nothing... Hope u guys can help me ^^.
Upvotes: 0
Views: 426
Reputation: 33
You did not add any sensor pin in setup() function. Edit you function just like it.
void setup() {
pinMode(redSensorpin,INPUT);
pinMode(greenSensorpin,INPUT);
pinMode(blueSensorpin,INPUT);
pinMode(greenLEDpin,OUTPUT);
pinMode(redLEDpin,OUTPUT);
pinMode(blueLEDpin,OUTPUT);
Serial.begin(9600);
}
Upvotes: 0
Reputation: 167
Try to add this just before the setup:
int redSensorValue = 0;
int greenSensorValue = 0;
int blueSensorValue = 0;
Or if you prefer, you can just add int
before the name of your variables in the loop.
Upvotes: 2