Created
October 19, 2014 04:53
-
-
Save huytd/6bebf5f55b43ad49ce89 to your computer and use it in GitHub Desktop.
Simple time counter (90s)
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
#include <SPI.h> | |
#include <Adafruit_GFX.h> | |
#include <Adafruit_PCD8544.h> | |
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3); | |
int LED_PIN = 8; | |
int INP = 2; | |
int counter = 0; | |
boolean lcdStarted = false; | |
void setup() { | |
Serial.begin(9600); | |
display.begin(); | |
display.setContrast(50); | |
display.clearDisplay(); | |
display.display(); | |
pinMode(LED_PIN, OUTPUT); | |
display.clearDisplay(); | |
display.setTextColor(BLACK); | |
display.setCursor(0,0); | |
display.display(); | |
Reset(); | |
} | |
void Reset() { | |
counter = 91; | |
display.setTextSize(7); | |
Light(true); | |
Clock(); | |
} | |
void Light(boolean on) { | |
if (on) { | |
digitalWrite(LED_PIN, HIGH); | |
} else { | |
digitalWrite(LED_PIN, LOW); | |
} | |
} | |
void Draw(int text) { | |
display.clearDisplay(); | |
if (text >= 10) { | |
display.println(text, DEC); | |
} else { | |
display.println("0" + String(text)); | |
} | |
if (text <= 10) { | |
if (text % 2 == 0 && text > 0) { | |
Light(false); | |
} else { | |
Light(true); | |
} | |
} | |
display.display(); | |
} | |
void Clock() { | |
counter = counter - 1; | |
if (counter >= 0) { | |
Draw(counter); | |
delay(1000); | |
Clock(); | |
} else { | |
display.clearDisplay(); | |
display.setTextSize(2); | |
display.println("TIME UP"); | |
display.display(); | |
delay(1000); | |
Light(false); | |
} | |
} | |
void loop() { | |
if (counter <= 0) { | |
if (digitalRead(INP) == LOW) { | |
Reset(); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment