Created
November 10, 2009 08:56
-
-
Save harrisony/230751 to your computer and use it in GitHub Desktop.
TV Timer thing for arduino
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
/* | |
* TV Timer by Harrison Conlin | |
* http://harrisony.com/tvtimer.html | |
* | |
*/ | |
#include <LiquidCrystal.h>; | |
#define BTN2 (15) | |
#define POT (3) | |
#define PIEZO (9) | |
#define LATCH (11) // LED SHIFT REGISTER | |
#define DATA (12) | |
#define CLOCK (10) | |
LiquidCrystal lcd(6,7,8,2,3,4,5); | |
void setup(void){ | |
lcd.clear(); | |
pinMode(BTN2, INPUT); // Right Button | |
digitalWrite(BTN2, HIGH); | |
pinMode(PIEZO, OUTPUT); // Piezo Buzzer | |
pinMode(LATCH, OUTPUT); // LED Shift Register | |
pinMode(DATA, OUTPUT); | |
pinMode(CLOCK, OUTPUT); | |
ledWrite(0); // Clear the LED's | |
} | |
void loop(void){ | |
lcd.setCursor(0,0); | |
lcd.print("Ready"); | |
lcd.setCursor(0, 1); | |
int minutes = map(analogRead(POT), 0, 1023, 5 , 1); | |
lcd.print("Min: "); | |
lcd.print(minutes); | |
lcd.print(" "); | |
lcd.setCursor(14,1); | |
lcd.print("Go"); | |
if (digitalRead(BTN2) == LOW){ | |
set(minutes*60); // turns minutes to sec | |
} | |
} | |
void alert(void){ | |
long wait_atill = millis() + 300; | |
while (millis() < wait_atill){ | |
digitalWrite(PIEZO, HIGH); | |
delayMicroseconds(2000); | |
digitalWrite(PIEZO, LOW); | |
delayMicroseconds(2000); | |
} | |
ledWrite(0); | |
delay(200); | |
ledWrite(255); | |
delay(200); | |
ledWrite(0); | |
delay(200); | |
ledWrite(255); | |
delay(200); | |
ledWrite(0); | |
} | |
void set(unsigned long time){ // This is when it starts getting really hacky and kludgy | |
lcd.setCursor(14,1); | |
lcd.print(" "); | |
unsigned long origtime = millis(); | |
unsigned long waittime = origtime + (time * 1000); | |
while (millis() < waittime){ | |
byte i = map(millis(), origtime, waittime, 8,0); // For the LED's | |
byte led = (i == 0) ? 0 : ((1 << i) - 1); // don't ask. I found it somewhere and it works (I think) | |
ledWrite(led); | |
lcd.setCursor(0,0); | |
lcd.print("Time:"); | |
lcd.setCursor(6,0); | |
int timeleft = ((waittime - millis())/1000); // time remaining in second | |
if (timeleft > 60) { // If its more than a minute show M SS | |
lcd.print(int(timeleft/60)); | |
lcd.print(" "); | |
lcd.print(timeleft % 60); | |
} | |
else { //Otherwise SS | |
lcd.print(timeleft); | |
} | |
lcd.print(" "); | |
} | |
lcd.setCursor(0,0); | |
lcd.print("Done"); | |
lcd.print(" "); | |
ledWrite(0); | |
alert(); | |
alert(); | |
lcd.clear(); | |
} | |
void ledWrite(byte a){ | |
digitalWrite(LATCH, LOW); | |
shiftOut(DATA, CLOCK, LSBFIRST, a); | |
digitalWrite(LATCH, HIGH); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment