Created
May 24, 2017 02:12
-
-
Save r0lodex/18d51fc5ce9d364b3c871e7be15606ad to your computer and use it in GitHub Desktop.
A refactored solution for Arduino test
This file contains hidden or 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
#include <LiquidCrystal.h> | |
int buttonPin = 7; | |
int ledPin = 13; | |
int buttonState = 0; | |
boolean on = false; | |
int flag = 0; | |
int S = 05; // count seconds | |
int M = 00; // count minutes | |
int H = 00; // count hours | |
//initialize the library with the numbers of the interface pins | |
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // pins connected to LCD | |
void setup() | |
{ | |
pinMode(ledPin, OUTPUT); | |
pinMode(buttonPin, INPUT); | |
lcd.begin(16, 2); | |
lcd.clear(); | |
} | |
void loop() { | |
buttonState = digitalRead(buttonPin); | |
timeOut = (H == 0 && M == 0 && S == 0) | |
on = (buttonState == HIGH) ? true : false; | |
currentState = (on == true && timeOut) ? LOW : HIGH | |
digitalWrite(ledPin, currentState); | |
while (currentState == HIGH) { | |
S = S - 1 | |
lcd.setCursor(1,0); | |
lcd.print("Remaining"); | |
lcd.setCursor(6,1); | |
lcd.print(":"); | |
lcd.setCursor(9,1); | |
lcd.print(":"); | |
delay(1000); | |
if (S == 0) { | |
M--; | |
S = 05; | |
} | |
if (M == 0) { | |
H--; | |
M = 00; | |
} | |
if (H == 0) { | |
H = 00; | |
M = 00; | |
S = 05; | |
} | |
} | |
lcd.clear(); | |
lcd.display(); | |
lcd.setCursor(0,0); | |
lcd.print("Your laundry is "); | |
lcd.setCursor(4,1); | |
lcd.print("DONE!"); | |
delay(300); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment