Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- #include <Keypad.h>
- #include "pitches.h"
- #define BLUE 11
- #define GREEN 12
- #define RED 13
- LiquidCrystal lcd(5, 6, 7, 8, 9, 10);
- const byte ROWS = 4; //four rows
- const byte COLS = 4; //four columns
- int sensor = 0;
- int pump = 23;
- //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 hexaKeys[ROWS][COLS] = {
- {'D','C','B','A'},
- {'#','9','6','3'},
- {'0','8','5','2'},
- {'*','7','4','1'}
- };
- byte rowPins[ROWS] = {53, 52, 51, 50}; //connect to the row pinouts of the keypad
- byte colPins[COLS] = {49, 48, 47, 46}; //connect to the column pinouts of the keypad
- int i;
- String code;
- boolean pas = false;
- String password = "1234";
- int redValue;
- int greenValue;
- int blueValue;
- //initialize an instance of class NewKeypad
- Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
- void setup() {
- // set up the LCD's number of columns and rows:
- // pinMode (7, INPUT);
- // pinMode (A0, INPUT);
- //pinMode (pumpOn, OUTPUT);
- pinMode (sensor, INPUT);
- pinMode (pump, OUTPUT);
- digitalWrite(pump, LOW);
- pinMode(RED, OUTPUT);
- pinMode(GREEN, OUTPUT);
- pinMode(BLUE, OUTPUT);
- digitalWrite(RED, HIGH);
- digitalWrite(GREEN, LOW);
- digitalWrite(BLUE, LOW);
- Serial.begin(9600);
- i = 0;
- lcd.begin(16, 2);
- lcd.print("Password:");
- code = "";
- }
- void loop() {
- char customKey = customKeypad.getKey();
- led(255, 0, 40);
- if(!pas){
- Serial.println("test");
- if (customKey){
- if(customKey == 'A'){
- tone(22, NOTE_C5, 400);
- if(code == password){
- tone(22, NOTE_B5, 600);
- tone(22, NOTE_C5, 600);
- led(0, 0, 255);
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Zugriff");
- lcd.setCursor(0, 1);
- lcd.print("gewaehrt!");
- delay(2000);
- led(0, 0, 0);
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Code:");
- pas = true;
- i=0;
- code="";
- }else{
- code = "";
- i=0;
- lcd.clear();
- lcd.print("Falsches");
- lcd.setCursor(0, 1);
- lcd.print("Password");
- led(255, 0, 0);
- tone(22, NOTE_B5, 600);
- delay(2000);
- lcd.clear();
- lcd.print("Password:");
- }
- }else if(customKey == 'C'){
- if(i != 0){
- i--;
- tone(22, NOTE_C5, 400);
- lcd.setCursor(i, 1);
- lcd.print(" ");
- char copy[code.length()];
- code.toCharArray(copy, code.length());
- code = "";
- for(int z = 0; z<sizeof(copy)-1; z++){
- code = code+copy[z];
- }
- }
- }else if(customKey == 'B'){
- if(i != 0){
- i = 0;
- tone(22, NOTE_C5, 400);
- char copy[code.length()];
- code.toCharArray(copy, code.length());
- code = "";
- for(int z = 0; z<sizeof(copy); z++){
- lcd.setCursor(z, 1);
- lcd.print(" ");
- }
- }
- }else{
- tone(22, NOTE_C5, 400);
- lcd.setCursor(i, 1);
- lcd.print("#");
- code = code+customKey;
- i++;
- }
- }
- }else{
- int prozent = 100- analogRead(sensor)/10.2;
- Serial.println(prozent);
- if(prozent <= 70){
- digitalWrite(pump, HIGH);
- Serial.println("motor an");
- delay(2000);
- Serial.println("motor aus");
- digitalWrite(pump, LOW);
- delay(2000);
- }
- if (customKey){
- tone(22, NOTE_C5, 400);
- if(i!=0 && customKey == 'C'){
- i--;
- lcd.setCursor(i, 1);
- lcd.print(" ");
- char copy[code.length()];
- code.toCharArray(copy, code.length());
- code = "";
- for(int z = 0; z<sizeof(copy)-1; z++){
- code = code+copy[z];
- }
- }else if(customKey == 'D'){
- pas = false;
- lcd.clear();
- led(255, 0, 0);
- lcd.print("Abgemeldet!");
- delay(2000);
- lcd.clear();
- lcd.print("Password:");
- i=0;
- code="";
- }else{
- lcd.setCursor(i, 1);
- lcd.print(customKey);
- code = code+customKey;
- i++;
- }
- }
- }
- /*int istTrocken = digitalRead(11); // Pin 11 auslesen -> in Variable istTrocken
- int feuchtigkeit = analogRead(A0); // Pin A0 auslesen -> in Variable feuchtigkeit
- Serial.print("istTrocken: "); // Variablenname für Übersichtlichkeit im Serial Monitor
- Serial.println(istTrocken); // Wert von "istTrocken" ausgeben
- Serial.print("feuchtigkeit: "); // Variablenname für Übersichtlichkeit im Serial Monitor
- Serial.println(feuchtigkeit);
- //delay(1000);
- /*int istTrocken = digitalRead(52);
- int feuchtigkeit = analogRead(A0);
- Serial.print("istTrocken: ");
- Serial.println(istTrocken);
- Serial.print("feuchtigkeit: ");
- Serial.println(feuchtigkeit);
- delay(1000);
- */
- }
- void led(int red, int blue, int green){
- analogWrite(RED, red);
- analogWrite(GREEN, green);
- analogWrite(BLUE, blue);
- }
Add Comment
Please, Sign In to add comment