Strength-o-meter with Arduino and LEDs

There are 5 red LEDs that light up progressively and one by one as you press on the sensor. Here is the code but it is not working as expected. They don’t dim or turn off when you let go. I think I need to nest the if-statements. I need to keep working on this.

int pressureVal = 0;
int mappedVal;
float voltageIn =0;

const int ledPin = 9; // pin that the LED is attached to
const int ledPin2 = 10;
const int ledPin3 = 11;
const int ledPin4 = 6;
const int ledPin5 = 5;

void setup(){
//this opens a debug window, that speaks at 96bits per second
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
}

void loop(){
pressureVal = analogRead(0);

Serial.print("\n Potentiometer Value = ");
Serial.print(pressureVal);

// goes from 1023 to 0
// we can set mapped values so they mean more to us
mappedVal = map(pressureVal,0, 1023,0, 255);
Serial.print("\n Mapped Value = ");
Serial.print(mappedVal);

//reset the RDC, good practice, 10 ms
delay(10);

if (mappedVal > 255 / 5){
analogWrite(ledPin, mappedVal);
}
if ( mappedVal > 255 * 2/5 ){
analogWrite(ledPin2, mappedVal);
}
if ( mappedVal > 255 * 3/5 ){
analogWrite(ledPin3, mappedVal);
}
if ( mappedVal > 255 * 4/5 ){
analogWrite(ledPin4, mappedVal);
}
if ( mappedVal == 255 ){
analogWrite(ledPin5, mappedVal);
}
}

Proudly powered by WordPress
Theme: Esquire by Matthew Buchanan.