View Single Post
Old 01-03-16, 02:33 PM   #28
Acuario
Apprentice EcoRenovator
 
Join Date: May 2011
Location: Tortosa, Spain
Posts: 221
Thanks: 2
Thanked 81 Times in 46 Posts
Default

14. OLED.ino
/*
Universal 8 bit Graphics Library, u8glib - Universal Graphics Library for 8 Bit Embedded Systems - Google Project Hosting
*/
#include <Wire.h> // Comes with Arduino IDE
#include <U8glib.h>

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0 | U8G_I2C_OPT_NO_ACK | U8G_I2C_OPT_FAST); // Fast I2C / TWI


void failureBAC1000(void) {
u8g.setFont(u8g_font_unifont);
u8g.drawStr(0, 10, "Fail to read BAC1000");
}

// graphic commands to redraw the complete screen should be placed here
void draw(void) {
char line1[20]; // used to store strings

u8g.setFont(u8g_font_unifont);

readTime(); //Get the time from the DS1307
if (lcd_page == LCD_PAGE0) {
sprintf(line1, "%02d:%02d:%02d %02d/%02d", tm.Hour, tm.Minute, tm.Second, tm.Day, tm.Month);
u8g.drawStr(0, 10, line1);

char t[3];
char u[3];
dtostrf(tempCompressor, 2, 0, t);
dtostrf(tempEvaporator, 2, 0, u);
sprintf(line1, "Cp:%s Ev:%s", t, u);
u8g.drawStr(0, 22, line1);

//Dewpoint
dtostrf(dewPointTemp, 5, 2, t);
sprintf(line1, "Dp:%s", t);
//u8g.drawBitmapP(0, 25, 1, 8, dropletIco);
u8g.drawStr(0, 34, line1);

if (defrostFlag == FALSE)
sprintf(line1, "Machine:%s", operatingState == FALSE ? "OFF" : "ON");
else
sprintf(line1, "Machine:%s Def:%d", operatingState == FALSE ? "OFF" : "ON", defrostStartTime - (int)(defrostRunTime / 1000));
u8g.drawStr(0, 46, line1);
sprintf(line1, "%s", systemState);
u8g.drawStr(0, 58, line1);
}
}

NIL_THREAD(threadDisplayOLED, arg) {
while (TRUE) {

wdt_reset(); //Reset watchdog timer

u8g.firstPage(); // picture loop
do {
draw();
nilThdSleepMilliseconds(50);

} while (u8g.nextPage());

// rebuild the picture after some delay
nilThdSleepMilliseconds(100);
}
}
Acuario is offline   Reply With Quote