This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:iot:examples:oled [2018/05/21 08:16] – Somepub | en:iot:examples:oled [Unknown date] (current) – external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 7: | Line 7: | ||
Needed libraries: | Needed libraries: | ||
- | < | + | < |
The example code above shows counter value on screen | The example code above shows counter value on screen | ||
<code c> | <code c> | ||
- | |||
#include < | #include < | ||
#include < | #include < | ||
#include < | #include < | ||
#include < | #include < | ||
- | #include <SPI.h> | + | #include <Adafruit_I2CDevice.h> |
- | #include <Wire.h> | + | |
#include < | #include < | ||
#include < | #include < | ||
+ | #define WIFI_NAME " | ||
+ | #define WIFI_PASSWORD " | ||
+ | |||
+ | // OLED reset pin is GPIO0 | ||
#define OLED_RESET 0 // GPIO0 | #define OLED_RESET 0 // GPIO0 | ||
Ticker timeTicker; | Ticker timeTicker; | ||
- | Adafruit_SSD1306 display(OLED_RESET); | + | Adafruit_SSD1306 display(OLED_RESET); |
- | // ITT splashs screen bitmap. Generator: http:// | + | bool isBootModeNormal; |
+ | bool sendDataFlag; | ||
+ | |||
+ | int i = 0; // Counter variable is defined | ||
+ | |||
+ | // ITT splashs screen bitmap. Generator | ||
static const unsigned char PROGMEM logo16_glcd_bmp[] = | static const unsigned char PROGMEM logo16_glcd_bmp[] = | ||
{ | { | ||
Line 55: | Line 62: | ||
0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | 0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
}; | }; | ||
- | |||
- | #if (SSD1306_LCDHEIGHT != 48) | ||
- | # | ||
- | #endif | ||
- | |||
- | bool isBootModeNormal; | ||
- | bool sendDataFlag; | ||
- | |||
- | int i = 0; | ||
// Ticker library callback, which will occur 0.5 second interval. | // Ticker library callback, which will occur 0.5 second interval. | ||
Line 69: | Line 67: | ||
{ | { | ||
sendDataFlag=true; | sendDataFlag=true; | ||
+ | } | ||
+ | |||
+ | // If message received print it out. | ||
+ | void iot_received(String topic, String msg) | ||
+ | { | ||
+ | Serial.print(" | ||
+ | Serial.print(topic); | ||
+ | Serial.print(" | ||
+ | Serial.println(msg); | ||
} | } | ||
Line 81: | Line 88: | ||
void setup() | void setup() | ||
{ | { | ||
- | Serial.begin(115200); | + | Serial.begin(115200); |
Serial.println(" | Serial.println(" | ||
Line 87: | Line 94: | ||
display.begin(SSD1306_SWITCHCAPVCC, | display.begin(SSD1306_SWITCHCAPVCC, | ||
- | // Since the buffer is intialized | + | // Since the buffer is initialized |
// internally, we should clear it | // internally, we should clear it | ||
display.clearDisplay(); | display.clearDisplay(); | ||
Line 98: | Line 105: | ||
// Display splashscreen two second | // Display splashscreen two second | ||
delay(2000); | delay(2000); | ||
+ | |||
+ | // | ||
+ | // | ||
// print IoT json config to serial | // print IoT json config to serial | ||
Line 109: | Line 119: | ||
} | } | ||
+ | // Main code, which runs in loop | ||
void loop() | void loop() | ||
{ | { | ||
Line 114: | Line 125: | ||
iot.handle(); | iot.handle(); | ||
- | // Increase counter value | + | // Increase counter value by 1 |
i++; | i++; | ||
- | // Display counter value and boot mode on the OLED screen | + | // Display counter value on the OLED screen |
- | display.clearDisplay(); | + | display.clearDisplay(); |
- | display.setTextSize(1); | + | display.setTextSize(1); |
- | display.setTextColor(WHITE); | + | display.setTextColor(WHITE); |
- | display.setCursor(0, | + | display.setCursor(0, |
- | display.println(" | + | display.println(" |
- | display.println(i); | + | display.println(i); |
- | + | display.display(); | |
- | display.setCursor(0, | + | |
- | + | ||
- | if(isBootModeNormal) | + | |
- | { | + | |
- | display.println(" | + | |
- | } | + | |
- | else | + | |
- | { | + | |
- | display.println(" | + | |
- | } | + | |
- | + | ||
- | display.display(); | + | |
- | // Send counter value to the server | + | // Send counter value to the computer |
if(WiFi.isConnected() && isBootModeNormal) | if(WiFi.isConnected() && isBootModeNormal) | ||
{ | { | ||
Line 149: | Line 148: | ||
} | } | ||
} | } | ||
+ | |||
+ | delay(500); // delay of 0.5s, to change the counter value slowly | ||
} | } | ||
- | |||
</ | </ |