Variable "int numberLEDs" not changing

I’m not that good at this. A solid programmer should be able to figure it out very quickly by opening up the sketch, run it, and looking at the serial monitor. The RPMs variable changes, but the other variable doesn’t change.

The variable numberLEDs is not changing and thus the LEDs are not turning on. I’ve tested the LEDs independently, and they all work.

#include <SPI.h>

int RPM =0;

int numberLEDs = 0;

const int A = 1000; //Threshold to turn on first LED, represented by pin13 LED
const int B = 1500; //Threshold to turn on second LED, represented by pin12 LED
const int C = 2000; //Threshold to turn on third LED, represented by pin11 LED

void setup() {
// put your setup code here, to run once:
;

Serial.begin(9600);

pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);

}

void loop() {
// put your main code here, to run repeatedly:
int numberLEDs = 0;

int RPM = 600; //manually manipulate the RPM values for now.

if( RPM < A){

 numberLEDs = 0;// This variable isn't changing when RPMs go over the constant thresholds I have set.

digitalWrite(13,LOW);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
}
if (( RPM >= A) && ( RPM < B)){
numberLEDs = 1;
digitalWrite(13,HIGH);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
}
if(( RPM >= B)&&( RPM < C)){
numberLEDs = 2;
digitalWrite(13,HIGH);
digitalWrite(12,HIGH);
digitalWrite(11,LOW);
}
if( RPM >= C){
numberLEDs = 3;
digitalWrite(13,HIGH);
digitalWrite(12,HIGH);
digitalWrite(11,HIGH);
}

delay(1000);

Serial.print("RPM = ");
Serial.println(RPM);
Serial.print("numberLEDs on = ");
Serial.println(numberLEDs);
delay(2000);

RPM= RPM + 500;
Serial.print("RPM = ");
Serial.println(RPM);
Serial.print("numberLEDs on = ");
Serial.println(numberLEDs);
delay(2000);

RPM= RPM + 500;
Serial.print("RPM = ");
Serial.println(RPM);
Serial.print("numberLEDs on = ");
Serial.println(numberLEDs);
delay(2000);

RPM= RPM + 500;
Serial.print("RPM = ");
Serial.println(RPM);
Serial.print("numberLEDs on = ");
Serial.println(numberLEDs);
delay(2000);

RPM= RPM + 500;
Serial.print("RPM = ");
Serial.println(RPM);
Serial.print("numberLEDs on = ");
Serial.println(numberLEDs);
delay(2000);
}

Something went a bit wrong with your code tags there! Try again using More->Modify

The variable numberLEDs is not changing and thus the LEDs are not turning on

"Thus"? But the LEDs that are on does not depend on that variable. They depend on the RPM variable. Can you explain what you mean?

Hello justin_bouchard,
Please enclose your code in code tags </>, it makes it easier to read.

You have set RPM to 600 at the start and then have:

if( RPM < A){
 numberLEDs = 0;// This variable isn't changing when RPMs go over the constant thresholds I have set.
 digitalWrite(13,LOW);
 digitalWrite(12,LOW);
 digitalWrite(11,LOW);
 }

So, as 600 is less than A (1000) numberLEDs == 0, which is what prints out, so the code is doing as expected. I have not read every single following if().

At the start of each loop the RPM is set back to 600, checks the conditions and then prints all of the information. You are not rechecking the if statements after you add 500 to RPM. This is the reason the Leds # is not changing.

I would recommend putting the if statements into a function that is called after each +500 to the RPM. This will clean up your code and provide the functionality you desire.

You have two variables called numberLEDs.
Oops.

3½ days and no response.

Looking like a dead thread!