Hi.
I am trying to make multiple LED's turn on at different brightnesses depending on the amount of force exerted on an FSR connected to my circuit. The code also needs to tell me the value of the force exerted.
However, when I am doing my if, else statements I keep getting the errors:
/tmp/480419218/final_project_round_2/final_project_round_2.ino: In function 'void loop()':
/tmp/480419218/final_project_round_2/final_project_round_2.ino:42:6: error: 'else' without a previous 'if'
/tmp/480419218/final_project_round_2/final_project_round_2.ino:48:6: error: 'else' without a previous 'if'
/tmp/480419218/final_project_round_2/final_project_round_2.ino:54:6: error: 'else' without a previous 'if'
exit status 1
This is my code.
const int sensorPin = A0;
const float baselineForce = 0.1;
const int LED1 = 2;
const int LED2 = 3;
const int LED3 = 4;
const int LED4 = 5;
int ledState = LOW;
int LED ;
void setup() {
Serial.begin(9600); // open a serial port
for(int pinNumber = 2; pinNumber<6; pinNumber++) {
pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber, LOW);
}
}
void loop() {{
int sensorVal = analogRead(sensorPin);
Serial.print ("Sensor Value: ");
Serial.print (sensorVal);
// convert the voltage to light output
digitalWrite(sensorPin, ledState);
digitalWrite(LED, ledState);
float voltage = (sensorVal/1024.0) * 5.0;
Serial.print("sensorVal");
if (map(sensorVal, 0.1, 1032, 0.1, 258));
{
digitalWrite(sensorPin, ledState);
digitalWrite(LED1, ledState);
}
else if (map(sensorVal, 0.1, 1032, 258.1, 516));
{
digitalWrite(sensorPin, ledState);
digitalWrite(LED2, ledState);
}
else if (map(sensorVal, 0.1, 1032, 516.1, 774));
{
digitalWrite(sensorPin, ledState);
digitalWrite(LED3, ledState);
}
else if (map(sensorVal, 0.1, 1032, 774.1, 1024));
{
digitalWrite(sensorPin, ledState);
digitalWrite(LED4, ledState);
}
delay(100);
}
}
I've only been coding a couple of weeks but I can not figure out what I am doing wrong. Any help you can give would be much appreciated.
Thank you!