Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * I have two essays to write. Each 5000 words with a tonne
- * of literature review required. The deadline is fast
- * approaching.
- *
- * I can't start writing until I have some form of hardware
- * timer to let me know how long I've been working for. If
- * this program were on twitter: #procrastination
- *
- * LEDs count up 10 minute increments (in binary) reseting
- * at 60 minutes with an alarm tone.
- *
- * Mark Ruff, April 2016
- */
- // GLOBALS
- // LED pins
- int pin1 = 8;
- int pin2 = 7;
- int pin3 = 4;
- int indicatorLed = 13; // so I know it's working
- int resetSwitch = 2;
- int speaker = 11;
- // timing
- unsigned long int timer = 0;
- unsigned long int prevMillis = 0;
- unsigned long int ledTime = 600000; // time to increment the LEDS = 10 mins
- unsigned long int alarmTime = 3600000; // time to alarm and reset LEDS/counter
- // notes for alarm
- int alarmNoteCount = 3;
- int alarmNotes[] = { 196, 196, 261 };
- int alarmNoteLen[] { 500, 250, 2000 };
- void setup() {
- // LED pins and speaker = output, reset switch = input
- pinMode(pin1,OUTPUT);
- pinMode(pin2,OUTPUT);
- pinMode(pin3,OUTPUT);
- pinMode(speaker,OUTPUT);
- pinMode(resetSwitch,INPUT);
- pinMode(indicatorLed,OUTPUT);
- }
- void loop() {
- // increment the timer
- timer += millis() - prevMillis;
- prevMillis = millis();
- if (digitalRead(resetSwitch) == HIGH) {
- // reset stuff
- digitalWrite(pin1, LOW);
- digitalWrite(pin2, LOW);
- digitalWrite(pin3, LOW);
- timer = 0;
- // need delay to get finger off the button
- delay(500);
- }
- if ( timer > alarmTime ) {
- // flash LEDs
- for ( int i = 0 ; i < 10 ; i++ ) {
- digitalWrite(pin1, HIGH);
- digitalWrite(pin2, HIGH);
- digitalWrite(pin3, HIGH);
- delay(200);
- digitalWrite(pin1, LOW);
- digitalWrite(pin2, LOW);
- digitalWrite(pin3, LOW);
- delay(100);
- }
- // play alarm
- for (int i = 0 ; i < alarmNoteCount ; i++ ) {
- tone(speaker, alarmNotes[i], alarmNoteLen[i]);
- delay(alarmNoteLen[i]);
- }
- // reset timer
- timer = 0;
- }
- // light up the LEDs for the time
- int timerConversion = timer / ledTime;
- if (timerConversion == 1 || timerConversion == 3 || timerConversion == 5) {
- digitalWrite(pin1, HIGH);
- }
- else {
- digitalWrite(pin1, LOW);
- }
- if (timerConversion == 2 || timerConversion == 3 || timerConversion == 6) {
- digitalWrite(pin2, HIGH);
- }
- else {
- digitalWrite(pin2, LOW);
- }
- if (timerConversion > 3) {
- digitalWrite(pin3, HIGH);
- }
- else {
- digitalWrite(pin3, LOW);
- }
- // give the poor little Arduino a rest
- delay(200);
- // let me know the thing is actually working (flash on/off every second)
- if ( (timer / 1000)%2 == 0 ) {
- digitalWrite(indicatorLed, HIGH);
- }
- else {
- digitalWrite(indicatorLed, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement