Last active
December 20, 2015 03:09
-
-
Save Gonzih/6062052 to your computer and use it in GitHub Desktop.
Arduino timer with nokia display
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 <Adafruit_GFX.h> | |
#include <Adafruit_PCD8544.h> | |
// pin 7 - Serial clock out (SCLK) | |
// pin 6 - Serial data out (DIN) | |
// pin 5 - Data/Command select (D/C) | |
// pin 4 - LCD chip select (CS) | |
// pin 3 - LCD reset (RST) | |
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3); | |
int rele_pin = 8; | |
int backlight_pin = 2; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(rele_pin, OUTPUT); | |
pinMode(backlight_pin, OUTPUT); | |
analogWrite(backlight_pin, 1024); | |
display.begin(); | |
// you can change the contrast around to adapt the display | |
// for the best viewing! | |
display.setContrast(50); | |
display.display(); // show splashscreen | |
delay(2000); | |
display.clearDisplay(); // clears the screen and buffer | |
// text display tests | |
display.setTextSize(2); | |
display.setTextColor(BLACK); | |
display.setCursor(0,0); | |
} | |
int time_to_wait = 4 * 60 * 60; | |
int _3600 = 60 * 60; | |
void loop() { | |
display.clearDisplay(); | |
if (time_to_wait > 0) { | |
digitalWrite(rele_pin, HIGH); | |
delay(1000); | |
int hours = time_to_wait / _3600; | |
int minutes = (time_to_wait % _3600) / 60; | |
int seconds = (time_to_wait % _3600) % 60; | |
display.print(hours); | |
display.print(":"); | |
if (minutes < 10) display.print(0); | |
display.print(minutes); | |
display.print(":"); | |
if (seconds < 10) display.print(0); | |
display.println(seconds); | |
time_to_wait--; | |
} else { | |
analogWrite(backlight_pin, 0); | |
digitalWrite(rele_pin, LOW); | |
display.println("Done charging!"); | |
} | |
display.display(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment