Created
March 3, 2018 19:54
-
-
Save DaveGraff/cf9db1a93f1ca45a2cd2ddd694759a52 to your computer and use it in GitHub Desktop.
Arduino code for Cooler Buddy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
v#include <Servo.h> | |
int l = 0; | |
int light1 = 11; | |
int light2 = 10; | |
int light3 = 9; | |
int light4 = 8; | |
int light5 = 7; | |
int button1 = 2; | |
int button2 = 3; | |
int button3 = 4; | |
int button4 = 5; | |
int button5 = 6; | |
int greenLight = 12; | |
Servo lock; | |
String pass = "22222"; | |
int angleLock = 120; | |
int angleUnlock = 72; | |
boolean isUnlocked = false; | |
String passTry = ""; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(light1, OUTPUT); | |
pinMode(light2, OUTPUT); | |
pinMode(light3, OUTPUT); | |
pinMode(light4, OUTPUT); | |
pinMode(light5, OUTPUT); | |
pinMode(button1, INPUT); | |
pinMode(button2, INPUT); | |
pinMode(button3, INPUT); | |
pinMode(button4, INPUT); | |
pinMode(button5, INPUT); | |
pinMode(greenLight, OUTPUT); | |
lock.attach(13); | |
Serial.println("done with setup"); | |
} | |
void changeState() { | |
Serial.println("change state"); | |
if (isUnlocked) { | |
lock.write(angleLock); | |
} else { | |
lock.write(angleUnlock); | |
} | |
isUnlocked = !isUnlocked; | |
} | |
void reset(){ | |
digitalWrite(light5, LOW); | |
digitalWrite(light4, LOW); | |
digitalWrite(light3, LOW); | |
digitalWrite(light2, LOW); | |
digitalWrite(light1, LOW); | |
digitalWrite(greenLight, LOW); | |
passTry = ""; | |
l = 0; | |
while(digitalRead(button1)){} | |
while(digitalRead(button2)){} | |
while(digitalRead(button3)){} | |
while(digitalRead(button4)){} | |
while(digitalRead(button5)){} | |
} | |
void loop() { | |
if (l == 5) { | |
Serial.println(passTry); | |
if (passTry.equals(pass)) { | |
digitalWrite(greenLight, HIGH); | |
changeState(); | |
//delay(1000); | |
Serial.println("l"); | |
//while (button1 != HIGH || button2 != HIGH || button3 != HIGH || button4 != HIGH || button5 != HIGH){ | |
while(true){ | |
if(digitalRead(button1) || digitalRead(button2) || digitalRead(button3) || digitalRead(button4) || digitalRead(button5)) { | |
changeState(); | |
break; | |
} | |
} | |
//} | |
} else { | |
delay(300); | |
} | |
reset(); | |
} | |
if (digitalRead(button1)) { | |
l++; | |
passTry = passTry + "1"; | |
Serial.println("button 1"); | |
while(digitalRead(button1)){} | |
} | |
if (digitalRead(button2)) { | |
l++; | |
passTry = passTry + "2"; | |
Serial.println("button 2"); | |
while(digitalRead(button2)){} | |
} | |
if (digitalRead(button3)) { | |
l++; | |
passTry = passTry + "3"; | |
Serial.println("button 3"); | |
while(digitalRead(button3)){} | |
} | |
if (digitalRead(button4)) { | |
l++; | |
passTry = passTry + "4"; | |
Serial.println("button 4"); | |
while(digitalRead(button4)){} | |
} | |
if (digitalRead(button5)) { | |
l++; | |
passTry = passTry + "5"; | |
Serial.println("button 5"); | |
while(digitalRead(button5)){} | |
} | |
switch (l) { | |
case 5: digitalWrite(light5, HIGH); | |
case 4: digitalWrite(light4, HIGH); | |
case 3: digitalWrite(light3, HIGH); | |
case 2: digitalWrite(light2, HIGH); | |
case 1: digitalWrite(light1, HIGH); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment