129 lines
5.1 KiB
Arduino
129 lines
5.1 KiB
Arduino
|
/*
|
||
|
Clock for e-radionica.com Inkplate 6
|
||
|
For this example you will need USB cable and Inkplate 6.
|
||
|
Select "Inkplate 6(ESP32)" from Tools -> Board menu.
|
||
|
Don't have "Inkplate 6(ESP32)" option? Follow our tutorial and add it:
|
||
|
https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/
|
||
|
|
||
|
This example will show you how you can use low power functionality of Inkplate board.
|
||
|
In deep sleep, whole board will consume about 25uA from battery.
|
||
|
Inkplate will wake every 60 seconds change content on screen.
|
||
|
|
||
|
NOTE: Because we are using deep sleep, everytime the board wakes up,
|
||
|
it starts program from beginning. Also, whole content from RAM gets erased.
|
||
|
To use partial updates after wakeup, the old bitmap in RAM is recreated.
|
||
|
|
||
|
Want to learn more about Inkplate? Visit www.inkplate.io
|
||
|
Looking to get support? Write on our forums: http://forum.e-radionica.com/en/
|
||
|
15 July 2020 by e-radionica.com
|
||
|
*/
|
||
|
|
||
|
#include "Inkplate.h" //Include Inkplate library to the sketch
|
||
|
#include "driver/rtc_io.h" //ESP32 library used for deep sleep and RTC wake up pins
|
||
|
#include "driver/adc.h"
|
||
|
#include <esp_wifi.h>
|
||
|
#include <esp_bt.h>
|
||
|
|
||
|
//Including bitmaps (created with the LCD Image Converter)
|
||
|
typedef struct {
|
||
|
const uint8_t *data;
|
||
|
uint16_t width;
|
||
|
uint16_t height;
|
||
|
uint8_t dataSize;
|
||
|
} tImage;
|
||
|
#include "binary_icons/icon_char_colon.h"
|
||
|
#include "binary_icons/icon_digit_0.h"
|
||
|
#include "binary_icons/icon_digit_1.h"
|
||
|
#include "binary_icons/icon_digit_2.h"
|
||
|
#include "binary_icons/icon_digit_3.h"
|
||
|
#include "binary_icons/icon_digit_4.h"
|
||
|
#include "binary_icons/icon_digit_5.h"
|
||
|
#include "binary_icons/icon_digit_6.h"
|
||
|
#include "binary_icons/icon_digit_7.h"
|
||
|
#include "binary_icons/icon_digit_8.h"
|
||
|
#include "binary_icons/icon_digit_9.h"
|
||
|
const uint8_t *digits[10] = { image_data_icon_digit_0, image_data_icon_digit_1, image_data_icon_digit_2, image_data_icon_digit_3, image_data_icon_digit_4, image_data_icon_digit_5, image_data_icon_digit_6, image_data_icon_digit_7, image_data_icon_digit_8, image_data_icon_digit_9 };
|
||
|
|
||
|
//Includes
|
||
|
#include <ctime>
|
||
|
#include "Network.h"
|
||
|
|
||
|
//CHANGE HERE ---------------
|
||
|
|
||
|
char *ssid = "Freifunk";
|
||
|
char *pass = "";
|
||
|
int timeZone = 2;
|
||
|
|
||
|
//Set to 1 to flip the screen 180 degrees
|
||
|
#define ROTATION 3
|
||
|
|
||
|
//---------------------------
|
||
|
|
||
|
|
||
|
#define uS_TO_S_FACTOR 1000000 //Conversion factor for micro seconds to seconds
|
||
|
#define TIME_TO_SLEEP 60 //How long ESP32 will be in deep sleep (in seconds)
|
||
|
|
||
|
RTC_DATA_ATTR int timeDigits[4] = { 9, 5, 0, 0 }; // start time: 23:59
|
||
|
|
||
|
Inkplate display(INKPLATE_1BIT); //Create an object on Inkplate library and also set library into 1 Bit mode
|
||
|
Network network; //Our networking functions, see Network.cpp for info
|
||
|
|
||
|
//All our functions declared below setup and loop
|
||
|
void drawTime();
|
||
|
|
||
|
void setup() {
|
||
|
bool networking = false;
|
||
|
|
||
|
//Initial display settings
|
||
|
display.begin(); //Before calling any display method you must call .begin()
|
||
|
display.clearDisplay(); //Clears all data in buffer.
|
||
|
display.setRotation(ROTATION);
|
||
|
|
||
|
//restore old bitmap (before the deep sleep)
|
||
|
drawTime();
|
||
|
display.load1b();
|
||
|
|
||
|
//Update data
|
||
|
// if (timeDigits[0]+timeDigits[1]+timeDigits[2]+timeDigits[3] == 0) {
|
||
|
if ((timeDigits[1] == 5) && (timeDigits[0] == 9)) {
|
||
|
network.begin(); // every midnight set the time from internet
|
||
|
network.off();
|
||
|
networking = true;
|
||
|
}
|
||
|
network.getTime(timeDigits);
|
||
|
|
||
|
// create new bitmap
|
||
|
display.clearDisplay();
|
||
|
drawTime();
|
||
|
|
||
|
//Actually display all data
|
||
|
if (timeDigits[0]+timeDigits[1] == 0 || networking) {
|
||
|
display.display(); // full refresh at full hour or after network update
|
||
|
}
|
||
|
else
|
||
|
display.partialUpdate();
|
||
|
|
||
|
//Sleep
|
||
|
adc_power_off(); //don't forget to turn ADC back before using it (also after wake up from deep sleep)
|
||
|
esp_wifi_stop();
|
||
|
rtc_gpio_isolate(GPIO_NUM_12); //Isolate/disable GPIO12 on ESP32 (only to reduce power consumption in sleep)
|
||
|
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); //Activate wake-up timer -- wake up after 20s here
|
||
|
esp_deep_sleep_start(); //Put ESP32 into deep sleep. Program stops here.
|
||
|
}
|
||
|
|
||
|
void loop() {
|
||
|
//Nothing! If you use deep sleep, whole program should be in setup() because each time the board restarts, not in a loop()! loop() must be empty!
|
||
|
|
||
|
}
|
||
|
|
||
|
//Drawing what time it is
|
||
|
void drawTime()
|
||
|
{
|
||
|
// ??? bug in library: offset 201
|
||
|
display.drawBitmap(201, 0, digits[timeDigits[3]], 134, 317, WHITE, BLACK); //hours (tens)
|
||
|
display.drawBitmap(335, 0, digits[timeDigits[2]], 134, 317, WHITE, BLACK); //hours (units)
|
||
|
display.drawBitmap(469, 0, image_data_icon_char_colon, 64, 317, WHITE, BLACK); //colon
|
||
|
display.drawBitmap(533, 0, digits[timeDigits[1]], 134, 317, WHITE, BLACK); //minutes (tens)
|
||
|
display.drawBitmap(667, 0, digits[timeDigits[0]], 134, 317, WHITE, BLACK); //minutes (units)
|
||
|
}
|