Hello, I am a beginner in C++ and am trying out something, what I want the program to do is light up an LED when it is between a certain water level, but the LED is not lighting up no matter what.
here is the code
int adc_id = 0;
int HistoryValue = 0;
char printBuffer[128];
void setup()
{
Serial.begin(9600);
pinMode(2, OUTPUT);
}
void loop()
{
int value = analogRead(adc_id); // get adc value
if(((HistoryValue>=value) && ((HistoryValue - value) > 10)) || ((HistoryValue<value) && ((value - HistoryValue) > 10)))
{
sprintf(printBuffer,"ADC%d level is %d\n",adc_id, value);
Serial.print(printBuffer);
HistoryValue = value;
}
if (printBuffer <= 200){
digitalWrite(2,HIGH);
}
else(digitalWrite(2,LOW));
}