Skip to content

Commit 26505a3

Browse files
committed
Fixed World Clock example
1 parent 5229097 commit 26505a3

File tree

4 files changed

+191
-183
lines changed

4 files changed

+191
-183
lines changed

examples/Inkplate2/Projects/Inkplate2_World_Clock/Inkplate2_World_Clock.ino

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/*
22
Inkplate2_World_Clock example for Soldered Inkplate 2
3-
For this example you will need only USB cable, Inkplate 2 and a WiFi with stable Internet connection.
3+
For this example you will need only USB cable, Inkplate 2 and WiFi.
44
Select "Soldered Inkplate2" from Tools -> Board menu.
55
Don't have "Soldered Inkplate2" option? Follow our tutorial and add it:
66
https://soldered.com/learn/add-inkplate-6-board-definition-to-arduino-ide/
77
88
This example uses API call to get time for wanted city and it's timezone.
99
Fetched data is in JSON format, and library is used to extract data. To choose
10-
city just type any part of city's name and it will be automatically found, but if you type
11-
to few letters, any city containig that letters will be found.
10+
the cities just type a part of city's name and it will be automatically found.
11+
The more letters you type, the more accurate it is.
1212
1313
IMPORTANT:
14-
Make sure to change your wifi credentials below
15-
Also have ArduinoJSON installed in your Arduino libraries, download here: https://arduinojson.org/
14+
Make sure to change your WiFi credentials below.
15+
Also, have ArduinoJSON installed in your Arduino libraries (https://arduinojson.org)
1616
1717
Want to learn more about Inkplate? Visit www.inkplate.io
1818
Looking to get support? Write on our forums: https://forum.soldered.com/
@@ -45,44 +45,43 @@ Inkplate display;
4545
char ssid[] = "";
4646
char pass[] = "";
4747

48-
// Structure for time and date data
49-
struct tm t;
48+
// Variables to store the hours and minutes about to be drawn
49+
int hours;
50+
int minutes;
5051

51-
// You can type part of city's and it will be found automatically.
52-
// The more letters you type, the more chance is that your city will be found.
53-
// Refer to Network.h file for full list of cities. Instead of space use underline
54-
// and every word starts with CAPITAL letter and the rest of letters are not capitals.
52+
// You can type part of city's name and it will be automatically found.
53+
// The more letters you type, the better.
54+
// Refer to Network.h for a full list of cities.
55+
// Important: Instead of space use underline.
56+
// Every word should start with a CAPITAL letter (the rest of letters are lowercase), e.g. "New_York".
5557
// List of all available cities and zones can be found here https://www.timeapi.io/api/TimeZone/AvailableTimeZones
5658
const char city1[] = "Zag";
5759
const char city2[] = "Lim";
5860

59-
// Pointers to store city names
60-
6161
void setup()
6262
{
6363
// Begin serial communitcation, set for debugging
6464
Serial.begin(115200);
6565

66-
// Initial display settings
66+
// Init display
6767
display.begin();
6868

69-
// Our begin function
69+
// Network begin function
7070
network.begin(ssid, pass);
7171

72+
// Get all the available timezones
7273
network.getAllCities();
7374

74-
Serial.print("City 1: ");
75-
if(network.getData((char *)city1, &t))
75+
if (network.getData((char *)city1, &hours, &minutes))
7676
{
77-
// x coordinate, y coordinate, PM/AM indicator, pointer to city name. Use ternary operator to specify PM or AM is currently.
78-
drawTime(17, 1, t.tm_hour >= 12 ? 1 : 0, (char *)city1);
79-
}
77+
// x coordinate, y coordinate, PM/AM indicator, pointer to city name. Use ternary operator to specify AM or PM
78+
drawTime(17, 1, hours >= 12 ? 1 : 0, (char *)city1);
79+
}
8080

81-
Serial.print("City 2: ");
82-
if(network.getData((char *)city2, &t))
81+
if (network.getData((char *)city2, &hours, &minutes))
8382
{
84-
drawTime(115, 1, t.tm_hour >= 12 ? 1 : 0, (char *)city2);
85-
}
83+
drawTime(115, 1, hours >= 12 ? 1 : 0, (char *)city2);
84+
}
8685

8786
display.display();
8887

@@ -96,6 +95,7 @@ void loop()
9695
{
9796
// Never here
9897
}
98+
9999
// Function to draw time
100100
void drawTime(uint16_t x_pos, uint16_t y_pos, bool am, const char *city)
101101
{
@@ -129,10 +129,10 @@ void drawTime(uint16_t x_pos, uint16_t y_pos, bool am, const char *city)
129129

130130
// This part of code draws needles and calculates their angles
131131
int x_minute, y_minute, x_hour, y_hour;
132-
x_minute = x_pos + w / 2 + 30 * (float)sin((t.tm_min / (float)60) * 2 * (float)3.14); //
133-
y_minute = y_pos + w / 2 - 30 * (float)cos((t.tm_min / (float)60) * 2 * (float)3.14);
134-
x_hour = x_pos + w / 2 + 22 * sin((t.tm_hour / (float)12 + t.tm_min / (float)720) * 2 * (float)3.14);
135-
y_hour = y_pos + w / 2 - 22 * cos((t.tm_hour / (float)12 + t.tm_min / (float)720) * 2 * (float)3.14);
132+
x_minute = x_pos + w / 2 + 30 * (float)sin((minutes / (float)60) * 2 * (float)3.14); //
133+
y_minute = y_pos + w / 2 - 30 * (float)cos((minutes / (float)60) * 2 * (float)3.14);
134+
x_hour = x_pos + w / 2 + 22 * sin((hours / (float)12 + minutes / (float)720) * 2 * (float)3.14);
135+
y_hour = y_pos + w / 2 - 22 * cos((hours / (float)12 + minutes / (float)720) * 2 * (float)3.14);
136136

137137
display.drawThickLine(x_pos + w / 2, y_pos + w / 2, x_minute, y_minute, INKPLATE2_RED, 2); // Needle for minutes
138138
display.drawThickLine(x_pos + w / 2, y_pos + w / 2, x_hour, y_hour, INKPLATE2_BLACK, 3); // Needle for hours
@@ -159,3 +159,4 @@ void drawTime(uint16_t x_pos, uint16_t y_pos, bool am, const char *city)
159159
display.setFont(&SourceSansPro_Regular6pt7b); // Set customn font
160160
am ? display.print("PM") : display.print("AM");
161161
}
162+

0 commit comments

Comments
 (0)