Hi,
Does anyone knows how to make a decrement code without it having showing negative values or the value that show on LCD goes beyond 2 digit?
The problem that I'm facing is..after it goes below -1 and I start to +1 it back..the value started to +10 due to the symbol "-" shown before.
I attached my coding in case if you can point out anything wrong in the code..
thanks in advance
Counting_Cust.ino (1.24 KB)
#include <CapacitiveSensor.h>
byte incrementButton = A0;
byte decrementButton = A1;
#include <LiquidCrystal.h>
const int rs = 12,en = 11,d4 = 5,d5 =4,d6 = 3,d7 = 2;
LiquidCrystal lcd(rs, en, d4 ,d5, d6, d7);
int switchPin = A0;
int switchPin1 = A1;
int incrementState = 0;
int lastIncrementState = 0;
int decrementState = 0;
int lastDecrementState = 0;
int counter = 0;
int val = 0;
void setup()
{
pinMode(switchPin, INPUT);
pinMode(switchPin, INPUT);
lcd.begin(16, 2);
lcd.print("No. Cust.");
}
void loop()
{
if(val = analogRead(switchPin));{
if(val == HIGH);{
incrementState = 0;
}
}
if(val == LOW);
else{
incrementState = 1;
}
if(incrementState == HIGH){
counter = counter + 10;
lcd.setCursor(12, 1);
lcd.print(counter);
delay(1000);
}
{
if(val = analogRead(switchPin1));{
if(val == HIGH);{
decrementState = 0;
}
if(val == LOW);
else{
decrementState = 1;
}
}
if(decrementState == HIGH){
counter = counter -10;
lcd.setCursor(12, 1);
lcd.print(counter);
delay(1000);
}
}
lastIncrementState = incrementState;
lastDecrementState = decrementState;
}
pinMode(switchPin, INPUT);
pinMode(switchPin, INPUT);
You only need to do it once.
if(val = analogRead(switchPin));{
if(val == HIGH);
Triple Oops.
Lose the semicolons, do a digitalRead
if(val == LOW);
Again, lose the semicolon.
Or just use "else"