My code gives out this error:
if (sensorvalue <= 40) {
^
MY_RGB_sound:32:3: error: expected unqualified-id before 'if'
if (sensorvalue <= 45) {
^
MY_RGB_sound:37:3: error: expected unqualified-id before 'else'
else {
^
MY_RGB_sound:42:1: error: expected declaration before '}' token
}
^
exit status 1
expected unqualified-id before 'if'
Tried googling it and nothing helpful comes up. I never understand when people talk code unless i hear them.
int red_pin= 11;
int green_pin = 10;
int blue_pin = 9;
int DO = 2; //Pin for Digital Output - DO
int DA = A0; // Pin for Analog Output - AO
int sensorvalue = 0;
void setup() {
Serial.begin(9600);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
}
void loop() {
sensorvalue = analogRead(DA); //Read the analog value
Serial.print("Analog: ");
Serial.print(sensorvalue); //Print the analog value
Serial.print(" ");
Serial.print("Digital: ");
Serial.println(digitalRead(DO)); //Print the digital value
// if (sensorvalue <= 40) {
// digitalWrite(11, HIGH);
// digitalWrite(10, LOW);
// digitalWrite(9, LOW);
}
if (sensorvalue <= 40) {
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
}
if (sensorvalue <= 45) {
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
}
else {
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
}
}
Should give no error and pins should provide the right output
Aucun commentaire:
Enregistrer un commentaire