Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Keypad.h>
- #define RED 10
- #define BLUE 11
- #define GREEN 12
- const byte ROWS = 4; //four rows
- const byte COLS = 4; //four columns
- //define the cymbols on the buttons of the keypads
- char hexaKeys[ROWS][COLS] = {
- {'1','2','3','A'},
- {'4','5','6','B'},
- {'7','8','9','C'},
- {'*','0','#','D'}
- };
- char password[] = { '1', '2', '3', '4'};
- bool startRed = false;
- bool isPass = false;
- byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
- byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
- //initialize an instance of class NewKeypad
- Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
- void setup(){
- pinMode(RED,OUTPUT);
- pinMode(GREEN, OUTPUT);
- pinMode(BLUE, OUTPUT);
- digitalWrite(RED,HIGH);
- digitalWrite(GREEN,LOW);
- digitalWrite(BLUE,LOW);
- Serial.begin(9600);
- }
- int redValue;
- int greenValue;
- int blueValue;
- void loop(){
- if (startRed = false) {
- Serial.println("Paina *-nappainta ja syota salasana.");
- analogWrite(RED, 255);
- startRed = true;
- }
- char customKey = customKeypad.getKey();
- if (customKey == '*')
- {
- analogWrite(GREEN, 0);
- analogWrite(RED, 0);
- analogWrite(BLUE, 255);
- char customKey2 = customKeypad.getKey();
- int i = 0;
- bool rr = false;
- while (rr == false)
- {
- customKey2 = customKeypad.getKey();
- if (customKey2 != password[i])
- {
- if (!customKey2 == NO_KEY)
- {
- analogWrite(BLUE, 0);
- Serial.println("\nVirheellinen salasana!!");
- break;
- }
- }
- else
- {
- Serial.print('*');
- if (i == 3)
- {
- analogWrite(BLUE, 0);
- analogWrite(GREEN, 255);
- analogWrite(RED, 0);
- Serial.println(" Salasana oikein!");
- delay(5000);
- rr = true;
- }
- i++;
- }
- }
- analogWrite(GREEN, 0);
- analogWrite(RED, 255);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement