Hallo zusammen,
ich bin relativ neu in dem Thema Arduino und habe jetzt ein Problem mit meinem Sketch ich hoffe mir kann jemand helfen.
Ich möchte mit dem Keypad eine 4-stellige Zahl eingeben, und falls ich mich mal vertippe die Zahl bzw. Variable "zahl" mit der Taste "" wieder löschen um eine neue Zahl eingeben zu können. Bis jetzt funktioniert alles soweit bis auf das löschen des Arrays bzw. der Variable mit der Taste ''. Kann mir da bitte jemand weiterhelfen?
Grüße Johannes
// Wire Bibliothek einbinden
#include <Wire.h>
// Vorher hinzugefügte LiquidCrystal_I2C Bibliothek einbinden
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <Keypad.h>
//Hier wird die größe des Keypads definiert
const byte COLS = 4;
const byte ROWS = 4;
//Die Ziffern/Zeichen:
char hexaKeys[ROWS][COLS]=
{
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte colPins[COLS] = { 5, 4, 3, 2 };
byte rowPins[ROWS] = { 9, 8, 7, 6 };
Keypad Tastenfeld = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
char Taste;
int zahl;
int Speicher[3];
int zaehler;
int i = 0;
void setup() {
Serial.begin(9600);
//Im Setup wird der LCD gestartet
lcd.init();
//Hintergrundbeleuchtung einschalten
lcd.backlight();
}
void loop() {
Taste = Tastenfeld.getKey();
if (zaehler <= 4) {
if((Taste) and (zaehler == 0) and (Taste != '*')){
Speicher[0] = (Taste - 48);
zaehler ++;
Taste = 0;
}
if((Taste) and (zaehler == 1) and (Taste != '*')){
Speicher[1] = (Taste - 48);
zaehler ++;
Taste = 0;
}
if((Taste) and (zaehler == 2) and (Taste != '*')){
Speicher[2] = (Taste - 48);
zaehler ++;
Taste = 0;
}
if((Taste) and (zaehler == 3) and (Taste != '*')){
Speicher[3] = (Taste - 48);
zaehler ++;
Taste = 0;
}
}
if (Taste == '*') {
Speicher[0]=0;
Speicher[1]=0;
Speicher[2]=0;
Speicher[3]=0;
}
zahl = ((Speicher[0] * 1000) + (Speicher[1] * 100) + (Speicher[2] * 10) + (Speicher[3]));
lcd.setCursor(11,1);
lcd.print(zahl);
lcd.setCursor(0, 1);
lcd.print("Fuellstand");
}