This repository has been archived by the owner on Mar 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
159 lines (136 loc) · 2.99 KB
/
main.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
#include "mbed.h"
#include "neopixel.h"
#include <cstdio>
#define nb_led 15
void init();
void led_controlle(int led, uint32_t color, Pixel *pix);
void led_init(float adj_lum);
void led_cleaner(Pixel *pix);
typedef enum
{
btn1_1 = 0x27,
btn1_2 = 0x47,
btn1_3 = 0x87,
btn2_1 = 0x2B,
btn2_2 = 0x4B,
btn2_3 = 0x8B,
btn3_1 = 0x2D,
btn3_2 = 0x4D,
btn3_3 = 0x8D,
btn4_1 = 0x2E,
btn4_2 = 0x4E,
btn4_3 = 0x8E,
}
ButtonMatrix;
uint32_t rouge = 0xFF0000;
uint32_t jaune = 0xFFFF00;
uint32_t vert = 0x00FF00;
uint32_t bleu = 0x0000FF;
uint32_t violet = 0xFF00FF;
uint32_t non_couleur = 0x000000;
float adj_lum = 0.05f;
PortInOut buttons_col(PortA, 0xE0);
PortInOut buttons_row(PortA, 0xF);
NeoPixelOut neoPixel(PA_12);
Pixel pixels[nb_led];
#define MAXIMUM_BUFFER_SIZE 32
static BufferedSerial serial_port(PA_9, PA_10);
FileHandle *mbed::mbed_override_console(int fd)
{
return &serial_port;
}
int main()
{
init();
serial_port.set_baud(9600);
serial_port.set_format(8, BufferedSerial::None, 1);
char buf[MAXIMUM_BUFFER_SIZE] = { 0 };
buttons_row.mode(PullUp);
while (1)
{
buttons_row.output();
buttons_col.input();
unsigned int btnCol = buttons_col.read();
printf("buttons_col: %x\n", btnCol);
buttons_row.input();
buttons_col.output();
unsigned int btnRow = buttons_row.read();
printf("buttons_row: %x\n", btnRow);
printf("---------------------\n");
unsigned int btn = btnCol | btnRow;
switch (btn)
{
case btn1_1:
led_cleaner(pixels);
led_controlle(1, jaune, pixels);
break;
case btn1_2:
led_cleaner(pixels);
led_controlle(2, bleu, pixels);
break;
case btn1_3:
led_cleaner(pixels);
led_controlle(3, bleu, pixels);
break;
case btn2_1:
led_cleaner(pixels);
led_controlle(4, violet, pixels);
break;
case btn2_2:
led_cleaner(pixels);
led_controlle(5, vert, pixels);
break;
case btn2_3:
led_cleaner(pixels);
led_controlle(6, bleu, pixels);
break;
case btn3_1:
led_cleaner(pixels);
led_controlle(7, vert, pixels);
break;
case btn3_2:
led_cleaner(pixels);
led_controlle(8, bleu, pixels);
break;
case btn3_3:
led_cleaner(pixels);
led_controlle(9, violet, pixels);
break;
case btn4_1:
led_cleaner(pixels);
led_controlle(10, bleu, pixels);
break;
case btn4_2:
led_cleaner(pixels);
led_controlle(11, vert, pixels);
break;
case btn4_3:
led_cleaner(pixels);
led_controlle(12, violet, pixels);
break;
}
}
}
// Инициализация LED ленты
void init()
{
led_init(adj_lum);
}
void led_cleaner(Pixel *pix)
{
for (int i = 1; i <= nb_led; i++)
{
led_controlle(i, non_couleur, pix);
}
}
void led_init(float adj_lum)
{
ThisThread::sleep_for(20ms);
neoPixel.global_scale = adj_lum;
neoPixel.normalize = false;
}
void led_controlle(int led, uint32_t color, Pixel *pix)
{
pix[led - 1].hex = color;
neoPixel.send(pixels, nb_led);
}