Sorry, hier mal beide tab's, hoffe das ist so verständlicher. Möchte das die eingegebenen Ziffern nebeneinander dargestellt werden und nicht übereinander (überschrieben).
// Start
#include "Adafruit_GFX.h"
#include "MCUFRIEND_kbv.h"
MCUFRIEND_kbv tft;
#include "Fonts/FreeMonoBold12pt7b.h"
#include "Fonts/FreeMonoBold9pt7b.h"
#include "Fonts/FreeSans9pt7b.h"
// Pinbelegung
const int led_PinR = 53; //Pin 53 ROT
const int led_PinB = 51; //Pin 51 BLAU
const int BP_PinR = 22; //Pin 22 ROT
const int BP_PinB = 24; //Pin 26 BLAU
const int greenPin = 51;
const int redPin = 53;
const int openDelay = 3000;
#include <Keypad.h>
char masterCode[] = "123456";
char limitedCode[] = "112233";
const byte ROWS = 4; // vier Reihen
const byte COLS = 4; // vier Spalten
// Define the Keymap
char keys[ROWS][COLS] = {
{'D', '#', '0', '*'},
{'C', '9', '8', '7'},
{'B', '6', '5', '4'},
{'A', '3', '2', '1'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 37, 35, 33, 31 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 45, 43, 41, 39 };
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int col[8];
void showmsgXY(int x, int y, int sz, const GFXfont *f, const char *msg)
{
int16_t x1, y1;
uint16_t wid, ht;
tft.setFont(f);
tft.setCursor(x, y);
tft.setTextColor(0x0000);
tft.setTextSize(sz);
tft.print(msg);
}
void setup() {
// Erklärung E/S
pinMode(led_PinR, OUTPUT);
pinMode(BP_PinR, INPUT);
pinMode(led_PinB, OUTPUT);
pinMode(BP_PinB, INPUT);
tastatur();
} //Ende SETUP
und die Nummer 2
byte validateCode() { // 0...keine Taste 1...MasterCode 2...LimitedCode
static byte counter = 0;
static char code[sizeof(masterCode)];
char key = keypad.getKey();
if (!key) return 0; // keine Taste gedrückt, kann nicht gültig sein
if (counter == 0) memset(code, 0, sizeof(code)); // clear code string
tft.setCursor(100,110); //setCursor(int16_t x, int16_t y)
tft.setTextColor(6); //setTextColor(uint16_t t)
tft.setTextColor(1,3); //setTextColor(uint16_t t, uint16_t b)
tft.setTextSize(2); //setTextSize(uint8_t s)
tft.print(key); // comment out if not needed for debugging
switch (key) {
case '*': counter = 0; // start new code
break;
case '#':
if (strcmp(code, masterCode) == 0) // maybe correct code?
{
counter = 0;
return 1; // correct masterCode was entered: return 1
}
if (strcmp(code, limitedCode) == 0) // maybe correct code?
{
counter = 0;
return 2; // correct limitedCode was entered: return 2
}
break;
default : code[counter] = key; // just add the keystroke to the code
if (counter < sizeof(code) - 1) counter++;
}
return 0; // es wurde kein gültiger Code eingegeben
}
//Tastatur Code
void tastatur() {
tft.reset();
uint16_t ID = tft.readID();
tft.begin(ID);
tft.setRotation(1);
tft.invertDisplay(true);
tft.fillScreen(0xFFFF);
showmsgXY(90, 45, 2, &FreeMonoBold12pt7b, "ENTER");
showmsgXY(55, 220, 2, &FreeMonoBold9pt7b, "your PINCODE");
}
void loop() {
byte schluessel = validateCode();
switch (schluessel) {
case 1:
Serial.println("Code RED");
// mach was bei Master Code
digitalWrite(greenPin, HIGH);
delay(2000);
// myservo.write(angleClosed);
//digitalWrite(greenPin, LOW);
break;
case 2:
Serial.println("Code BLUE");
// mach was bei Limited Code
digitalWrite(redPin, HIGH);
delay(2000);
//digitalWrite(redPin, LOW);
break;
default:
break;
}
}