1
1
/*
2
2
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.
4
4
Select "Soldered Inkplate2" from Tools -> Board menu.
5
5
Don't have "Soldered Inkplate2" option? Follow our tutorial and add it:
6
6
https://soldered.com/learn/add-inkplate-6-board-definition-to-arduino-ide/
7
7
8
8
This example uses API call to get time for wanted city and it's timezone.
9
9
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 .
12
12
13
13
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)
16
16
17
17
Want to learn more about Inkplate? Visit www.inkplate.io
18
18
Looking to get support? Write on our forums: https://forum.soldered.com/
@@ -45,44 +45,43 @@ Inkplate display;
45
45
char ssid[] = " " ;
46
46
char pass[] = " " ;
47
47
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;
50
51
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".
55
57
// List of all available cities and zones can be found here https://www.timeapi.io/api/TimeZone/AvailableTimeZones
56
58
const char city1[] = " Zag" ;
57
59
const char city2[] = " Lim" ;
58
60
59
- // Pointers to store city names
60
-
61
61
void setup ()
62
62
{
63
63
// Begin serial communitcation, set for debugging
64
64
Serial.begin (115200 );
65
65
66
- // Initial display settings
66
+ // Init display
67
67
display.begin ();
68
68
69
- // Our begin function
69
+ // Network begin function
70
70
network.begin (ssid, pass);
71
71
72
+ // Get all the available timezones
72
73
network.getAllCities ();
73
74
74
- Serial.print (" City 1: " );
75
- if (network.getData ((char *)city1, &t))
75
+ if (network.getData ((char *)city1, &hours, &minutes))
76
76
{
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
+ }
80
80
81
- Serial.print (" City 2: " );
82
- if (network.getData ((char *)city2, &t))
81
+ if (network.getData ((char *)city2, &hours, &minutes))
83
82
{
84
- drawTime (115 , 1 , t. tm_hour >= 12 ? 1 : 0 , (char *)city2);
85
- }
83
+ drawTime (115 , 1 , hours >= 12 ? 1 : 0 , (char *)city2);
84
+ }
86
85
87
86
display.display ();
88
87
@@ -96,6 +95,7 @@ void loop()
96
95
{
97
96
// Never here
98
97
}
98
+
99
99
// Function to draw time
100
100
void drawTime (uint16_t x_pos, uint16_t y_pos, bool am, const char *city)
101
101
{
@@ -129,10 +129,10 @@ void drawTime(uint16_t x_pos, uint16_t y_pos, bool am, const char *city)
129
129
130
130
// This part of code draws needles and calculates their angles
131
131
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 );
136
136
137
137
display.drawThickLine (x_pos + w / 2 , y_pos + w / 2 , x_minute, y_minute, INKPLATE2_RED, 2 ); // Needle for minutes
138
138
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)
159
159
display.setFont (&SourceSansPro_Regular6pt7b); // Set customn font
160
160
am ? display.print (" PM" ) : display.print (" AM" );
161
161
}
162
+
0 commit comments