-
Notifications
You must be signed in to change notification settings - Fork 4
/
GC9A01_demo.ino
140 lines (125 loc) · 2.82 KB
/
GC9A01_demo.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
// Copyright (c) 2023 by GWENDESIGN. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// Adapted for M5Dial from
// https://github.com/carlfriess/GC9A01_demo
#include <Arduino.h>
#include <SPI.h>
#include "GC9A01.h"
#define MY_MOSI GPIO_NUM_5
#define MY_SCLK GPIO_NUM_6
#define MY_CS GPIO_NUM_7
#define MY_DC GPIO_NUM_4
#define MY_RST GPIO_NUM_8
#define MY_BL GPIO_NUM_9
void GC9A01_set_reset(uint8_t val)
{
digitalWrite(MY_RST, val);
}
void GC9A01_set_data_command(uint8_t val)
{
digitalWrite(MY_DC, val);
}
void GC9A01_set_chip_select(uint8_t val)
{
digitalWrite(MY_CS, val);
}
void GC9A01_spi_tx(uint8_t *data, size_t len)
{
while (len--)
{
SPI.transfer(*data);
data++;
}
}
void GC9A01_delay(uint16_t ms)
{
delay(ms);
}
void setup()
{
pinMode(MY_RST, OUTPUT);
pinMode(MY_DC, OUTPUT);
pinMode(MY_CS, OUTPUT);
pinMode(MY_BL, OUTPUT);
digitalWrite(MY_BL, HIGH);
SPI.begin(MY_SCLK, -1, MY_MOSI, -1);
GC9A01_init();
struct GC9A01_frame frame = {{0, 0},{239, 239}};
GC9A01_set_frame(frame);
}
void loop()
{
uint8_t color[3];
// Triangle
color[0] = 0xFF;
color[1] = 0xFF;
for(int x = 0; x < 240; x++)
{
for(int y = 0; y < 240; y++)
{
if(x < y) color[2] = 0xFF;
else color[2] = 0x00;
if(x == 0 && y == 0) GC9A01_write(color, sizeof(color));
else GC9A01_write_continue(color, sizeof(color));
}
}
delay(1000);
// Rainbow
float frequency = 0.026;
for(int x = 0; x < 240; x++)
{
color[0] = sin(frequency*x + 0) * 127 + 128;
color[1] = sin(frequency*x + 2) * 127 + 128;
color[2] = sin(frequency*x + 4) * 127 + 128;
for(int y = 0; y < 240; y++)
{
if(x == 0 && y == 0) GC9A01_write(color, sizeof(color));
else GC9A01_write_continue(color, sizeof(color));
}
}
delay(1000);
// Checkerboard
for(int x = 0; x < 240; x++)
{
for(int y = 0; y < 240; y++)
{
if((x / 10) % 2 == (y / 10) % 2)
{
color[0] = 0xFF;
color[1] = 0xFF;
color[2] = 0xFF;
}
else
{
color[0] = 0x00;
color[1] = 0x00;
color[2] = 0x00;
}
if(x == 0 && y == 0) GC9A01_write(color, sizeof(color));
else GC9A01_write_continue(color, sizeof(color));
}
}
delay(1000);
// Swiss flag
color[0] = 0xFF;
for(int x = 0; x < 240; x++)
{
for(int y = 0; y < 240; y++)
{
if((x >= 1*48 && x < 4*48 && y >= 2*48 && y < 3*48) ||
(x >= 2*48 && x < 3*48 && y >= 1*48 && y < 4*48))
{
color[1] = 0xFF;
color[2] = 0xFF;
}
else
{
color[1] = 0x00;
color[2] = 0x00;
}
if(x == 0 && y == 0) GC9A01_write(color, sizeof(color));
else GC9A01_write_continue(color, sizeof(color));
}
}
delay(1000);
}