-
Notifications
You must be signed in to change notification settings - Fork 12
/
SharMemDisplay.ino
244 lines (206 loc) · 6.27 KB
/
SharMemDisplay.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*********************************************************************
This is an example sketch for our Monochrome SHARP Memory Displays
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/products/1393
These displays use SPI to communicate, 3 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
*********************************************************************/
#include "Adafruit_mfGFX.h"
#include "Adafruit_SharpMem.h"
// This #include statement was automatically added by the Spark IDE.
//#include "glcdfont.h"
// any pins can be used
//#define SCK 10
//#define MOSI 11
//#define SS 13
Adafruit_SharpMem display(D3, D4, D5); //SCK, MOSI, SS
#define BLACK 0
#define WHITE 1
void setup(void)
{
display.init(); // Initialize the hardware ports since cannot be done in class instantation above
Serial.begin(9600);
Serial.println("Hello!");
//Default font is ARIAL_8, uncomment line below to set to different font
//display.setFont(TIMESNR_8);
// start & clear the display
display.begin();
display.clearDisplay();
// draw a single pixel
display.drawPixel(10, 10, BLACK);
display.refresh();
delay(500);
display.clearDisplay();
// draw many lines
testdrawline();
delay(500);
display.clearDisplay();
// draw rectangles
testdrawrect();
delay(500);
display.clearDisplay();
// draw multiple rectangles
testfillrect();
display.refresh();
delay(500);
display.clearDisplay();
// draw a circle, 10 pixel radius
display.fillCircle(display.width()/2, display.height()/2, 10, BLACK);
display.refresh();
delay(500);
display.clearDisplay();
testdrawroundrect();
display.refresh();
delay(500);
display.clearDisplay();
testfillroundrect();
display.refresh();
delay(500);
display.clearDisplay();
testdrawtriangle();
display.refresh();
delay(500);
display.clearDisplay();
testfilltriangle();
display.refresh();
delay(500);
display.clearDisplay();
// draw the first ~12 characters in the font
testdrawchar();
display.refresh();
delay(2000);
display.clearDisplay();
// text display tests
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println("Hello, world!");
display.setTextColor(WHITE, BLACK); // 'inverted' text
display.println(3.141592);
display.setTextSize(2);
display.setTextColor(BLACK);
display.print("0x"); display.println(0xDEADBEEF, HEX);
display.refresh();
delay(2000);
}
void loop(void)
{
// Screen must be refreshed at least once per second
display.refresh();
delay(500);
}
///
void testdrawchar(void) {
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
for (uint8_t i=0; i < 168; i++) {
if (i == '\n') continue;
display.write(i);
//if ((i > 0) && (i % 14 == 0))
//display.println();
}
display.refresh();
}
void testdrawcircle(void) {
for (uint8_t i=0; i<display.height(); i+=2) {
display.drawCircle(display.width()/2-5, display.height()/2-5, i, BLACK);
display.refresh();
}
}
void testfillrect(void) {
uint8_t color = 1;
for (uint8_t i=0; i<display.height()/2; i+=3) {
// alternate colors
display.fillRect(i, i, display.width()-i*2, display.height()-i*2, color%2);
display.refresh();
color++;
}
}
void testdrawtriangle(void) {
for (uint16_t i=0; i<min(display.width(),display.height())/2; i+=5) {
display.drawTriangle(display.width()/2, display.height()/2-i,
display.width()/2-i, display.height()/2+i,
display.width()/2+i, display.height()/2+i, BLACK);
display.refresh();
}
}
void testfilltriangle(void) {
uint8_t color = BLACK;
for (int16_t i=min(display.width(),display.height())/2; i>0; i-=5) {
display.fillTriangle(display.width()/2, display.height()/2-i,
display.width()/2-i, display.height()/2+i,
display.width()/2+i, display.height()/2+i, color);
if (color == WHITE) color = BLACK;
else color = WHITE;
display.refresh();
}
}
void testdrawroundrect(void) {
for (uint8_t i=0; i<display.height()/4; i+=2) {
display.drawRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, BLACK);
display.refresh();
}
}
void testfillroundrect(void) {
uint8_t color = BLACK;
for (uint8_t i=0; i<display.height()/4; i+=2) {
display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, color);
if (color == WHITE) color = BLACK;
else color = WHITE;
display.refresh();
}
}
void testdrawrect(void) {
for (uint8_t i=0; i<display.height()/2; i+=2) {
display.drawRect(i, i, display.width()-2*i, display.height()-2*i, BLACK);
display.refresh();
}
}
void testdrawline() {
for (uint8_t i=0; i<display.width(); i+=4) {
display.drawLine(0, 0, i, display.height()-1, BLACK);
display.refresh();
}
for (uint8_t i=0; i<display.height(); i+=4) {
display.drawLine(0, 0, display.width()-1, i, BLACK);
display.refresh();
}
delay(250);
display.clearDisplay();
for (uint8_t i=0; i<display.width(); i+=4) {
display.drawLine(0, display.height()-1, i, 0, BLACK);
display.refresh();
}
for (int8_t i=display.height()-1; i>=0; i-=4) {
display.drawLine(0, display.height()-1, display.width()-1, i, BLACK);
display.refresh();
}
delay(250);
display.clearDisplay();
for (int8_t i=display.width()-1; i>=0; i-=4) {
display.drawLine(display.width()-1, display.height()-1, i, 0, BLACK);
display.refresh();
}
for (int8_t i=display.height()-1; i>=0; i-=4) {
display.drawLine(display.width()-1, display.height()-1, 0, i, BLACK);
display.refresh();
}
delay(250);
display.clearDisplay();
for (uint8_t i=0; i<display.height(); i+=4) {
display.drawLine(display.width()-1, 0, 0, i, BLACK);
display.refresh();
}
for (uint8_t i=0; i<display.width(); i+=4) {
display.drawLine(display.width()-1, 0, i, display.height()-1, BLACK);
display.refresh();
}
delay(250);
}