Hallo liebe Community,
ich möchte eine Teemaschine bauen.
An 3 Buttons soll mann die Zeit eintellen bzw. starten.
Ein counter soll sie haben.
Button1: +1Minute, wenn über 10 Minuten wieder bei 0 anfangen
Button2: -1Minute, wenn unter null bei 10 beginnen
Button3 Start/Stop
Auf dem Display (16/2) wird oben der Name angezeigt unten dann "Minuten:"
Ein kleiner Motor zieht an einem Faden zeitgesteuert.
Mit einem 2Kanal Relais ändere ich die polarität vom Motor, da er vor und zurück laufen soll.
Ich glaube das war es soweit zu den Funktionen, ich will ja nicht direkt so ausflippen ![]()
Bis jetzt habe ich auf dem Display stehen was ich oben beschrieben habe.
Jetzt hänge ich am counter.
Wenn ich Button1 drücke tickern jedes mal die Zahlen ordentlich hoch, nicht nur 1.
Dafür müsste ich warscheinlich ein debounce einbauen, puhhhh
Kann mir da jemand weiterhelfen?
Mein Code bis jetzt:
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
const int BUTTON1 = 2;// the number of the pushbutton pin
const int BUTTON2 = 3;// the number of the pushbutton pin
const int BUTTON3 = 4;// the number of the pushbutton pin
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState2 = 0;// current state of the button
int buttonState3 = 0;// current state of the button
int buttonState4 = 0;// current state of the button
int lastButtonState = 0; // previous state of the button
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("TeaMyTron");
lcd.setCursor(0,1);
lcd.print("Minuten: 0");
pinMode(BUTTON1, INPUT);
pinMode(BUTTON2, INPUT);
pinMode(BUTTON3, INPUT);
}
void loop() {
buttonState2 = digitalRead(BUTTON1);
if (buttonState2 != lastButtonState) {
if (buttonState2 == HIGH)
{
buttonPushCounter++;
lcd.setCursor(9,1);
lcd.print(buttonPushCounter);
}
}
}
Irgendwo haperts, verschiedene Szenarien schon durch, mhhhh
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
const int BUTTON1 = 2;// the number of the pushbutton pin
const int BUTTON2 = 3;// the number of the pushbutton pin
const int BUTTON3 = 4;// the number of the pushbutton pin
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState2 = 0;// current state of the button
int buttonState3 = 0;// current state of the button
int buttonState4 = 0;// current state of the button
boolean lastButtonState = LOW; // previous state of the button
boolean currentButtonState = LOW;
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("TeaMyTron");
lcd.setCursor(0,1);
lcd.print("Minuten: 0");
pinMode(BUTTON1, INPUT);
pinMode(BUTTON2, INPUT);
pinMode(BUTTON3, INPUT);
}
boolean debounce(boolean last)
{
boolean current = digitalRead(BUTTON1);
if(last != current){
delay(5);
current = digitalRead(BUTTON1);
}
return current;
}
void loop() {
currentButtonState = debounce(lastButtonState);
if(lastButtonState == LOW && currentButtonState ==HIGH)
//lastButtonState = currentButtonState;
//buttonState2 = digitalRead(BUTTON1);
//if (buttonState2 != lastButtonState) {
//if (buttonState2 == HIGH)
{
buttonPushCounter++;
lcd.setCursor(9,1);
lcd.print(buttonPushCounter);
}
//}
}
