-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEspressoShotTimer.ino
64 lines (51 loc) · 1.58 KB
/
EspressoShotTimer.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*********************************************************************
This code is for a 64x48 size
Monochrome OLEDs based on SSD1306 drivers
using I2C to communicate
3 pins are required to interface (2 I2C and one reset)
Written by Christoph Steinbeck,
MIT License
*********************************************************************/
#include <SPI.h>
#include <Wire.h>
#include <Ticker.h>
#include <time.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// SCL GPIO5
// SDA GPIO4
#define OLED_RESET 0 // GPIO0
Adafruit_SSD1306 display(OLED_RESET);
Ticker ticker1;
int seconds = 0;
void setup() {
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 64x48)
/* Start a 1 second ticker which calls the routine displayNumber() below, which again increments the
* seconds counter and updates the OLED display
*/
ticker1.attach(1, displayNumber);
}
void loop() {
delay(100);
}
void displayNumber()
{
char secondsChar[3];
seconds = seconds + 1;
if (seconds > 99) seconds = 0;
// Clear the buffer.
display.clearDisplay();
display.setTextSize(5);
display.setTextColor(WHITE);
String secondsString = String(seconds);
if (seconds < 10) secondsString = "0" + secondsString;
secondsString.toCharArray(secondsChar, 3);
int16_t tbx, tby; uint16_t tbw, tbh;
display.getTextBounds(secondsChar, 0, 0, &tbx, &tby, &tbw, &tbh);
uint16_t x = (display.width() - tbw) / 2 + 2;
uint16_t y = (display.height() - tbh) / 2;
display.setCursor(x,y);
display.println(secondsChar);
display.display();
}