die Darstellung und die Zahlenwerte sind so erst einmal wie sei sein sollten, nur mit der Eingabe ist es einwenig schwierig, da die Hexadezimalzahl eingegeben wird und der Zufall die richtige Stelle wählt...
die Eigabe der Dualzahl mittels der zugehörigen Taste in 0 und 1 wäre super.
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 20, 4); // mit HW61 Modul, Pin A4-SDA,A5-SCL,-,+5V
char H[3];
char L[3];
const byte KEYPAD_ROWS = 4;
const byte KEYPAD_COLS = 4;
byte rowPins[KEYPAD_ROWS] = {2, 3, 4, 5};
byte colPins[KEYPAD_COLS] = {6, 7, 8, 9};
char keys[KEYPAD_ROWS][KEYPAD_COLS] = {
{'0', '1', '2', '3'},
{'4', '5', '6', '7'},
{'8', '9', 'A', 'B'},
{'C', 'D', 'E', 'F'}
};
Keypad keypad(makeKeymap(keys), rowPins, colPins, KEYPAD_ROWS, KEYPAD_COLS);
void setup() {
lcd.init();
lcd.backlight();
lcd.clear();}
void loop() {
lcd.setCursor(0, 0); lcd.print("FEDC BA98 7654 3210");
static byte pos = 0;
static uint16_t Total = 0;
char key = keypad.getKey();
if (key) {
lcd.setCursor(5 * pos + 3, 1);
lcd.print(key);
lcd.setCursor(5 * pos, 1);
if (key > '9')key -= 7;
key -= '0';
for (byte i = 4; i > 0; i--)lcd.print((key & 1 << (i - 1)) ?'1':'0'); // hier kann man H/L schreiben
Total = Total & ~(0b1111 << 4 * (3 - pos));
Total = Total | (key << 4 * (3 - pos));
sprintf (H, "%02X", Total >> 8);
sprintf (L, "%02X", Total & 0xFF);
lcd.setCursor(7, 2);
lcd.print(H);
lcd.setCursor(17, 2);
lcd.print(L);
lcd.setCursor(12, 3);
lcd.print(" ");
lcd.setCursor(12, 3);
lcd.print(Total);
if (++pos == 4)pos = 0;
}
}