/
pseudoclock_RP2040_ST7567S_v1.ino
119 lines (97 loc) · 4.31 KB
/
pseudoclock_RP2040_ST7567S_v1.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
Clock.ino
Demonstrates a clock-like display with a very huge font.
Also shows usage of u8x8_u8toa().
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
Copyright (c) 2016, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Nicu FLORICA (niq_ro) used info from:
https://aliexpress.ru/item/1005004617618178.html?sku_id=12000029849830576
https://pastebin.com/cMgTQMQd
https://www.waveshare.com/wiki/RP2040-Zero
https://nicuflorica.blogspot.com/
to create a pseudo-clock
*/
#include <Arduino.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
/*
U8g2lib Example Overview:
Frame Buffer Examples: clearBuffer/sendBuffer. Fast, but may not work with all Arduino boards because of RAM consumption
Page Buffer Examples: firstPage/nextPage. Less RAM usage, should work with all Arduino boards.
U8x8 Text Only Example: No RAM usage, direct communication with display controller. No graphics, 8x8 Text only.
*/
//#define SCL_PIN SCL // SCL pin of OLED. Default: GP5 (I2CO SCL for RP2040)
//#define SDA_PIN SDA // SDA pin of OLED. Default: GP4 (I2CO SDA for RP2040)
#define u8g2_PIN_NONE 100
//U8G2_ST7567_ENH_DG128064I_F_SW_I2C u8g2(U8G2_R0, SCL, SDA, U8X8_PIN_NONE);
U8G2_ST7567_ENH_DG128064I_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE); // this works with RP2040
String weekDays[7]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup(void) {1
u8g2.setI2CAddress (0x7E); //(0x3F * 2);
u8g2.begin();
u8g2.setContrast(255);
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_ncenB08_tr);
//u8g2.setFont(u8g2_font_cu12_tr);
u8g2.drawStr(15, 10, "RP2040-Zero board"); // write something to the internal memory
u8g2.drawStr(30, 25, "with 128x64"); // write something to the internal memory
u8g2.drawStr(20, 45, "ST7567S display"); // write something to the internal memory
u8g2.drawStr(0, 60, "using Arduino u8g2lib"); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
delay(3000);
}
uint8_t h = 23;
uint8_t m = 24;
byte i = 0;
void loop(void) {
char m_str[3];
strcpy(m_str, u8x8_u8toa(m, 2)); /* convert m to a string with two digits */
char h_str[3];
strcpy(h_str, u8x8_u8toa(h, 2));
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_ncenB08_tr);
u8g2.drawStr(0, 10, "22.07.2023 - ");
u8g2.setCursor(63,10);
u8g2.print(weekDays[i]);
u8g2.drawStr(10, 63, "arduinotehniq.com"); // write something to the internal memory
u8g2.setFont(u8g2_font_7Segments_26x42_mn);
u8g2.drawStr(0,54,h_str);
if ((millis()/1000)%2 == 0)
u8g2.drawStr(58,54,":");
u8g2.drawStr(69,54,m_str);
} while (u8g2.nextPage() );
delay(500);
m++;
if (m == 60)
m = 0;
i++;
if (i > 6)
i = 0;
} // end main loop