Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <LiquidCrystal.h>
- void printLcd(String, String);
- char Comp(char* This);
- char password[] = "Hope";
- char input[16];
- int igual = 0;
- bool justChecked = false;
- const int ledGreen = 6;
- const int ledRed = 7;
- const int buzzer = 8;
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- void setup() {
- lcd.begin(16, 2);
- printLcd(":<","ENTER PASSWORD");
- pinMode(ledGreen, OUTPUT);
- pinMode(buzzer, OUTPUT);
- pinMode(ledRed, OUTPUT);
- Serial.begin(9600);
- }
- void loop() {
- if(Serial.available() > 0) {
- igual = Comp(password);
- justChecked = true;
- } else {
- justChecked = false;
- igual = 0;
- }
- if(igual) {
- printLcd("CORRECT","ACCES GRANTED");
- digitalWrite(buzzer, HIGH);
- delay(200);
- digitalWrite(buzzer, LOW);
- digitalWrite(ledGreen, HIGH);
- digitalWrite(ledRed, LOW);
- } else if (justChecked) {
- printLcd("WRONG PASSWORD","TRY AGAIN");
- digitalWrite(ledRed, HIGH);
- digitalWrite(ledGreen, LOW);
- }
- delay(100);
- }
- char Comp(char This[30]) {
- int cont = 0;
- int tamanho = 0;
- while (Serial.available() > 0)
- {
- input[cont] = Serial.read();
- cont++;
- }
- input[cont] = '\0';
- if (strcmp(input,This) == 0) {
- return(1);
- }
- else {
- return(0);
- }
- }
- void printLcd(String first, String second) {
- lcd.clear();
- lcd.print(first);
- lcd.setCursor(0,1);
- lcd.print(second);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement