/*
Simple countdown timer with number counting down. Will start when a button is pressed.
Author: F. van Slooten
More info:
https://home.et.utwente.nl/slootenvanf/2020/06/08/countdown-timers-tasks-in-parallel/
*/
#include <U8g2lib.h>
#define START_BTN 4
U8X8_SSD1306_128X64_NONAME_HW_I2C display(U8X8_PIN_NONE);
int count = 10;
char buf[10]; // text buffer; to be able to use draw2x2String to show the value
void setup() {
Serial.begin(9600);
pinMode(START_BTN, INPUT_PULLUP); // start button, without resistor (internal pull-up)
display.begin();
display.setPowerSave(0);
display.setFont(u8x8_font_pxplusibmcgathin_f);
// wait until button pressed to proceed:
// (this while statement halts the program, until the button is pressed)
while(digitalRead(START_BTN)==HIGH) ; // note the empty statement: ';' does nothing, thus waits for START_BTN to be pressed (becomes LOW)
}
void loop() {
if (count>=0) { // if counter not finished
snprintf(buf, 10, "%2d", count);
display.draw2x2String(4,3,buf); // show the counter
count = count - 1; // decrease counter
}
delay(1000); // wait one second
}
nano:12
nano:11
nano:10
nano:9
nano:8
nano:7
nano:6
nano:5
nano:4
nano:3
nano:2
nano:GND.2
nano:RESET.2
nano:0
nano:1
nano:13
nano:3.3V
nano:AREF
nano:A0
nano:A1
nano:A2
nano:A3
nano:A4
nano:A5
nano:A6
nano:A7
nano:5V
nano:RESET
nano:GND.1
nano:VIN
nano:12.2
nano:5V.2
nano:13.2
nano:11.2
nano:RESET.3
nano:GND.3
oled1:GND
oled1:VCC
oled1:SCL
oled1:SDA
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r