#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{ '1', '2', '3' },
{ '4', '5', '6' },
{ '7', '8', '9' },
{ '*', '0', '#' }
};
byte rowPins[ROWS] = { PA7, PA6, PA5, PA4 }; //connect to the row pinouts of the keypad
byte colPins[COLS] = { PA3, PA2, PA1 }; //connect to the column pinouts of the keypad
unsigned int indeks = 0;
unsigned int counter = 0;
double serial_no = 123456789;
double p1 = 3.98132;
double p2 = 3.99785;
double p3 = 3.99466;
//Create an object of keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
double generateKey(double p1, double p2, double p3, double serial_no, int counter, int duration) {
double r1 = fungsiHash(p1, serial_no, 50);
double r2 = fungsiHash(p2, r1, counter);
double r3 = fungsiHash(p3, r2, duration);
return r3;
}
double fungsiHash(double p1, double x, int n) {
double xi = x;
for (int i = 1; i <= n; i++) {
xi = p1 * xi * (1 - xi / 1000000000);
xi = floor(xi);
}
return xi;
}
void setup() {
lcd.init(); // initialize the lcd
lcd.init();
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3, 0);
lcd.print(" SEWA SELIS");
lcd.setCursor(2, 1);
lcd.print(" V1.0");
delay(5000);
lcd.clear();
lcd.print("MASUKKAN KODE");
lcd.setCursor(2, 1);
lcd.print("*=HAPUS #=OK");
Serial.begin(115200);
Serial.println("MULAI");
/*
Serial.print("ID Kendaraan = ");
Serial.println(serial_no);
Serial.print("Counter = ");
while(!Serial.available());
String konter = Serial.readStringUntil(0x0D);
Serial.println(konter);
counter = konter.toInt();
Serial.print("Token = ");
while(!Serial.available());
String token = Serial.readStringUntil(0x0D);
Serial.println(token);
double key = token.toDouble();
double k30 = generateKey(p1, p2, p3, serial_no, counter, 30);
double k60 = generateKey(p1, p2, p3, serial_no, counter, 60);
if (key == k30) {
Serial.println("Embedded system akan aktif 30 menit.");
} else if (key == k60) {
Serial.println("Embedded system akan aktif 60 menit.");
} else {
Serial.println("Kode aktifasi salah !");
}*/
}
void loop() {
char key = keypad.getKey(); // Read the key
// Print if key pressed
if (key) {
Serial.print("Key Pressed : ");
if (indeks == 0) {
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 0);
}
lcd.print(key);
//indeks++;
//if (indeks==9){}
Serial.println(key);
delay(100);
}
}
Loading
stm32-bluepill
stm32-bluepill