Skip to content

Commit ed46c1b

Browse files
committed
Version 0.0.2
1 parent 5e15a18 commit ed46c1b

13 files changed

+179
-46
lines changed

convertImage.py renamed to convertSendImage2Arduino.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,32 @@
88

99
ser = serial.Serial('/dev/ttyUSB0',9600)
1010

11+
12+
def color2alpha(arr):
13+
new_arr = []
14+
for old_value in arr:
15+
new_value = int((old_value / 255) * 25 + 97)
16+
new_arr.append(new_value)
17+
return new_arr
18+
1119
def sendImage(image_name):
1220
img = Image.open(image_name)
1321

1422
img_array = np.array(img)
1523

24+
#print(img_array)
25+
1626
my_array = img_array.reshape((10, 10, 3))
1727

1828
color_flat = my_array.flatten()
29+
30+
print(color_flat)
31+
32+
new_color_flat = color2alpha(color_flat)
33+
34+
print(new_color_flat)
1935

20-
color_str = ''.join(map(chr, color_flat))
36+
color_str = ''.join(map(chr, new_color_flat))
2137

2238
print(color_str)
2339

doc.md

+29-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
1-
util01@station173:~$ python3
1+
Panel Led
2+
=========
3+
4+
5+
#### 1/ Programme Arduino.
6+
7+
```
8+
panel_led.ino
9+
```
10+
11+
12+
#### 2/ Programme Python3.
13+
14+
- Initialisation de l'interface série :
15+
16+
```
17+
$ python3
218
Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] on linux
319
Type "help", "copyright", "credits" or "license" for more information.
420
>>> import serial;
521
>>> ser = serial.Serial('/dev/ttyUSB0',9600)
6-
>>> variable = "send"
7-
>>> ser.write(variable.encode())
8-
4
9-
>>>
22+
```
23+
24+
- Envoyer le dessin de lettre A :
25+
26+
```
27+
$ ./sendletter.py
28+
```
29+
30+
- Effacer le panel led :
1031

11-
util01@station173:~/Arduino/panel_led_8$ python3 ./sendletter.py
12-
util01@station173:~/Arduino/panel_led_8$ python3 ./clearletter.py
32+
```
33+
$ ./clear.py
34+
```

hacklab.sh

-31
This file was deleted.

image.png

-8.55 KB
Binary file not shown.

image_a.png

-8.83 KB
Binary file not shown.

image_b.png

-8.85 KB
Binary file not shown.

image_c.png

-8.5 KB
Binary file not shown.

image_color.png

1.62 KB
Loading

image_h.png

-8.55 KB
Binary file not shown.

image_k.png

-8.75 KB
Binary file not shown.

image_l.png

-8.27 KB
Binary file not shown.

panel_led.ino

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
//Libraries
2+
//https://github.com/FastLED/FastLED
3+
#include <FastLED.h>
4+
5+
//Constants
6+
#define NUM_STRIPS 1
7+
#define NUM_LEDS 100
8+
#define BRIGHTNESS 10
9+
#define LED_TYPE WS2812B
10+
#define COLOR_ORDER BRG//RGB
11+
#define FASTLED_ALLOW_INTERRUPTS 0
12+
#define FASTLED_INTERRUPT_RETRY_COUNT 1
13+
#define FRAMES_PER_SECOND 60
14+
#define COOLING 55
15+
#define SPARKING 120
16+
17+
//Parameters
18+
const int stripPin = 3;
19+
20+
//Objects
21+
CRGB leds[NUM_LEDS];
22+
23+
int xy2i(int x, int y) {
24+
int i;
25+
if ( y % 2 == 0) {
26+
return i = y * 10 + x;
27+
} else {
28+
return i = (10 * (y + 1)) - 1 - x;
29+
}
30+
}
31+
32+
int toDrawA[10][10][3]=
33+
{
34+
{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}},
35+
{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}},
36+
{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}},
37+
{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}},
38+
{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}},
39+
{{0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}},
40+
{{0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}},
41+
{{0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {255, 0, 0}, {255, 0, 0}, {255, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}},
42+
{{0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}},
43+
{{0, 0, 0}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}},
44+
};
45+
46+
47+
String command;
48+
49+
String colorArray[5];
50+
51+
52+
int l;
53+
int cR, cG, cB;
54+
55+
const int NUM_ROWS = 10;
56+
const int NUM_COLS = 10;
57+
58+
59+
void displayImage(int toDraw[10][10][3]) {
60+
61+
FastLED.clear();
62+
63+
for ( int y = 0; y < 10; y++) {
64+
for (int x = 0; x < 10; x++) {
65+
l = xy2i(x, y);
66+
cR = toDraw[y][x][0];
67+
cG = toDraw[y][x][1];
68+
cB = toDraw[y][x][2];
69+
leds[l].setRGB(cR, cG, cB);
70+
}
71+
}
72+
FastLED.show();
73+
}
74+
75+
void setup() {
76+
Serial.begin(9600);
77+
FastLED.addLeds<LED_TYPE, stripPin, COLOR_ORDER>(leds, NUM_LEDS);
78+
FastLED.setBrightness( BRIGHTNESS );
79+
80+
FastLED.clear();
81+
FastLED.show();
82+
}
83+
84+
85+
int alpha2color(int old_value) {
86+
int new_value = int((old_value - 97) * (255.0 / 25.0));
87+
return new_value;
88+
}
89+
90+
91+
void loop() {
92+
93+
while (Serial.available() == 0) {}
94+
95+
FastLED.clear();
96+
FastLED.show();
97+
98+
99+
command = Serial.readString();
100+
command.trim();
101+
102+
if (command == "clear") {
103+
Serial.println(F("Clear"));
104+
for (int i=0; i < 100; i++) {
105+
leds[i].setRGB(0, 0, 0);
106+
}
107+
FastLED.show();
108+
} else if (command == "letter") {
109+
Serial.println(F("Letter"));
110+
displayImage(toDrawA);
111+
FastLED.show();
112+
} else {
113+
byte colors[NUM_ROWS][NUM_COLS][3];
114+
115+
int index = 0;
116+
for (int row = 0; row < NUM_ROWS; row++) {
117+
for (int col = 0; col < NUM_COLS; col++) {
118+
int r = command.charAt(index++);
119+
int v = command.charAt(index++);
120+
int b = command.charAt(index++);
121+
122+
r = alpha2color(r);
123+
v = alpha2color(v);
124+
b = alpha2color(b);
125+
126+
int l = xy2i(col, row);
127+
leds[l] = CRGB( r, v, b);
128+
}
129+
}
130+
FastLED.show();
131+
}
132+
133+
}

sendPixel.py

-7
This file was deleted.

0 commit comments

Comments
 (0)