#include <Keypad.h>
const byte n_rows = 4;
const byte n_cols = 4;
char keys[n_rows][n_cols] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte colPins[n_rows] = {D3, D2, D1, D0};
byte rowPins[n_cols] = {D7, D6, D5, D4};
Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, n_rows, n_cols);
int toplamrakam = 0;
void setup(){
Serial.begin(115200);
}
void loop() {
char tus_degeri = myKeypad.getKey();
if ( isdigit(tus_degeri) ) { // basılan tuş rakam ise, basamakları toplar 1+2+3 =123
uint8_t rakam = tus_degeri - '0';
toplamrakam = ((toplamrakam * 10) + rakam);
//Serial.println(tus_degeri); // basılan her bir tuş
//Serial.println(toplamrakam); // ortaya çıkan sayı
} else if ( tus_degeri == '*' ) {
Serial.print(toplamrakam);
Serial.print( " numaralı sipariş oluşturuldu. \nBir daha yeni bir sipariş oluşturmadan önce hayatın ne kadar pahalı olduğunu düşünün!\n" );
toplamrakam = 0;
// yıldız duşu enter gibi davranır
} else if ( tus_degeri == 'A' ) {
toplamrakam = 0;
Serial.print("Toplamrakam ");
Serial.print(toplamrakam);
Serial.print(" sıfırlandı.\n");
// A tuşu yanlış girişi sıfırlar....
}
}