/*********************************************
* Thermometer mit
*
* ATTiny 85
* OLED-Display
* DS18B20 Sensor
*
* Soll mal in meinen Roller, also 12V mit 7805 100mA Festspannuingsregler
*********************************************/
/***********************************
* DS18B20
*/
#include <OneWire.h>
#include <DallasTemperature.h>
const int oneWireBus = PB1; //GPIO Pin 1-Wire Bus
OneWire oneWire(oneWireBus);
DallasTemperature sensors(&oneWire);
/***********************************
* für das OLED-Display
*/
#include <TinyWireM.h>
#include <Tiny4kOLED.h>
uint8_t width = 128;
uint8_t height = 64;
// 'Celsius', 24x32px
const unsigned char bitmap_Celsius [] PROGMEM = {
0xf8, 0xfc, 0x8e, 0x07, 0x03, 0x03, 0x03, 0x07, 0x0e, 0xfe, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x06, 0xc6, 0xe6, 0xf7,
0xfb, 0xff, 0x3c, 0x0e, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x0c, 0x1c, 0x7c, 0xfe, 0xfe, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xc1, 0xc1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07,
0x07, 0x0f, 0x0f, 0x1c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x0c, 0x0c, 0x07, 0x03, 0x00, 0x00
};
// 'Percent', 24x32px
const unsigned char bitmap_Volt [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xe0, 0xf8, 0x7c, 0x1c, 0x04, 0x06,
0x84, 0xfc, 0x08, 0x08, 0x88, 0xe8, 0x3c, 0x0c, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x03, 0x07, 0x04, 0x04, 0x04, 0x02, 0xc1, 0x70, 0x1c, 0x06, 0x01, 0xf0, 0xf8, 0x7c,
0x1e, 0x06, 0x02, 0x82, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x03,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x06, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00
};
/*************************************
* Heartbeat
*/
#define LED_PIN PB4
unsigned long event_Heartbeat; // nächstes ereigniss
const long delta_Heartbeat = 50; // alle 100 mS
int act_LED;
int delta_LED;
/***********************************
* Oversampling,
* Mittelwert über mehrere Messungen
*/
float Summe;
float lasttemp;
float lastVolt;
/*****************************************
* kein Delaay, sondern Digits
*/
unsigned long act_Millis;
unsigned long event_Sensor;
const long delta_Sensor = 2000;
/************************************************
* Splash-Screen beim Programmstart
*************************************************/
void splash() {
/* oled.setFont(FONT8X16);
oled.setCursor(4, 0); // x: pixel / y: line je 8 pixel
oled.print("Dieses Motorrad");
oled.setCursor(0,2);
oled.print("ist Eigentum von");
oled.setCursor(4,4);
oled.print("Robert Kesseler");
oled.setCursor(0,6);
oled.print("DS18B20"); */
}
/************************************************
* Bildschirm vorbereiten
*************************************************/
void initScreen() {
oled.clear();
oled.setFontX2Smooth(FONT8X16);
oled.bitmap(100, 0, 124, 4, bitmap_Celsius);
oled.bitmap(100, 4, 124, 8, bitmap_Volt);
}
/************************************************
* Devault-Werte setzen
*************************************************/
void setDefaults() {
lasttemp = -100;
lastVolt = -100;
act_Millis = millis();
event_Heartbeat = act_Millis;
event_Sensor = act_Millis;
act_LED = 0;
delta_LED = 5;
}
/************************************************
* LED langsam auf und abblenden
* return: neues Heartbeat Event
* actmillis: Actuelle Zeit in Millis
*************************************************/
unsigned long HeartBeat(unsigned long actmillis) {
act_LED = act_LED + delta_LED;
if ( (act_LED<0) or (act_LED>250) ) {
delta_LED = -delta_LED;
} else {
analogWrite(LED_PIN, act_LED);
}
return actmillis+delta_Heartbeat;
}
/****************************************************
* sensorAction
* lesen des Temperatursensors und ausgabe der Werte
*****************************************************/
unsigned long SensorAction(unsigned long actmillis) {
sensors.requestTemperatures();
float temperatureC = sensors.getTempCByIndex(0);
float temperatureF = sensors.getTempFByIndex(0);
oled.setCursor(48,0); //x in Pixel, y in Zeilen (je 8 Pixel)
oled.print(" ");
oled.setCursor(0,0); //x in Pixel, y in Zeilen (je 8 Pixel)
oled.print(temperatureC,1);
/* Ausgabe */
/*
if(lasttemp!=DHT.temperature) {
lasttemp = DHT.temperature;
oled.setCursor(48,0); //x in Pixel, y in Zeilen (je 8 Pixel)
oled.print(" ");
oled.setCursor(0,0); //x in Pixel, y in Zeilen (je 8 Pixel)
oled.print(lasttemp,1);
}
if(lasthumi!=DHT.humidity) {
lasthumi = DHT.humidity;
oled.setCursor(48,4); //x in Pixel, y in Zeilen (je 8 Pixel)
oled.print(" ");
oled.setCursor(0,4); //x in Pixel, y in Zeilen (je 8 Pixel)
oled.print(lasthumi,1);
}
*/
return actmillis + delta_Sensor;
}
/* ==============================================================
Setup
=============================================================== */
void setup() {
sensors.begin();
sensors.setResolution(12);
//
// ATTiny vorbereiten
//
pinMode(LED_PIN,OUTPUT);
analogWrite(LED_PIN, 200);
//
// Starten der Librarys,
//
TinyWireM.begin();
oled.begin(width, height, sizeof(tiny4koled_init_128x64br), tiny4koled_init_128x64br);
oled.clear(); //Speicher Löschen
oled.on();
//
// Splashscreen
// Initialisierunge
// 3sek warten
//
splash();
delay(1000);
initScreen();
setDefaults();
}
/*================================================================
Loop
================================================================= */
void loop() {
act_Millis = millis();
if (act_Millis >= event_Heartbeat) event_Heartbeat = HeartBeat(act_Millis);
/* Sesor alle delta_temperature abfragen */
// if (act_Millis >= event_Sensor) event_Sensor = SensorAction(act_Millis);
}