Skip to content

Instantly share code, notes, and snippets.

@MrTrick
Last active January 1, 2016 04:19
Show Gist options
  • Save MrTrick/8090806 to your computer and use it in GitHub Desktop.
Save MrTrick/8090806 to your computer and use it in GitHub Desktop.
void loop() {
...
if (state == IDLE) {
//Start? If an interval is given, and there is no error.
if ((digitalRead(RUN_BTN) == HIGH) && (interval != 0) && !has_error) { setState(RUN); beep(); return; }
//Are some buttons pressed? Adjust the interval.
boolean p1 = (digitalRead(P1_BTN) == LOW);
boolean p10 = (digitalRead(P10_BTN) == LOW);
if (p1 || p10) {
if (p1 && p10) { interval = 0; } //Reset interval
else if (p1) { interval += 60; } //+1 minute
else if (p10) { interval += 600; }//+10 minutes
Serial.print("Updated interval: ");
displayTime(interval);
beep();
}
}
...
}
/**
* Display the given interval on the screen
* @param time The time, in seconds
*/
void displayTime(int time) {
time_display.writeDigitNum(0, (time / 600));
time_display.writeDigitNum(1, (time / 60) % 10);
time_display.drawColon(true);
time_display.writeDigitNum(3, (time / 10) % 6);
time_display.writeDigitNum(4, (time % 10));
time_display.writeDisplay();
Serial.write('0' + (time / 600) );
Serial.write('0' + ((time / 60) % 10) );
Serial.write(':');
Serial.write('0' + ((time / 10) % 6) );
Serial.write('0' + (time % 10) );
Serial.write('\n');
}
/**
* Sound the buzzer for a short or long period
*/
void beep() { digitalWrite(BUZZER, HIGH); delay(500); digitalWrite(BUZZER, LOW); }
void beeeep() { digitalWrite(BUZZER, HIGH); delay(2000); digitalWrite(BUZZER, LOW); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment