@@ -34,6 +34,10 @@ Arduino_RGB_Display *gfx = new Arduino_RGB_Display(
34
34
// 480 /* width */, 480 /* height */, rgbpanel, 0 /* rotation */, true /* auto_flush */,
35
35
// expander, GFX_NOT_DEFINED /* RST */, tl034wvs05_b1477a_init_operations, sizeof(tl034wvs05_b1477a_init_operations));
36
36
37
+ // 3.2" 320x820 rectangle bar display
38
+ // 320 /* width */, 820 /* height */, rgbpanel, 0 /* rotation */, true /* auto_flush */,
39
+ // expander, GFX_NOT_DEFINED /* RST */, tl032fwv01_init_operations, sizeof(tl032fwv01_init_operations));
40
+
37
41
uint16_t *colorWheel;
38
42
39
43
void setup (void )
@@ -61,7 +65,7 @@ void setup(void)
61
65
expander->digitalWrite (PCA_TFT_BACKLIGHT, HIGH);
62
66
63
67
TB.begin ();
64
- colorWheel = (uint16_t *) ps_malloc (480 * 480 * sizeof (uint16_t ));
68
+ colorWheel = (uint16_t *) ps_malloc (gfx-> width () * gfx-> height () * sizeof (uint16_t ));
65
69
if (colorWheel) generateColorWheel (colorWheel);
66
70
}
67
71
@@ -70,29 +74,34 @@ uint8_t allpins[] = {SS, SCK, MOSI, MISO, A1, A0};
70
74
71
75
void loop ()
72
76
{
73
- gfx->draw16bitRGBBitmap (0 , 0 , colorWheel, 480 , 480 );
77
+ gfx->draw16bitRGBBitmap (0 , 0 , colorWheel, gfx-> width (), gfx-> height () );
74
78
delay (100 );
75
79
return ;
76
80
}
77
81
78
82
// https://chat.openai.com/share/8edee522-7875-444f-9fea-ae93a8dfa4ec
79
83
void generateColorWheel (uint16_t *colorWheel) {
84
+ int width = gfx->width ();
85
+ int height = gfx->height ();
86
+ int half_width = width / 2 ;
87
+ int half_height = height / 2 ;
80
88
float angle;
81
89
uint8_t r, g, b;
82
- int scaled_index;
90
+ int index, scaled_index;
83
91
84
- for (int y = 0 ; y < 240 ; y++) {
85
- for (int x = 0 ; x < 240 ; x++) {
86
- angle = atan2 (y - 120 , x - 120 );
92
+ for (int y = 0 ; y < half_height; y++) {
93
+ for (int x = 0 ; x < half_width; x++) {
94
+ index = y * half_width + x;
95
+ angle = atan2 (y - half_height / 2 , x - half_width / 2 );
87
96
r = uint8_t (127.5 * (cos (angle) + 1 ));
88
97
g = uint8_t (127.5 * (sin (angle) + 1 ));
89
98
b = uint8_t (255 - (r + g) / 2 );
90
99
uint16_t color = RGB565 (r, g, b);
91
100
92
- // Scale this pixel into 4 pixels in the 480x480 buffer
101
+ // Scale this pixel into 4 pixels in the full buffer
93
102
for (int dy = 0 ; dy < 2 ; dy++) {
94
103
for (int dx = 0 ; dx < 2 ; dx++) {
95
- scaled_index = (y * 2 + dy) * 480 + (x * 2 + dx);
104
+ scaled_index = (y * 2 + dy) * width + (x * 2 + dx);
96
105
colorWheel[scaled_index] = color;
97
106
}
98
107
}
0 commit comments