Moi,
Arduinon ohjelmointia nyt kovasti opettelen ja napin painallus laskuri projekti on meneillään. Siinä lisätään tai vähennetään painallusten määrää. Mutta 2x16 lcd-näytöllä on tämmöinen ongelma.
Esim, painettu + nappia 10 kertaa, lcd:llä tämä:
Nappilaskuri
Kpl: 10
Sitten vähennetään yksi ja lcd:llä tämä:
Nappilaskuri
Kpl: 90
Eli nuo viimeset numerot ei poistu näytöltä ja ois hauska saada ne pois. Tuossa koodi:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int switchPin = 6; // switch is connected to pin 2
int switchPin2 = 7; // switch is connected to pin 2
int val; // variable for reading the pin status
int val2; // variable for reading the pin status
int buttonState; // variable to hold the button state
int buttonState2; // variable to hold the button state
int buttonPresses = 0; // how many times the button has been pressed
void setup() {
pinMode(switchPin, INPUT); // Set the switch pin as input
pinMode(switchPin2, INPUT); // Set the switch pin as input
buttonState = digitalRead(switchPin); // read the initial state
buttonState2 = digitalRead(switchPin2); // read the initial state
lcd.begin(16, 2);
lcd.print("Nappilaskuri");
}
void loop(){
val = digitalRead(switchPin); // read input value and store it in val
val2 = digitalRead(switchPin2); // read input value and store it in val
if (val != buttonState) { // the button state has changed!
if (val == HIGH) { // check if the button is pressed
buttonPresses++; // increment the buttonPresses variable
}
}
if (val2 != buttonState2) { // the button state has changed!
if (val2 == HIGH) { // check if the button is pressed
buttonPresses--; // increment the buttonPresses variable
}
}
lcd.setCursor(0, 1); // bottom left
lcd.print("Kpl:");
lcd.print(buttonPresses);
buttonState2 = val2;
buttonState = val; // save the 8tate in our variable
}