Bonjour à tous!
Avant de parler de mon projet je vais me présenter rapidement : Je m'appelle Cédric, je suis graphiste de formation et n'en touche pas une en code...
J'ai eu envie de satisfaire ma compagne en lui réalisant une horloge qu'elle a adoré il y a 10 ans dans un magasin... la Qlocktwo (https://qlocktwo.com/eu/qlocktwo-classic)
Me voila donc avec un panneau mdf que j'ai fais usiné pour intégrer les strip led adressable.... j'ai voulu suivre ce tuto ci : https://rpi-wordclock.readthedocs.io/en/master/ car il proposait la fonction horloge mais pas que.... il y avait un plugin météo, des actions commandée via 3 boutons, etc...
Après avoir longuement essayer, j'ai été demander de l'aide sur un forum raspberry et on a pas mal avancer... je me suis rendu compte que le tuto était obsolete car codé en python 2 et des plugin n'ont pas suivi. j'ai donc trouvé celui ci https://benedikt-kuenzel.com/2019/01...locktwo-clone/ qui se base sur le strandtest neopixel. ça fonctionne plus ou moins. Le code à été fais pour une wordclock Allemande de base... j'ai déjà changé tous les mots pour avoir ça en français.
ça marche ! mon horloge donne l'heuremais on m'a conseiller de me tourner vers un forum python pour la suite... me voila
En somme : mon horloge donne l'heure, mais j'ai un souci pour définir les mots midi et minuit: en gros il affiche midi à minuit... et le mot heure ne s'eteind pas... :-(
Voici mon python :
y-en a t'il qui ont déjà réalisé ce projet? Saurais-je attribuer des action à mes boutons? à terme j'instalerai peut-etre un capteur de luminosité... ce serait jouable de faire varier la luminosité des led selon celles de la piece?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #!/usr/bin/env python3 # NeoPixel library strandtest example # Author: Tony DiCola (tony@tonydicola.com) # # Direct port of the Arduino NeoPixel library strandtest example. Showcases # various animations on a strip of NeoPixels. import time import datetime from neopixel import * import argparse # LED strip configuration: LED_COUNT = 114 # Number of LED pixels. LED_PIN = 18 # GPIO pin connected to the pixels (18 uses PWM!). #LED_PIN = 10 # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0). LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz) LED_DMA = 10 # DMA channel to use for generating signal (try 10) LED_BRIGHTNESS = 255 # Set to 0 for darkest and 255 for brightest LED_INVERT = False # True to invert the signal (when using NPN transistor level shift) LED_CHANNEL = 0 # set to '1' for GPIOs 13, 19, 41, 45 or 53 LAST_MINUTE_ENTRY = 0; #All words on the clock IL = [100, 101] EST = [103, 104, 105] DEUX = [107, 108, 109, 110] QUATRE = [99, 98, 97, 96, 95, 94] ET = [94, 93] TROIS = [93, 92, 91, 90, 89] NEUF = [78, 79, 80, 81] UNE = [82, 83, 84] SEPT = [85, 86, 87, 88] HUIT = [77, 76, 75, 74] SIX = [73, 72, 71] CINQ = [70, 69, 68, 67] MIDI = [56, 57, 58, 59] DIX = [58, 59, 60] MINUIT = [61, 62, 63, 64, 65, 66] ONZE = [55, 54, 53, 52] HEURES = [50, 49, 48, 47, 46, 45] M_MOINS = [34, 35, 36, 37, 38] M_LE = [40, 41] M_DIX = [42, 43, 44] M_ET = [33, 32] M_QUART = [30, 29, 28, 27, 26] M_VINGT = [12, 13, 14, 15, 16] M_TIRET = [17] M_CINQ = [18, 19, 20, 21] M_ET2 = [11, 10] M_DEMIE = [8, 7, 6, 5, 4] M_1 = [111] M_2 = [111, 112] M_3 = [111, 112, 113] M_4 = [111, 112, 113, 114] def convertTimeToArray(strip): now = datetime.datetime.now() print(now) min = LAST_MINUTE_ENTRY hour = now.hour + 1 array = [] if hour == 4 and min == 20 or hour == 16 and min == 20: #embrace 420 rainbow(strip) # if hour < 8: #turn clock off from 0 to 8 in the morning # return array; if min == 0: #new hour, let's have fun theaterChase(strip, Color(127,127,127), 50, 30) array = array + IL + EST + HEURES + getMinuteArray() if min == 0: array = array + getHourArray(hour, True) + HEURES elif min <= 35: array = array + getHourArray(hour, False) else: array = array + getHourArray(hour + 1, False) return array print (now) def getHourArray(hour, fullTime): if hour > 12: hour = hour - 12 if hour == 0: return MINUIT if hour == 1: if fullTime: return UNE return UNE if hour == 2: return DEUX if hour == 3: return TROIS if hour == 4: return QUATRE if hour == 5: return CINQ if hour == 6: return SIX if hour == 7: return SEPT if hour == 8: return HUIT if hour == 9: return NEUF if hour == 10: return DIX if hour == 11: return ONZE if hour == 12: return MIDI return [] #get minutes def getMinuteArray(): min = LAST_MINUTE_ENTRY if min == 0: return [] if min == 1: return M_1 if min == 2: return M_2 if min == 3: return M_3 if min == 4: return M_4 if min == 5: return M_CINQ if min == 6: return M_1 + M_CINQ if min == 7: return M_2 + M_CINQ if min == 8: return M_3 + M_CINQ if min == 9: return M_4 + M_CINQ if min == 10: return M_DIX if min == 11: return M_1 + M_DIX if min == 12: return M_2 + M_DIX if min == 13: return M_3 + M_DIX if min == 14: return M_4 + M_DIX if min == 15: return M_QUART if min == 16: return M_1 + M_QUART if min == 17: return M_2 + M_QUART if min == 18: return M_3 + M_QUART if min == 19: return M_4 + M_QUART if min == 20: return M_VINGT if min == 21: return M_1 + M_VINGT if min == 22: return M_2 + M_VINGT if min == 23: return M_3 + M_VINGT if min == 24: return M_4 + M_VINGT if min == 25: return M_VINGT + M_CINQ if min == 26: return M_1 + M_VINGT + M_CINQ if min == 27: return M_2 + M_VINGT + M_CINQ if min == 28: return M_3 + M_VINGT + M_CINQ if min == 29: return M_4 + M_VINGT + M_CINQ if min == 30: return M_ET2 + M_DEMIE if min == 31: return M_1 + M_ET2 + M_DEMIE if min == 32: return M_2 + M_ET2 + M_DEMIE if min == 33: return M_3 + M_ET2 + M_DEMIE if min == 34: return M_4 + M_ET2 + M_DEMIE if min == 35: return M_MOINS + M_VINGT + M_TIRET + M_CINQ if min == 36: return M_1 + M_MOINS + M_VINGT + M_TIRET + M_CINQ if min == 37: return M_2 + M_MOINS + M_VINGT + M_TIRET + M_CINQ if min == 38: return M_3 + M_MOINS + M_VINGT + M_TIRET + M_CINQ if min == 39: return M_4 + M_MOINS + M_VINGT + M_TIRET + M_CINQ if min == 40: return M_MOINS + M_VINGT if min == 41: return M_1 + M_MOINS + M_VINGT if min == 42: return M_2 + M_MOINS + M_VINGT if min == 43: return M_3 + M_MOINS + M_VINGT if min == 44: return M_4 + M_MOINS + M_VINGT if min == 45: return M_MOINS + M_QUART if min == 46: return M_1 + M_MOINS + M_QUART if min == 47: return M_2 + M_MOINS + M_QUART if min == 48: return M_3 + M_MOINS + M_QUART if min == 49: return M_4 + M_MOINS + M_QUART if min == 50: return M_MOINS + M_DIX if min == 51: return M_1 + M_MOINS + M_DIX if min == 52: return M_2 + M_MOINS + M_DIX if min == 53: return M_3 + M_MOINS + M_DIX if min == 54: return M_4 + M_MOINS + M_DIX if min == 55: return M_MOINS + M_CINQ if min == 56: return M_1 + M_MOINS + M_CINQ if min == 57: return M_2 + M_MOINS + M_CINQ if min == 58: return M_3 + M_MOINS + M_CINQ if min == 59: return M_4 + M_MOINS + M_CINQ return [] #Show array def showArray(strip, color, array): for i in range(strip.numPixels()): if array.__contains__(i + 1): strip.setPixelColor(i, color) else: strip.setPixelColor(i, Color(0,0,0)) strip.show() # Define functions which animate LEDs in various ways. def colorWipe(strip, color, wait_ms=50): """Wipe color across display a pixel at a time.""" for i in range(strip.numPixels()): strip.setPixelColor(i, color) strip.show() time.sleep(wait_ms/1000.0) # Returns true every time a new 5 minutes have started on the clock # i.E it's now 00:35 or 00:10 def timeHasChanged(isStartup): global LAST_MINUTE_ENTRY now = datetime.datetime.now() if isStartup == True: LAST_MINUTE_ENTRY = round(now.minute / 1) * 1 #round to nearest five return True if LAST_MINUTE_ENTRY != now.minute: if now.minute % 1 == 0: LAST_MINUTE_ENTRY = now.minute return True return False def theaterChase(strip, color, wait_ms=50, iterations=10): """Movie theater light style chaser animation.""" for j in range(iterations): for q in range(3): for i in range(0, strip.numPixels(), 3): strip.setPixelColor(i+q, color) strip.show() time.sleep(wait_ms/1000.0) for i in range(0, strip.numPixels(), 3): strip.setPixelColor(i+q, 0) def rainbow(strip, wait_ms=20, iterations=1): """Draw rainbow that fades across all pixels at once.""" for j in range(256*iterations): for i in range(strip.numPixels()): strip.setPixelColor(i, wheel((i+j) & 255)) strip.show() time.sleep(wait_ms/1000.0) def wheel(pos): """Generate rainbow colors across 0-255 positions.""" if pos < 85: return Color(pos * 3, 255 - pos * 3, 0) elif pos < 170: pos -= 85 return Color(255 - pos * 3, 0, pos * 3) else: pos -= 170 return Color(0, pos * 3, 255 - pos * 3) # Main program logic follows: if __name__ == '__main__': # Process arguments parser = argparse.ArgumentParser() parser.add_argument('-c', '--clear', action='store_true', help='clear the display on exit') args = parser.parse_args() # Create NeoPixel object with appropriate configuration. strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL) # Intialize the library (must be called once before other functions). strip.begin() print ('Press Ctrl-C to quit.') if not args.clear: print('Use "-c" argument to clear LEDs on exit') timeHasChanged(True) array = convertTimeToArray(strip) showArray(strip, Color(50,50,50), array) try: while True: if timeHasChanged(False) == True: array = convertTimeToArray(strip) showArray(strip, Color(50,50,50), array) else: time.sleep(30) except KeyboardInterrupt: if args.clear: colorWipe(strip, Color(0,0,0), 10)
merciiiiii!
Partager