/*
Keeping the heart icon for future heartbeat sensor use
*/
#include <TinyWireM.h>
#include <Tiny4kOLED.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Pin definition for DS18B20
#define ONE_WIRE_BUS PB1 // PB4 (physical pin 3)
const unsigned char img_heart_small[] PROGMEM = {
0x00, 0x00, 0xc0, 0xe0, 0xe0, 0xe0, 0xc0, 0x80, 0x80, 0x80, 0xc0, 0xe0, 0xe0, 0xe0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00
};
const unsigned char img_heart_big[] PROGMEM = {
0xe0, 0xf0, 0xf8, 0xf8, 0xf8, 0xf8, 0xf0, 0xe0, 0xe0, 0xe0, 0xf0, 0xf8, 0xf8, 0xf8, 0xf8, 0xf0, 0xe0, 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00
};
const unsigned char img_thermometer[] PROGMEM = {
0x00, 0xfe, 0x03, 0xfe, 0x50,
0x00, 0xff, 0x00, 0xff, 0x55,
0x60, 0x9f, 0x80, 0x9f, 0x65,
};
// Initialize OneWire and DallasTemperature
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void splash() {
oled.clear();
oled.setCursor(15, 1);
oled.print(F("ATtiny85+SSD1306"));
oled.setCursor(42, 3);
oled.print(F("Example"));
oled.setCursor(35, 7);
oled.print(F("wokwi.com"));
}
void heartBeat() {
static char big = 1;
static long startTime = 0;
long currentTime;
currentTime = millis();
if ((currentTime - startTime) > 200) {
startTime = currentTime;
big = 1 - big;
if (big) {
oled.bitmap(20, 4, 37, 6, img_heart_big);
} else {
oled.bitmap(20, 4, 37, 6, img_heart_small);
}
}
}
void prepareDisplay() {
oled.clear();
oled.begin();
oled.setCursor(20, 1);
oled.print(F("ATtiny85+SSD1306"));
oled.setCursor(3, 2);
oled.print(F("temperature"));
oled.bitmap(105, 4, 110, 7, img_thermometer);
oled.setCursor(57, 4);
oled.print(F("24.0C"));
oled.bitmap(10, 5, 17, 2, img_heart_small);
}
float getTemperature() {
sensors.requestTemperatures();
return sensors.getTempCByIndex(0);
}
void setup() {
TinyWireM.begin();
oled.begin(128, 64, sizeof(tiny4koled_init_128x64br), tiny4koled_init_128x64br);
oled.setFont(FONT6X8);
oled.clear();
oled.on();
sensors.begin();
splash();
delay(3000);
prepareDisplay();
}
void loop() {
static long startTime = 0;
long currentTime;
currentTime = millis();
if ((currentTime - startTime) > 1000) {
startTime = currentTime;
float temperature = getTemperature();
oled.setCursor(57, 4);
if (temperature == DEVICE_DISCONNECTED_C) {
oled.print(F("Error "));
} else {
oled.print(temperature, 2);
oled.print(F("C "));
}
oled.bitmap(105, 4, 110, 7, img_thermometer);
}
heartBeat();
}