Add some comments

This commit is contained in:
David Zovko 2020-07-31 10:33:14 +02:00 committed by GitHub
parent 648e3b6cd4
commit 01e528022b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 54 additions and 66 deletions

View File

@ -6,55 +6,47 @@
https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/ https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/
This example will show you how you can use Inkplate 6 to display API data, This example will show you how you can use Inkplate 6 to display API data,
e.g. Metaweather public weather API in this example Metaweather public weather API which provide weather info.
As a result, you get a functional weather station which shows today's
forecast and 3 days forecast on your Inkplate display.
IMPORTANT: IMPORTANT:
Make sure to change your desired city, timezone and wifi credentials below Make sure you have changed your desired city, timezone and WiFi credentials below.
Also have ArduinoJSON installed in your Arduino libraries You will also need to install ArduinoJSON library.
Download from here: https://github.com/bblanchon/ArduinoJson
Want to learn more about Inkplate? Visit www.inkplate.io Want to learn more about Inkplate? Visit www.inkplate.io
Looking to get support? Write on our forums: http://forum.e-radionica.com/en/ Looking to get support? Write on our forums: http://forum.e-radionica.com/en/
28 July 2020 by e-radionica.com 28 July 2020 by e-radionica.com
*/ */
// ---------- CHANGE HERE -------------: // ---------------- CHANGE HERE ---------------:
// Time zone for adding hours int timeZone = 2; //Update your timezone here. 2 means UTC+2
int timeZone = 2;
// City search query char city[128] = "SHENZHEN"; //Enter city name you wish to get forecast for
char city[128] = "ZAGREB";
// Change to your wifi ssid and password // Change to your WiFi SSID and password
char *ssid = ""; char *ssid = "e-radionica.com";
char *pass = ""; char *pass = "crodusino";
// ---------------------------------- #define DELAY_MS 15000 //Delay between screen refreshes goes here
// ----------------------------------------------
// Include Inkplate library to the sketch
#include "Inkplate.h" #include "Inkplate.h"
#include "Network.h" //Header file for easier code readability
// Header file for easier code readability //Include custom fonts & icons used
#include "Network.h"
// Including fonts used
#include "Fonts/Roboto_Light_48.h" #include "Fonts/Roboto_Light_48.h"
#include "Fonts/Roboto_Light_36.h" #include "Fonts/Roboto_Light_36.h"
#include "Fonts/Roboto_Light_120.h" #include "Fonts/Roboto_Light_120.h"
#include "icons.h" //Generated using embedded iconConvert.py script
// Including icons generated by the py file Inkplate display(INKPLATE_1BIT); //Inkplate object
#include "icons.h"
// Delay between API calls Network network; // All our network functions are in this object, see Network.h
#define DELAY_MS 15000
// Inkplate object //Constants used for drawing icons
Inkplate display(INKPLATE_1BIT);
// All our network functions are in this object, see Network.h
Network network;
// Contants used for drawing icons
char abbrs[32][16] = {"sn", "sl", "h", "t", "hr", "lr", "s", "hc", "lc", "c"}; char abbrs[32][16] = {"sn", "sl", "h", "t", "hr", "lr", "s", "hc", "lc", "c"};
const uint8_t *logos[16] = {icon_sn, icon_sl, icon_h, icon_t, icon_hr, icon_lr, icon_s, icon_hc, icon_lc, icon_c}; const uint8_t *logos[16] = {icon_sn, icon_sl, icon_h, icon_t, icon_hr, icon_lr, icon_s, icon_hc, icon_lc, icon_c};
@ -74,18 +66,13 @@ char days[8][4] = {
"", "",
}; };
// Variable for counting partial refreshes long refreshes = 0; //Variable for counting partial refreshes
long refreshes = 0; const int fullRefresh = 10; //Constant to determine when to full update
// Constant to determine when to full update
const int fullRefresh = 10;
//Variables for storing current time and weather info //Variables for storing current time and weather info
char currentTemp[16] = "0F"; char currentTemp[16] = "0F";
char currentWind[16] = "0m/s"; char currentWind[16] = "0m/s";
char currentTime[16] = "9:41"; char currentTime[16] = "9:41";
char currentWeather[32] = "-"; char currentWeather[32] = "-";
char currentWeatherAbbr[8] = "th"; char currentWeatherAbbr[8] = "th";
@ -98,9 +85,9 @@ void drawTime();
void setup() void setup()
{ {
// Begin serial and display //Begin serial and and begin display
Serial.begin(115200); Serial.begin(115200);
display.begin(); display.begin(); //Call this function only once!
//Initial cleaning of buffer and physical screen //Initial cleaning of buffer and physical screen
display.clearDisplay(); display.clearDisplay();
@ -109,7 +96,7 @@ void setup()
//Calling our begin from network.h file //Calling our begin from network.h file
network.begin(city); network.begin(city);
// If city not found, do nothing //If city not found, write error message and stop
if (network.location == -1) if (network.location == -1)
{ {
display.setCursor(50, 290); display.setCursor(50, 290);
@ -127,7 +114,7 @@ void setup()
display.display(); display.display();
//Wait a bit before proceeding //Wait a bit before proceeding
delay(5000); delay(3000);
} }
void loop() void loop()
@ -140,14 +127,14 @@ void loop()
network.getDays(days[0], days[1], days[2], days[3]); network.getDays(days[0], days[1], days[2], days[3]);
network.getData(city, temps[0], temps[1], temps[2], temps[3], currentTemp, currentWind, currentTime, currentWeather, currentWeatherAbbr); network.getData(city, temps[0], temps[1], temps[2], temps[3], currentTemp, currentWind, currentTime, currentWeather, currentWeatherAbbr);
// Draw data, see functions below for info //Draw data, see functions below in Network.cpp for info
drawWeather(); drawWeather();
drawCurrent(); drawCurrent();
drawTemps(); drawTemps();
drawCity(); drawCity();
drawTime(); drawTime();
// Refresh full screen every fullRefresh times, defined above //Refresh full screen every fullRefresh times
if (refreshes % fullRefresh == 0) if (refreshes % fullRefresh == 0)
display.display(); display.display();
else else
@ -165,12 +152,12 @@ void drawWeather()
// Searching for weather state abbreviation // Searching for weather state abbreviation
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
{ {
// If found draw specified icon //If found draw specified icon, draw it
if (strcmp(abbrs[i], currentWeatherAbbr) == 0) if (strcmp(abbrs[i], currentWeatherAbbr) == 0)
display.drawBitmap(50, 50, logos[i], 152, 152, BLACK); display.drawBitmap(50, 50, logos[i], 152, 152, BLACK);
} }
// Draw weather state //Draw current weather state
display.setTextColor(BLACK, WHITE); display.setTextColor(BLACK, WHITE);
display.setFont(&Roboto_Light_36); display.setFont(&Roboto_Light_36);
display.setTextSize(1); display.setTextSize(1);
@ -181,7 +168,7 @@ void drawWeather()
//Function for drawing current time //Function for drawing current time
void drawTime() void drawTime()
{ {
// Drawing current time //Drawing current time stored in currentTime variable
display.setTextColor(BLACK, WHITE); display.setTextColor(BLACK, WHITE);
display.setFont(&Roboto_Light_36); display.setFont(&Roboto_Light_36);
display.setTextSize(1); display.setTextSize(1);
@ -205,7 +192,7 @@ void drawCity()
//Function for drawing temperatures //Function for drawing temperatures
void drawTemps() void drawTemps()
{ {
// Drawing 4 black rectangles in which temperatures will be written //Drawing 4 black rectangles into which temperatures will be written
int rectWidth = 150; int rectWidth = 150;
int rectSpacing = (800 - rectWidth * 4) / 5; int rectSpacing = (800 - rectWidth * 4) / 5;
@ -216,6 +203,7 @@ void drawTemps()
int textMargin = 6; int textMargin = 6;
//Setting font specifics, writing the actual weather info
display.setFont(&Roboto_Light_48); display.setFont(&Roboto_Light_48);
display.setTextSize(1); display.setTextSize(1);
display.setTextColor(WHITE, BLACK); display.setTextColor(WHITE, BLACK);