-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNokia5110Lcd.cpp
766 lines (674 loc) · 15.4 KB
/
Nokia5110Lcd.cpp
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
/*
* Nokia5110Lcd.cpp
*
* Created on: 2022. okt. 29.
* Author: BT
*/
#include <avr/pgmspace.h>
#include "Nokia5110Lcd.h"
#define cbi(reg, bitmask) *reg &= ~bitmask
#define sbi(reg, bitmask) *reg |= bitmask
#define pulseClock cbi(P_SCK, B_SCK); asm ("nop"); sbi(P_SCK, B_SCK)
#define resetLCD sbi(P_DC, B_DC); sbi(P_MOSI, B_MOSI); sbi(P_SCK, B_SCK); sbi(P_CS, B_CS); cbi(P_RST, B_RST); delay(10); sbi(P_RST, B_RST)
#define fontbyte(x) pgm_read_byte(&cfont.font[x])
#define bitmapbyte(x) pgm_read_byte(&bitmap[x])
#define bitmapdatatype uint8_t*
#define LCD_COMMAND 0
#define LCD_DATA 1
// PCD8544 Commandset
// ------------------
// General commands
#define PCD8544_POWERDOWN 0x04
#define PCD8544_ENTRYMODE 0x02
#define PCD8544_EXTENDEDINSTRUCTION 0x01
#define PCD8544_DISPLAYBLANK 0x00
#define PCD8544_DISPLAYNORMAL 0x04
#define PCD8544_DISPLAYALLON 0x01
#define PCD8544_DISPLAYINVERTED 0x05
// Normal instruction set
#define PCD8544_FUNCTIONSET 0x20
#define PCD8544_DISPLAYCONTROL 0x08
#define PCD8544_SETYADDR 0x40
#define PCD8544_SETXADDR 0x80
// Extended instruction set
#define PCD8544_SETTEMP 0x04
#define PCD8544_SETBIAS 0x10
#define PCD8544_SETVOP 0x80
// Display presets
#define LCD_BIAS 0x03 // Range: 0-7 (0x00-0x07)
#define LCD_TEMP 0x02 // Range: 0-3 (0x00-0x03)
#define LCD_CONTRAST 0x46 // Range: 0-127 (0x00-0x7F)
/**
*
*/
Nokia5110Lcd::Nokia5110Lcd(int SCK, int MOSI, int DC, int RST, int CS) {
P_SCK = portOutputRegister(digitalPinToPort(SCK));
B_SCK = digitalPinToBitMask(SCK);
P_MOSI = portOutputRegister(digitalPinToPort(MOSI));
B_MOSI = digitalPinToBitMask(MOSI);
P_DC = portOutputRegister(digitalPinToPort(DC));
B_DC = digitalPinToBitMask(DC);
P_RST = portOutputRegister(digitalPinToPort(RST));
B_RST = digitalPinToBitMask(RST);
P_CS = portOutputRegister(digitalPinToPort(CS));
B_CS = digitalPinToBitMask(CS);
pinMode(SCK, OUTPUT);
pinMode(MOSI, OUTPUT);
pinMode(DC, OUTPUT);
pinMode(RST, OUTPUT);
pinMode(CS, OUTPUT);
SCK_Pin = SCK;
RST_Pin = RST;
}
void Nokia5110Lcd::_LCD_Write(unsigned char data, unsigned char mode) {
cbi(P_CS, B_CS);
if (mode == LCD_COMMAND)
cbi(P_DC, B_DC);
else
sbi(P_DC, B_DC);
for (unsigned char c = 0; c < 8; c++) {
if (data & 0x80)
sbi(P_MOSI, B_MOSI);
else
cbi(P_MOSI, B_MOSI);
data = data << 1;
pulseClock
;
}
sbi(P_CS, B_CS);
}
/**
*
*/
void Nokia5110Lcd::init(int contrast = 70) {
if (contrast > 0x7F)
contrast = 0x7F;
if (contrast < 0)
contrast = 0;
resetLCD
;
_LCD_Write(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION, LCD_COMMAND);
_LCD_Write(PCD8544_SETVOP | contrast, LCD_COMMAND);
_LCD_Write(PCD8544_SETTEMP | LCD_TEMP, LCD_COMMAND);
_LCD_Write(PCD8544_SETBIAS | LCD_BIAS, LCD_COMMAND);
_LCD_Write(PCD8544_FUNCTIONSET, LCD_COMMAND);
_LCD_Write(PCD8544_SETYADDR, LCD_COMMAND);
_LCD_Write(PCD8544_SETXADDR, LCD_COMMAND);
_LCD_Write(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL, LCD_COMMAND);
clrScr();
update();
cfont.font = 0;
_sleep = false;
_contrast = contrast;
}
/**
*
*/
void Nokia5110Lcd::clrScr() {
for (int c = 0; c < 504; c++)
scrbuf[c] = 0;
}
/**
*
*/
void Nokia5110Lcd::update() {
if (_sleep == false) {
_LCD_Write(PCD8544_SETYADDR, LCD_COMMAND);
_LCD_Write(PCD8544_SETXADDR, LCD_COMMAND);
for (int b = 0; b < 504; b++)
_LCD_Write(scrbuf[b], LCD_DATA);
}
}
/**
*
*/
void Nokia5110Lcd::setContrast(int contrast) {
if (contrast > 0x7F)
contrast = 0x7F;
if (contrast < 0)
contrast = 0;
_LCD_Write(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION, LCD_COMMAND);
_LCD_Write(PCD8544_SETVOP | contrast, LCD_COMMAND);
_LCD_Write(PCD8544_FUNCTIONSET, LCD_COMMAND);
_contrast = contrast;
}
/**
*
*/
void Nokia5110Lcd::enableSleep() {
_sleep = true;
_LCD_Write(PCD8544_SETYADDR, LCD_COMMAND);
_LCD_Write(PCD8544_SETXADDR, LCD_COMMAND);
for (int b = 0; b < 504; b++)
_LCD_Write(0, LCD_DATA);
_LCD_Write(PCD8544_FUNCTIONSET | PCD8544_POWERDOWN, LCD_COMMAND);
}
/**
*
*/
void Nokia5110Lcd::disableSleep() {
_sleep = false;
_LCD_Write(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION, LCD_COMMAND);
_LCD_Write(PCD8544_SETVOP | _contrast, LCD_COMMAND);
_LCD_Write(PCD8544_SETTEMP | LCD_TEMP, LCD_COMMAND);
_LCD_Write(PCD8544_SETBIAS | LCD_BIAS, LCD_COMMAND);
_LCD_Write(PCD8544_FUNCTIONSET, LCD_COMMAND);
_LCD_Write(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL, LCD_COMMAND);
update();
}
/**
*
*/
void Nokia5110Lcd::fillScr() {
for (int c = 0; c < 504; c++)
scrbuf[c] = 255;
}
void Nokia5110Lcd::invert(bool mode) {
if (mode == true)
_LCD_Write(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYINVERTED, LCD_COMMAND);
else
_LCD_Write(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL, LCD_COMMAND);
}
void Nokia5110Lcd::setPixel(uint16_t x, uint16_t y) {
int by, bi;
if ((x >= 0) and (x < 84) and (y >= 0) and (y < 48)) {
by = ((y / 8) * 84) + x;
bi = y % 8;
scrbuf[by] = scrbuf[by] | (1 << bi);
}
}
void Nokia5110Lcd::clrPixel(uint16_t x, uint16_t y) {
int by, bi;
if ((x >= 0) and (x < 84) and (y >= 0) and (y < 48)) {
by = ((y / 8) * 84) + x;
bi = y % 8;
scrbuf[by] = scrbuf[by] & ~(1 << bi);
}
}
void Nokia5110Lcd::invPixel(uint16_t x, uint16_t y) {
int by, bi;
if ((x >= 0) and (x < 84) and (y >= 0) and (y < 48)) {
by = ((y / 8) * 84) + x;
bi = y % 8;
if ((scrbuf[by] & (1 << bi)) == 0)
scrbuf[by] = scrbuf[by] | (1 << bi);
else
scrbuf[by] = scrbuf[by] & ~(1 << bi);
}
}
void Nokia5110Lcd::invertText(bool mode) {
if (mode == true)
cfont.inverted = 1;
else
cfont.inverted = 0;
}
void Nokia5110Lcd::print(char *st, int x, int y) {
unsigned char ch;
int stl;
stl = strlen(st);
if (x == RIGHT)
x = 84 - (stl * cfont.x_size);
if (x == CENTER)
x = (84 - (stl * cfont.x_size)) / 2;
for (int cnt = 0; cnt < stl; cnt++)
_print_char(*st++, x + (cnt * (cfont.x_size)), y);
}
void Nokia5110Lcd::print(String st, int x, int y) {
char buf[st.length() + 1];
st.toCharArray(buf, st.length() + 1);
print(buf, x, y);
}
void Nokia5110Lcd::printNumI(long num, int x, int y, int length, char filler) {
char buf[25];
char st[27];
boolean neg = false;
int c = 0, f = 0;
if (num == 0) {
if (length != 0) {
for (c = 0; c < (length - 1); c++)
st[c] = filler;
st[c] = 48;
st[c + 1] = 0;
} else {
st[0] = 48;
st[1] = 0;
}
} else {
if (num < 0) {
neg = true;
num = -num;
}
while (num > 0) {
buf[c] = 48 + (num % 10);
c++;
num = (num - (num % 10)) / 10;
}
buf[c] = 0;
if (neg) {
st[0] = 45;
}
if (length > (c + neg)) {
for (int i = 0; i < (length - c - neg); i++) {
st[i + neg] = filler;
f++;
}
}
for (int i = 0; i < c; i++) {
st[i + neg + f] = buf[c - i - 1];
}
st[c + neg + f] = 0;
}
print(st, x, y);
}
void Nokia5110Lcd::printNumF(double num, byte dec, int x, int y, char divider, int length, char filler) {
char st[27];
boolean neg = false;
if (num < 0)
neg = true;
_convert_float(st, num, length, dec);
if (divider != '.') {
for (int i = 0; i < sizeof(st); i++)
if (st[i] == '.')
st[i] = divider;
}
if (filler != ' ') {
if (neg) {
st[0] = '-';
for (int i = 1; i < sizeof(st); i++)
if ((st[i] == ' ') || (st[i] == '-'))
st[i] = filler;
} else {
for (int i = 0; i < sizeof(st); i++)
if (st[i] == ' ')
st[i] = filler;
}
}
print(st, x, y);
}
void Nokia5110Lcd::_print_char(unsigned char c, int x, int y) {
if ((cfont.y_size % 8) == 0) {
int font_idx = ((c - cfont.offset) * (cfont.x_size * (cfont.y_size / 8))) + 4;
for (int rowcnt = 0; rowcnt < (cfont.y_size / 8); rowcnt++) {
for (int cnt = 0; cnt < cfont.x_size; cnt++) {
for (int b = 0; b < 8; b++)
if ((fontbyte(font_idx+cnt+(rowcnt*cfont.x_size)) & (1 << b)) != 0)
if (cfont.inverted == 0)
setPixel(x + cnt, y + (rowcnt * 8) + b);
else
clrPixel(x + cnt, y + (rowcnt * 8) + b);
else if (cfont.inverted == 0)
clrPixel(x + cnt, y + (rowcnt * 8) + b);
else
setPixel(x + cnt, y + (rowcnt * 8) + b);
}
}
} else {
int font_idx = ((c - cfont.offset) * ((cfont.x_size * cfont.y_size / 8))) + 4;
int cbyte = fontbyte(font_idx);
int cbit = 7;
for (int cx = 0; cx < cfont.x_size; cx++) {
for (int cy = 0; cy < cfont.y_size; cy++) {
if ((cbyte & (1 << cbit)) != 0)
if (cfont.inverted == 0)
setPixel(x + cx, y + cy);
else
clrPixel(x + cx, y + cy);
else if (cfont.inverted == 0)
clrPixel(x + cx, y + cy);
else
setPixel(x + cx, y + cy);
cbit--;
if (cbit < 0) {
cbit = 7;
font_idx++;
cbyte = fontbyte(font_idx);
}
}
}
}
}
void Nokia5110Lcd::setFont(const uint8_t *font) {
cfont.font = font;
cfont.x_size = fontbyte(0);
cfont.y_size = fontbyte(1);
cfont.offset = fontbyte(2);
cfont.numchars = fontbyte(3);
cfont.inverted = 0;
}
void Nokia5110Lcd::drawHLine(int x, int y, int l) {
int by, bi;
if ((x >= 0) and (x < 84) and (y >= 0) and (y < 48)) {
for (int cx = 0; cx < l; cx++) {
by = ((y / 8) * 84) + x;
bi = y % 8;
scrbuf[by + cx] |= (1 << bi);
}
}
}
void Nokia5110Lcd::clrHLine(int x, int y, int l) {
int by, bi;
if ((x >= 0) and (x < 84) and (y >= 0) and (y < 48)) {
for (int cx = 0; cx < l; cx++) {
by = ((y / 8) * 84) + x;
bi = y % 8;
scrbuf[by + cx] &= ~(1 << bi);
}
}
}
void Nokia5110Lcd::drawVLine(int x, int y, int l) {
int by, bi;
if ((x >= 0) and (x < 84) and (y >= 0) and (y < 48)) {
for (int cy = 0; cy < l; cy++) {
setPixel(x, y + cy);
}
}
}
void Nokia5110Lcd::clrVLine(int x, int y, int l) {
int by, bi;
if ((x >= 0) and (x < 84) and (y >= 0) and (y < 48)) {
for (int cy = 0; cy < l; cy++) {
clrPixel(x, y + cy);
}
}
}
void Nokia5110Lcd::drawLine(int x1, int y1, int x2, int y2) {
int tmp;
double delta, tx, ty;
double m, b, dx, dy;
if (((x2 - x1) < 0)) {
tmp = x1;
x1 = x2;
x2 = tmp;
tmp = y1;
y1 = y2;
y2 = tmp;
}
if (((y2 - y1) < 0)) {
tmp = x1;
x1 = x2;
x2 = tmp;
tmp = y1;
y1 = y2;
y2 = tmp;
}
if (y1 == y2) {
if (x1 > x2) {
tmp = x1;
x1 = x2;
x2 = tmp;
}
drawHLine(x1, y1, x2 - x1);
} else if (x1 == x2) {
if (y1 > y2) {
tmp = y1;
y1 = y2;
y2 = tmp;
}
drawVLine(x1, y1, y2 - y1);
} else if (abs(x2-x1) > abs(y2 - y1)) {
delta = (double(y2 - y1) / double(x2 - x1));
ty = double(y1);
if (x1 > x2) {
for (int i = x1; i >= x2; i--) {
setPixel(i, int(ty + 0.5));
ty = ty - delta;
}
} else {
for (int i = x1; i <= x2; i++) {
setPixel(i, int(ty + 0.5));
ty = ty + delta;
}
}
} else {
delta = (float(x2 - x1) / float(y2 - y1));
tx = float(x1);
if (y1 > y2) {
for (int i = y2 + 1; i > y1; i--) {
setPixel(int(tx + 0.5), i);
tx = tx + delta;
}
} else {
for (int i = y1; i < y2 + 1; i++) {
setPixel(int(tx + 0.5), i);
tx = tx + delta;
}
}
}
}
void Nokia5110Lcd::clrLine(int x1, int y1, int x2, int y2) {
int tmp;
double delta, tx, ty;
double m, b, dx, dy;
if (((x2 - x1) < 0)) {
tmp = x1;
x1 = x2;
x2 = tmp;
tmp = y1;
y1 = y2;
y2 = tmp;
}
if (((y2 - y1) < 0)) {
tmp = x1;
x1 = x2;
x2 = tmp;
tmp = y1;
y1 = y2;
y2 = tmp;
}
if (y1 == y2) {
if (x1 > x2) {
tmp = x1;
x1 = x2;
x2 = tmp;
}
clrHLine(x1, y1, x2 - x1);
} else if (x1 == x2) {
if (y1 > y2) {
tmp = y1;
y1 = y2;
y2 = tmp;
}
clrVLine(x1, y1, y2 - y1);
} else if (abs(x2-x1) > abs(y2 - y1)) {
delta = (double(y2 - y1) / double(x2 - x1));
ty = double(y1);
if (x1 > x2) {
for (int i = x1; i >= x2; i--) {
clrPixel(i, int(ty + 0.5));
ty = ty - delta;
}
} else {
for (int i = x1; i <= x2; i++) {
clrPixel(i, int(ty + 0.5));
ty = ty + delta;
}
}
} else {
delta = (float(x2 - x1) / float(y2 - y1));
tx = float(x1);
if (y1 > y2) {
for (int i = y2 + 1; i > y1; i--) {
clrPixel(int(tx + 0.5), i);
tx = tx + delta;
}
} else {
for (int i = y1; i < y2 + 1; i++) {
clrPixel(int(tx + 0.5), i);
tx = tx + delta;
}
}
}
}
void Nokia5110Lcd::drawRect(int x1, int y1, int x2, int y2) {
int tmp;
if (x1 > x2) {
tmp = x1;
x1 = x2;
x2 = tmp;
}
if (y1 > y2) {
tmp = y1;
y1 = y2;
y2 = tmp;
}
drawHLine(x1, y1, x2 - x1);
drawHLine(x1, y2, x2 - x1);
drawVLine(x1, y1, y2 - y1);
drawVLine(x2, y1, y2 - y1 + 1);
}
void Nokia5110Lcd::clrRect(int x1, int y1, int x2, int y2) {
int tmp;
if (x1 > x2) {
tmp = x1;
x1 = x2;
x2 = tmp;
}
if (y1 > y2) {
tmp = y1;
y1 = y2;
y2 = tmp;
}
clrHLine(x1, y1, x2 - x1);
clrHLine(x1, y2, x2 - x1);
clrVLine(x1, y1, y2 - y1);
clrVLine(x2, y1, y2 - y1 + 1);
}
void Nokia5110Lcd::drawRoundRect(int x1, int y1, int x2, int y2) {
int tmp;
if (x1 > x2) {
tmp = x1;
x1 = x2;
x2 = tmp;
}
if (y1 > y2) {
tmp = y1;
y1 = y2;
y2 = tmp;
}
if ((x2 - x1) > 4 && (y2 - y1) > 4) {
setPixel(x1 + 1, y1 + 1);
setPixel(x2 - 1, y1 + 1);
setPixel(x1 + 1, y2 - 1);
setPixel(x2 - 1, y2 - 1);
drawHLine(x1 + 2, y1, x2 - x1 - 3);
drawHLine(x1 + 2, y2, x2 - x1 - 3);
drawVLine(x1, y1 + 2, y2 - y1 - 3);
drawVLine(x2, y1 + 2, y2 - y1 - 3);
}
}
void Nokia5110Lcd::clrRoundRect(int x1, int y1, int x2, int y2) {
int tmp;
if (x1 > x2) {
tmp = x1;
x1 = x2;
x2 = tmp;
}
if (y1 > y2) {
tmp = y1;
y1 = y2;
y2 = tmp;
}
if ((x2 - x1) > 4 && (y2 - y1) > 4) {
clrPixel(x1 + 1, y1 + 1);
clrPixel(x2 - 1, y1 + 1);
clrPixel(x1 + 1, y2 - 1);
clrPixel(x2 - 1, y2 - 1);
clrHLine(x1 + 2, y1, x2 - x1 - 3);
clrHLine(x1 + 2, y2, x2 - x1 - 3);
clrVLine(x1, y1 + 2, y2 - y1 - 3);
clrVLine(x2, y1 + 2, y2 - y1 - 3);
}
}
void Nokia5110Lcd::drawCircle(int x, int y, int radius) {
int f = 1 - radius;
int ddF_x = 1;
int ddF_y = -2 * radius;
int x1 = 0;
int y1 = radius;
char ch, cl;
setPixel(x, y + radius);
setPixel(x, y - radius);
setPixel(x + radius, y);
setPixel(x - radius, y);
while (x1 < y1) {
if (f >= 0) {
y1--;
ddF_y += 2;
f += ddF_y;
}
x1++;
ddF_x += 2;
f += ddF_x;
setPixel(x + x1, y + y1);
setPixel(x - x1, y + y1);
setPixel(x + x1, y - y1);
setPixel(x - x1, y - y1);
setPixel(x + y1, y + x1);
setPixel(x - y1, y + x1);
setPixel(x + y1, y - x1);
setPixel(x - y1, y - x1);
}
}
void Nokia5110Lcd::clrCircle(int x, int y, int radius) {
int f = 1 - radius;
int ddF_x = 1;
int ddF_y = -2 * radius;
int x1 = 0;
int y1 = radius;
char ch, cl;
clrPixel(x, y + radius);
clrPixel(x, y - radius);
clrPixel(x + radius, y);
clrPixel(x - radius, y);
while (x1 < y1) {
if (f >= 0) {
y1--;
ddF_y += 2;
f += ddF_y;
}
x1++;
ddF_x += 2;
f += ddF_x;
clrPixel(x + x1, y + y1);
clrPixel(x - x1, y + y1);
clrPixel(x + x1, y - y1);
clrPixel(x - x1, y - y1);
clrPixel(x + y1, y + x1);
clrPixel(x - y1, y + x1);
clrPixel(x + y1, y - x1);
clrPixel(x - y1, y - x1);
}
}
/**
* @brief Fill a rectangle completely with one color. Update in subclasses if
desired!
@param x Top left corner x coordinate
@param y Top left corner y coordinate
@param w Width in pixels
@param h Height in pixels
*
*/
void Nokia5110Lcd::clrArea(int x, int y, int w, int h) {
for (uint16_t sor = y; sor < min(h, LCDHEIGHT); sor++) {
for (uint16_t oszlop = x; oszlop < min(w, LCDWIDTH); oszlop++) {
clrPixel(oszlop, sor);
}
}
}
/**
*
*/
void Nokia5110Lcd::drawBitmap(int x, int y, uint8_t *bitmap, int sx, int sy) {
int bit;
byte data;
for (int cy = 0; cy < sy; cy++) {
bit = cy % 8;
for (int cx = 0; cx < sx; cx++) {
data = bitmapbyte(cx + ((cy / 8) * sx));
if ((data & (1 << bit)) > 0)
setPixel(x + cx, y + cy);
else
clrPixel(x + cx, y + cy);
}
}
}