Add some comments
This commit is contained in:
parent
648e3b6cd4
commit
01e528022b
|
@ -6,55 +6,47 @@
|
|||
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,
|
||||
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:
|
||||
Make sure to change your desired city, timezone and wifi credentials below
|
||||
Also have ArduinoJSON installed in your Arduino libraries
|
||||
Make sure you have changed your desired city, timezone and WiFi credentials below.
|
||||
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
|
||||
Looking to get support? Write on our forums: http://forum.e-radionica.com/en/
|
||||
28 July 2020 by e-radionica.com
|
||||
*/
|
||||
|
||||
// ---------- CHANGE HERE -------------:
|
||||
// ---------------- CHANGE HERE ---------------:
|
||||
|
||||
// Time zone for adding hours
|
||||
int timeZone = 2;
|
||||
int timeZone = 2; //Update your timezone here. 2 means UTC+2
|
||||
|
||||
// City search query
|
||||
char city[128] = "ZAGREB";
|
||||
char city[128] = "SHENZHEN"; //Enter city name you wish to get forecast for
|
||||
|
||||
// Change to your wifi ssid and password
|
||||
char *ssid = "";
|
||||
char *pass = "";
|
||||
// Change to your WiFi SSID and password
|
||||
char *ssid = "e-radionica.com";
|
||||
char *pass = "crodusino";
|
||||
|
||||
// ----------------------------------
|
||||
#define DELAY_MS 15000 //Delay between screen refreshes goes here
|
||||
|
||||
// ----------------------------------------------
|
||||
|
||||
// Include Inkplate library to the sketch
|
||||
#include "Inkplate.h"
|
||||
|
||||
// Header file for easier code readability
|
||||
#include "Network.h"
|
||||
|
||||
// Including fonts used
|
||||
#include "Network.h" //Header file for easier code readability
|
||||
//Include custom fonts & icons used
|
||||
#include "Fonts/Roboto_Light_48.h"
|
||||
#include "Fonts/Roboto_Light_36.h"
|
||||
#include "Fonts/Roboto_Light_120.h"
|
||||
#include "icons.h" //Generated using embedded iconConvert.py script
|
||||
|
||||
// Including icons generated by the py file
|
||||
#include "icons.h"
|
||||
Inkplate display(INKPLATE_1BIT); //Inkplate object
|
||||
|
||||
// Delay between API calls
|
||||
#define DELAY_MS 15000
|
||||
Network network; // All our network functions are in this object, see Network.h
|
||||
|
||||
// Inkplate object
|
||||
Inkplate display(INKPLATE_1BIT);
|
||||
|
||||
// All our network functions are in this object, see Network.h
|
||||
Network network;
|
||||
|
||||
// Contants used for drawing icons
|
||||
//Constants used for drawing icons
|
||||
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};
|
||||
|
||||
|
@ -74,18 +66,13 @@ char days[8][4] = {
|
|||
"",
|
||||
};
|
||||
|
||||
// Variable for counting partial refreshes
|
||||
long refreshes = 0;
|
||||
|
||||
// Constant to determine when to full update
|
||||
const int fullRefresh = 10;
|
||||
long refreshes = 0; //Variable for counting partial refreshes
|
||||
const int fullRefresh = 10; //Constant to determine when to full update
|
||||
|
||||
//Variables for storing current time and weather info
|
||||
char currentTemp[16] = "0F";
|
||||
char currentWind[16] = "0m/s";
|
||||
|
||||
char currentTime[16] = "9:41";
|
||||
|
||||
char currentWeather[32] = "-";
|
||||
char currentWeatherAbbr[8] = "th";
|
||||
|
||||
|
@ -98,9 +85,9 @@ void drawTime();
|
|||
|
||||
void setup()
|
||||
{
|
||||
// Begin serial and display
|
||||
//Begin serial and and begin display
|
||||
Serial.begin(115200);
|
||||
display.begin();
|
||||
display.begin(); //Call this function only once!
|
||||
|
||||
//Initial cleaning of buffer and physical screen
|
||||
display.clearDisplay();
|
||||
|
@ -109,7 +96,7 @@ void setup()
|
|||
//Calling our begin from network.h file
|
||||
network.begin(city);
|
||||
|
||||
// If city not found, do nothing
|
||||
//If city not found, write error message and stop
|
||||
if (network.location == -1)
|
||||
{
|
||||
display.setCursor(50, 290);
|
||||
|
@ -127,7 +114,7 @@ void setup()
|
|||
display.display();
|
||||
|
||||
//Wait a bit before proceeding
|
||||
delay(5000);
|
||||
delay(3000);
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
@ -140,14 +127,14 @@ void loop()
|
|||
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);
|
||||
|
||||
// Draw data, see functions below for info
|
||||
//Draw data, see functions below in Network.cpp for info
|
||||
drawWeather();
|
||||
drawCurrent();
|
||||
drawTemps();
|
||||
drawCity();
|
||||
drawTime();
|
||||
|
||||
// Refresh full screen every fullRefresh times, defined above
|
||||
//Refresh full screen every fullRefresh times
|
||||
if (refreshes % fullRefresh == 0)
|
||||
display.display();
|
||||
else
|
||||
|
@ -165,12 +152,12 @@ void drawWeather()
|
|||
// Searching for weather state abbreviation
|
||||
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)
|
||||
display.drawBitmap(50, 50, logos[i], 152, 152, BLACK);
|
||||
}
|
||||
|
||||
// Draw weather state
|
||||
//Draw current weather state
|
||||
display.setTextColor(BLACK, WHITE);
|
||||
display.setFont(&Roboto_Light_36);
|
||||
display.setTextSize(1);
|
||||
|
@ -181,7 +168,7 @@ void drawWeather()
|
|||
//Function for drawing current time
|
||||
void drawTime()
|
||||
{
|
||||
// Drawing current time
|
||||
//Drawing current time stored in currentTime variable
|
||||
display.setTextColor(BLACK, WHITE);
|
||||
display.setFont(&Roboto_Light_36);
|
||||
display.setTextSize(1);
|
||||
|
@ -205,7 +192,7 @@ void drawCity()
|
|||
//Function for drawing temperatures
|
||||
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 rectSpacing = (800 - rectWidth * 4) / 5;
|
||||
|
||||
|
@ -216,6 +203,7 @@ void drawTemps()
|
|||
|
||||
int textMargin = 6;
|
||||
|
||||
//Setting font specifics, writing the actual weather info
|
||||
display.setFont(&Roboto_Light_48);
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(WHITE, BLACK);
|
||||
|
|
Loading…
Reference in New Issue