This repository was archived by the owner on Jan 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathISSMP3.py
1894 lines (1745 loc) · 55.1 KB
/
ISSMP3.py
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# All Code Created by <NAME REDACTED>
################################################### Initialisation of Python Modules ##########################################
"""
Import all relevant modules for use
"""
import pygame as p
import os, glob, time, threading, subprocess
from sense_hat import SenseHat
import random
###############################################################################################################################
############################################## Changing the Audio Output and Creating a Pygame Window #########################
"""
Sets the audio to come through the Audio Jack and initialises the Pygame display so that keyboard events can be recorded
"""
os.system("sudo amixer cset numid=3 1")
os.system("sudo amixer cset numid=1 90%")
p.init()
p.display.init()
p.display.set_mode((100,100))
###############################################################################################################################
############################################### List of Variables #############################################################
"""
Initialises all of the variables needed throughout the code
"""
current = 0 #The position in the List of the song currently Playing
start = True #Whether the MP3 Player has just started or has already played a piece of music
nowDisplaying = 0 #The position in the List of the song currently displaying on the screen. This may not be the song currently playing
songPlaying = False #Whether the song is playing or not
volume = 0 #The Volume in terms of how many steps down from the full volume the song is, e.g one key press
leave = False #Whether to exit the main loop of the code
isPause = False #Check to see if the music is currently paused
newVar = None #Used to store the value of the current variable so that the current variable is separate from the display thread
newVar2 = None #""
newVar3 = None #""
newVar4 = None #""
newVar5 = None #""
overTime = 0 #Used to get the change in time from the top of the while loop to the bottom of the while loop
middleTime = 0 #Used to get the current time the song has been playing for
increase = False #Used to control whether the middleTime Variable needs to increase or not
hello = None # Used to store the value of Variables that need to be accessed by both threads so that the value can be used but the variables are not locked for a long time
check2 = None #""
check3 = None #""
check4 = None #""
check5 = None #""
check6 = None #""
check7 = None #""
check8 = None #""
check9 = None #""
check10 = None #""
check11 = None #""
check12 = None #""
check13 = 0 #""
check14 = None #""
check15 = None #""
check16 = None #""
check17 = None #""
check18 = None #""
check19 = None #""
check20 = None #""
check21 = None #""
helpCheck1 = None #""
isPlay = False #Checks whether the play symbol should be shown
canPause = False #Checks whether the pause symbol should be shown
isNextTrack = False #Checks whether the next track symbol should be shown
isPreviousTrack = False #Checks whether the previous track symbol should be shown
whatSound1 = False #Checks whether the no sound symbol should be shown
whatSound2 = False #Checks whether the low sound symbol should be shown
whatSound3 = False #Checks whether the medium sound symbol should be shown
whatSound4 = False #Checks whether the high sound symbol should be shown
placeHolder = None #A list of words in the song title
listWords = [] #Used to store the song title
pitch = 0 #Used to store the value of pitch
roll = 0 #Used to store the value of roll
yaw = 0 #Used to store the value of yaw
isOrientation = False #Checks whether the orientation is locked or unlocked
canOrientation1 = False #Checks whether the orientation symbol should show locked
canOrientation2 = False #Checks whether the orientation symbol should show unlocked
music = None #Is the variable where the subprocess to omxplayer is opened
showName = True #Checks whether the display should show the name of the song
showHelp = False #Checks whether the display should show the help menu
angle = 270 #Stores the angle of the Raspberry Pi
checkAngle = 270 #Is used to check to see whether the angle has moved to a different quadrant of the circle
xAxis = 0 #Stores the x axis value of the accelerometer
yAxis = 0 #Stores the y axis value of the accelerometer
zAxis = 0 #Stores the z axis value of the accelerometer
shakeTime = 0 #Stores the cooldown time for the shake to shuffle function
isShake = True #Checks whether the device is allowed to recieve shake input
randomNumber = 0 #Stores a random number in the range of the number of songs on the device
temperature = None #Stores the temperature in degrees
backgroundColour = [0,0,255] #Stores the background colour for the display text which changes depending on the temperature
checkRewind = None #Checks to see if the rewind symbol should be shown on the help menu
checkFastForward = None #Checks to see if the FastForward symbol should be shown on the help menu
checkScrollUp = None #checks to see if the up scroll button should be seen on the help menu
checkScrollDown = None #checks to see if the down scroll button should be seen on the help menu
c = [0,0,0] #colourless colour
r = [255,0,0] #red colour
g = [0,255,0] #green colour
b = [0,0,255] #blue colour
playButton = [
c,c,c,c,c,c,c,c,
c,c,g,c,c,c,c,c,
c,c,g,g,c,c,c,c,
c,c,g,g,g,c,c,c,
c,c,g,g,g,g,c,c,
c,c,g,g,g,c,c,c,
c,c,g,g,c,c,c,c,
c,c,g,c,c,c,c,c
]
pauseButton = [
c,c,c,c,c,c,c,c,
c,g,g,c,c,g,g,c,
c,g,g,c,c,g,g,c,
c,g,g,c,c,g,g,c,
c,g,g,c,c,g,g,c,
c,g,g,c,c,g,g,c,
c,g,g,c,c,g,g,c,
c,g,g,c,c,g,g,c
]
infoButton = [
c,c,c,g,g,c,c,c,
c,c,c,g,g,c,c,c,
c,c,c,c,c,c,c,c,
c,c,c,c,c,c,c,c,
c,c,c,g,g,c,c,c,
c,c,c,g,g,c,c,c,
c,c,c,g,g,c,c,c,
c,c,c,g,g,c,c,c
]
lockedButton = [
c,c,c,c,c,c,c,c,
c,c,c,g,g,c,c,c,
c,c,g,c,c,g,c,c,
c,c,g,c,c,g,c,c,
c,c,g,g,g,g,c,c,
c,c,g,g,g,g,c,c,
c,c,g,g,g,g,c,c,
c,c,g,g,g,g,c,c
]
unlockedButton = [
c,c,c,g,g,c,c,c,
c,c,g,c,c,g,c,c,
c,c,c,c,c,g,c,c,
c,c,c,c,c,g,c,c,
c,c,g,g,g,g,c,c,
c,c,g,g,g,g,c,c,
c,c,g,g,g,g,c,c,
c,c,g,g,g,g,c,c
]
nextTrackButton = [
c,c,c,c,c,c,c,c,
c,g,c,c,g,c,c,c,
c,c,g,c,c,g,c,c,
c,c,c,g,c,c,g,c,
c,c,c,c,g,c,c,g,
c,c,c,g,c,c,g,c,
c,c,g,c,c,g,c,c,
c,g,c,c,g,c,c,c
]
previousTrackButton = [
c,c,c,c,c,c,c,c,
c,c,c,g,c,c,g,c,
c,c,g,c,c,g,c,c,
c,g,c,c,g,c,c,c,
g,c,c,g,c,c,c,c,
c,g,c,c,g,c,c,c,
c,c,g,c,c,g,c,c,
c,c,c,g,c,c,g,c
]
rewindButton = [
c,c,c,c,c,c,c,c,
c,c,c,g,c,c,c,c,
c,c,g,c,c,c,c,c,
c,g,c,c,c,c,c,c,
g,c,c,c,c,c,c,c,
c,g,c,c,c,c,c,c,
c,c,g,c,c,c,c,c,
c,c,c,g,c,c,c,c
]
fastForwardButton = [
c,c,c,c,c,c,c,c,
c,c,c,c,g,c,c,c,
c,c,c,c,c,g,c,c,
c,c,c,c,c,c,g,c,
c,c,c,c,c,c,c,g,
c,c,c,c,c,c,g,c,
c,c,c,c,c,g,c,c,
c,c,c,c,g,c,c,c
]
scrollDownButton = [
c,c,c,c,c,c,c,c,
c,c,c,c,c,c,c,c,
c,c,c,c,c,c,c,c,
c,c,c,c,c,c,c,c,
c,g,c,c,c,c,c,g,
c,c,g,c,c,c,g,c,
c,c,c,g,c,g,c,c,
c,c,c,c,g,c,c,c
]
scrollUpButton = [
c,c,c,c,g,c,c,c,
c,c,c,g,c,g,c,c,
c,c,g,c,c,c,g,c,
c,g,c,c,c,c,c,g,
c,c,c,c,c,c,c,c,
c,c,c,c,c,c,c,c,
c,c,c,c,c,c,c,c,
c,c,c,c,c,c,c,c
]
noSoundButton = [
c,c,c,g,c,c,c,c,
c,c,g,g,c,c,c,c,
g,g,g,g,c,c,c,c,
g,g,g,g,c,c,c,c,
g,g,g,g,c,c,c,c,
g,g,g,g,c,c,c,c,
c,c,g,g,c,c,c,c,
c,c,c,g,c,c,c,c
]
lowSoundButton = [
c,c,c,g,c,c,c,c,
c,c,g,g,c,c,c,c,
g,g,g,g,r,c,c,c,
g,g,g,g,r,c,c,c,
g,g,g,g,r,c,c,c,
g,g,g,g,r,c,c,c,
c,c,g,g,c,c,c,c,
c,c,c,g,c,c,c,c
]
mediumSoundButton = [
c,c,c,g,c,c,c,c,
c,c,g,g,c,b,c,c,
g,g,g,g,r,b,c,c,
g,g,g,g,r,b,c,c,
g,g,g,g,r,b,c,c,
g,g,g,g,r,b,c,c,
c,c,g,g,c,b,c,c,
c,c,c,g,c,c,c,c
]
highSoundButton = [
c,c,c,g,c,c,g,c,
c,c,g,g,c,b,g,c,
g,g,g,g,r,b,g,c,
g,g,g,g,r,b,g,c,
g,g,g,g,r,b,g,c,
g,g,g,g,r,b,g,c,
c,c,g,g,c,b,g,c,
c,c,c,g,c,c,g,c
]
"""
Sets the pixels that are needed to make up the numbers for the time display, the seconds bar and the letters for the loading screen
"""
number01 = [(0,0),(1,0),(2,0),(0,1),(2,1),(0,2),(2,2),(0,3),(2,3),(0,4),(2,4),(1,4)]
number11 = [(2,0),(2,1),(2,2),(2,3),(2,4)]
number21 = [(0,0),(1,0),(2,0),(2,1),(2,2),(1,2),(0,2),(0,3),(0,4),(1,4),(2,4)]
number31 = [(0,0),(1,0),(2,0),(2,1),(2,2),(1,2),(0,2),(2,3),(2,4),(1,4),(0,4)]
number41 = [(0,0),(2,0),(0,1),(2,1),(0,2),(1,2),(2,2),(2,3),(2,4)]
number51 = [(2,0),(1,0),(0,0),(0,1),(0,2),(1,2),(2,2),(2,3),(2,4),(1,4),(0,4)]
number61 = [(2,0),(1,0),(0,0),(0,1),(0,2),(1,2),(2,2),(0,3),(2,3),(0,4),(1,4),(2,4)]
number71 = [(0,0),(1,0),(2,0),(2,1),(2,2),(2,3),(2,4)]
number81 = [(0,0),(1,0),(2,0),(0,1),(2,1),(0,2),(1,2),(2,2),(0,3),(2,3),(0,4),(1,4),(2,4)]
number91 = [(0,0),(1,0),(2,0),(0,1),(2,1),(0,2),(1,2),(2,2),(2,3),(2,4)]
number02 = [(4,0),(5,0),(6,0),(4,1),(6,1),(4,2),(6,2),(4,3),(6,3),(4,4),(6,4),(5,4)]
number12 = [(6,0),(6,1),(6,2),(6,3),(6,4)]
number22 = [(4,0),(5,0),(6,0),(6,1),(6,2),(5,2),(4,2),(4,3),(4,4),(5,4),(6,4)]
number32 = [(4,0),(5,0),(6,0),(6,1),(6,2),(5,2),(4,2),(6,3),(6,4),(5,4),(4,4)]
number42 = [(4,0),(6,0),(4,1),(6,1),(4,2),(5,2),(6,2),(6,3),(6,4)]
number52 = [(6,0),(5,0),(4,0),(4,1),(4,2),(5,2),(6,2),(6,3),(6,4),(5,4),(4,4)]
number62 = [(6,0),(5,0),(4,0),(4,1),(4,2),(5,2),(6,2),(4,3),(6,3),(4,4),(5,4),(6,4)]
number72 = [(4,0),(5,0),(6,0),(6,1),(6,2),(6,3),(6,4)]
number82 = [(4,0),(5,0),(6,0),(4,1),(6,1),(4,2),(5,2),(6,2),(4,3),(6,3),(4,4),(5,4),(6,4)]
number92 = [(4,0),(5,0),(6,0),(4,1),(6,1),(4,2),(5,2),(6,2),(6,3),(6,4)]
secondBar0 = [(1,5),(2,5),(3,5),(4,5),(5,5),(1,6),(2,6),(3,6),(4,6),(5,6),(1,7),(2,7),(3,7),(4,7),(5,7)]
secondBar1 = [(1,5),(1,6),(1,7)]
secondBar2 = [(2,5),(2,6),(2,7)]
secondBar3 = [(3,5),(3,6),(3,7)]
secondBar4 = [(4,5),(4,6),(4,7)]
secondBar5 = [(5,5),(5,6),(5,7)]
letterM = [(0,0),(0,1),(0,2),(0,3),(0,4),(1,1),(2,2),(3,1),(4,0),(4,1),(4,2),(4,3),(4,4)]
letterP = [(5,0),(5,1),(5,2),(5,3),(5,4),(6,0),(6,2),(7,0),(7,1),(7,2)]
loadingBar1 = [(0,6),(0,7)]
loadingBar2 = [(1,6),(1,7)]
loadingBar3 = [(2,6),(2,7)]
loadingBar4 = [(3,6),(3,7)]
loadingBar5 = [(4,6),(4,7)]
loadingBar6 = [(5,6),(5,7)]
loadingBar7 = [(6,6),(6,7)]
loadingBar8 = [(7,6),(7,7)]
sense = SenseHat() # Initialises the sense hat module
lock = threading.RLock() #Creates a lock to be able to allow both threads to change global variables with out causing problems. One lock for each shared variable so that the variables also don't interfere with each other
lock1 = threading.RLock() #""
lock2 = threading.RLock() #""
lock3 = threading.RLock() #""
lock4 = threading.RLock() #""
lock5 = threading.RLock() #""
lock6 = threading.RLock() #""
lock7 = threading.RLock() #""
lock8 = threading.RLock() #""
lock9 = threading.RLock() #""
lock10 = threading.RLock() #""
lock11 = threading.RLock() #""
lock12 = threading.RLock() #""
lock13 = threading.RLock() #""
lock14 = threading.RLock() #""
lock15 = threading.RLock() #""
lock16 = threading.RLock() #""
lock17 = threading.RLock() #""
lock18 = threading.RLock() #""
lock19 = threading.RLock() #""
lock20 = threading.RLock() #""
#################################################################################################################################
######################## Sets the rotation, Displays the start screen and Finds the list of MP3 songs ###########################
"""
Sets the rotation of the screen to the correct position, Creates the start screen which consists of my Initials MP, and also finds
the songs and their file paths in the correct folder
"""
sense.set_rotation(270)
for x in letterM:
sense.set_pixel(x[0],x[1],255,0,0)
for y in letterP:
sense.set_pixel(y[0],y[1],0,0,255)
List = glob.glob("/boot/mp3/*.mp3")
#################################################################################################################################
################################################### Secondary Display Thread ####################################################
"""
Function getSong takes the current song's filepath and splits it into the name of the song only. It then returns this name, which
is further split into the individual words of the name. If no songs are on the device, it will say so and then quit the program
"""
def getSong(x):
global List
global listWords
try:
display1 = List[x].split("/")
display = display1[(len(display1) - 1)].split(".", 1)[0]
listWords = display.split()
return listWords
except:
display = "No Songs are on This Device"
listWords = display.split()
return listWords
check2 = True
"""
Function showNumber shows the number of the song currently selected
"""
def showNumber(x):
global sense
sense.show_letter(str(x + 1))
time.sleep(1.5)
"""
Function loading displays the loading bars of the start screen with a time delay between each bar
"""
def loading():
global loadingBar1
global loadingBar2
global loadingBar3
global loadingBar4
global loadingBar5
global loadingBar6
global loadingBar7
global loadingBar8
for x in loadingBar1:
sense.set_pixel(x[0],x[1],255,0,0)
time.sleep(0.5)
for x in loadingBar2:
sense.set_pixel(x[0],x[1],255,165,0)
time.sleep(0.5)
for x in loadingBar3:
sense.set_pixel(x[0],x[1],255,255,0)
time.sleep(0.5)
for x in loadingBar4:
sense.set_pixel(x[0],x[1],124,252,0)
time.sleep(0.5)
for x in loadingBar5:
sense.set_pixel(x[0],x[1],0,128,0)
time.sleep(0.5)
for x in loadingBar6:
sense.set_pixel(x[0],x[1],0,255,127)
time.sleep(0.5)
for x in loadingBar7:
sense.set_pixel(x[0],x[1],0,255,255)
time.sleep(0.5)
for x in loadingBar8:
sense.set_pixel(x[0],x[1],0,0,255)
time.sleep(0.5)
"""
Function setTime1 takes the current time of the song and displays it in minutes at the top of the display and
every ten seconds a bar increases along the bottom of the display
"""
def setTime1(Time):
global number01
global number11
global number21
global number31
global number41
global number51
global number61
global number71
global number81
global number91
global number02
global number12
global number22
global number32
global number42
global number52
global number62
global number72
global number82
global number92
global secondBar0
global secondBar1
global secondBar2
global secondBar3
global secondBar4
global secondBar5
global sense
minute = int(Time / 60)
if minute < 10:
minute = "0" + str(minute)
else:
minute = str(minute)
if (int(Time / 60)) >= 1:
stringTime1 = Time - (60*int(Time / 60))
else:
stringTime1 = Time
sense.clear()
for y in range(10):
if minute[0] == str(y):
if y == 0:
for k in number01:
sense.set_pixel(k[0],k[1],75,0,130)
elif y == 1:
for k in number11:
sense.set_pixel(k[0],k[1],0,0,255)
elif y == 2:
for k in number21:
sense.set_pixel(k[0],k[1],0,255,255)
elif y == 3:
for k in number31:
sense.set_pixel(k[0],k[1],0,255,127)
elif y == 4:
for k in number41:
sense.set_pixel(k[0],k[1],0,128,0)
elif y == 5:
for k in number51:
sense.set_pixel(k[0],k[1],124,252,0)
elif y == 6:
for k in number61:
sense.set_pixel(k[0],k[1],255,255,0)
elif y == 7:
for k in number71:
sense.set_pixel(k[0],k[1],255,165,0)
elif y == 8:
for k in number81:
sense.set_pixel(k[0],k[1],250,128,114)
elif y == 9:
for k in number91:
sense.set_pixel(k[0],k[1],255,0,0)
if minute[1] == str(y):
if y == 0:
for k in number02:
sense.set_pixel(k[0],k[1],255,0,0)
elif y == 1:
for k in number12:
sense.set_pixel(k[0],k[1],250,128,114)
elif y == 2:
for k in number22:
sense.set_pixel(k[0],k[1],255,165,0)
elif y == 3:
for k in number32:
sense.set_pixel(k[0],k[1],255,255,0)
elif y == 4:
for k in number42:
sense.set_pixel(k[0],k[1],124,252,0)
elif y == 5:
for k in number52:
sense.set_pixel(k[0],k[1],0,128,0)
elif y == 6:
for k in number62:
sense.set_pixel(k[0],k[1],0,255,127)
elif y == 7:
for k in number72:
sense.set_pixel(k[0],k[1],0,255,255)
elif y == 8:
for k in number82:
sense.set_pixel(k[0],k[1],0,0,255)
elif y == 9:
for k in number92:
sense.set_pixel(k[0],k[1],75,0,130)
forTenSeconds = int((stringTime1 / 10))
for l in range(6):
if forTenSeconds == l:
if l == 0:
for m in secondBar0:
sense.set_pixel(m[0],m[1],0,0,0)
elif l == 1:
for m in secondBar1:
sense.set_pixel(m[0],m[1],255,0,0)
elif l == 2:
for m in secondBar1:
sense.set_pixel(m[0],m[1],255,0,0)
for m in secondBar2:
sense.set_pixel(m[0],m[1],255,255,0)
elif l == 3:
for m in secondBar1:
sense.set_pixel(m[0],m[1],255,0,0)
for m in secondBar2:
sense.set_pixel(m[0],m[1],255,255,0)
for m in secondBar3:
sense.set_pixel(m[0],m[1],0,255,0)
elif l == 4:
for m in secondBar1:
sense.set_pixel(m[0],m[1],255,0,0)
for m in secondBar2:
sense.set_pixel(m[0],m[1],255,255,0)
for m in secondBar3:
sense.set_pixel(m[0],m[1],0,255,0)
for m in secondBar4:
sense.set_pixel(m[0],m[1],0,255,255)
elif l == 5:
for m in secondBar1:
sense.set_pixel(m[0],m[1],255,0,0)
for m in secondBar2:
sense.set_pixel(m[0],m[1],255,255,0)
for m in secondBar3:
sense.set_pixel(m[0],m[1],0,255,0)
for m in secondBar4:
sense.set_pixel(m[0],m[1],0,255,255)
for m in secondBar5:
sense.set_pixel(m[0],m[1],0,0,255)
"""
Function display is the main function of the display thread and is responsible for checking to see whether the help, time or name
screens should be shown on the sensehat display. It also checks to see whether any symbols need to be displayed on the screen.
"""
def display():
global nowDisplaying
global lock
global lock1
global lock2
global hello
global check2
global leave
global sense
global check3
global isPlay
global playButton
global pauseButton
global check4
global canPause
global isNextTrack
global lock4
global check5
global nextTrackButton
global isPreviousTrack
global lock5
global check6
global previousTrackButton
global lock6
global lock7
global lock8
global lock9
global lock10
global check7
global check8
global check9
global check10
global check11
global check12
global check13
global whatSound1
global whatSound2
global whatSound3
global whatSound4
global noSoundButton
global lowSoundButton
global mediumSoundButton
global highSoundButton
global placeHolder
global showName
global middleTime
global lock11
global lock12
global angle
global checkAngle
global check14
global showHelp
global lock13
global infoButton
global check15
global check16
global lock14
global lock15
global lockedButton
global unlockedButton
global canOrientation1
global canOrientation2
global backgroundColour
global lock16
global check17
global check18
global check19
global lock17
global lock18
global checkScrollUp
global checkScrollDown
global scrollUpButton
global scrollDownButton
global lock19
global check20
global checkRewind
global rewindButton
global lock20
global check21
global checkFastForward
global fastForwardButton
loading()
lock.acquire()
check = nowDisplaying
lock.release()
showNumber(check)
check2 = False
hello = check
while check2 == False:
lock10.acquire()
check11 = showName
lock10.release()
lock13.acquire()
check14 = showHelp
lock13.release()
if check11 == True and check14 == False:
lock12.acquire()
if angle != checkAngle:
sense.set_rotation(angle)
checkAngle = angle
lock12.release()
lock4.acquire()
check5 = isNextTrack
lock4.release()
if check5 == True:
sense.set_pixels(nextTrackButton)
time.sleep(0.5)
lock4.acquire()
isNextTrack = False
lock4.release()
lock5.acquire()
check6 = isPreviousTrack
lock5.release()
if check6 == True:
sense.set_pixels(previousTrackButton)
time.sleep(0.5)
lock5.acquire()
isPreviousTrack = False
lock5.release()
lock.acquire()
hello = nowDisplaying
lock.release()
if hello != check:
showNumber(hello)
check = hello
placeholder = getSong(hello)
for word in placeholder:
lock12.acquire()
if angle != checkAngle:
sense.set_rotation(angle)
checkAngle = angle
lock12.release()
lock16.acquire()
check17 = backgroundColour
lock16.release()
sense.show_message(str(word), text_colour = check17, scroll_speed = 0.05)
lock4.acquire()
check5 = isNextTrack
lock4.release()
if check5 == True:
sense.set_pixels(nextTrackButton)
time.sleep(0.5)
lock4.acquire()
isNextTrack = False
lock4.release()
lock5.acquire()
check6 = isPreviousTrack
lock5.release()
if check6 == True:
sense.set_pixels(previousTrackButton)
time.sleep(0.5)
lock5.acquire()
isPreviousTrack = False
lock5.release()
lock.acquire()
hello = nowDisplaying
lock.release()
if hello != check:
showNumber(hello)
check = hello
break
lock2.acquire()
check3 = isPlay
lock2.release()
if check3 == True:
sense.set_pixels(playButton)
time.sleep(0.5)
lock2.acquire()
isPlay = False
lock2.release()
lock3.acquire()
check4 = canPause
lock3.release()
if check4 == True:
sense.set_pixels(pauseButton)
time.sleep(0.5)
lock3.acquire()
canPause = False
lock3.release()
lock6.acquire()
check7 = whatSound1
lock6.release()
if check7 == True:
sense.set_pixels(noSoundButton)
time.sleep(0.5)
lock6.acquire()
whatSound1 = False
lock6.release()
lock7.acquire()
check8 = whatSound2
lock7.release()
if check8 == True:
sense.set_pixels(lowSoundButton)
time.sleep(0.5)
lock7.acquire()
whatSound2 = False
lock7.release()
lock8.acquire()
check9 = whatSound3
lock8.release()
if check9 == True:
sense.set_pixels(mediumSoundButton)
time.sleep(0.5)
lock8.acquire()
whatSound3 = False
lock8.release()
lock9.acquire()
check10 = whatSound4
lock9.release()
if check10 == True:
sense.set_pixels(highSoundButton)
time.sleep(0.5)
lock9.acquire()
whatSound4 = False
lock9.release()
lock14.acquire()
check15 = canOrientation1
lock14.release()
if check15 == True:
sense.set_pixels(lockedButton)
time.sleep(0.5)
lock14.acquire()
canOrientation1 = False
lock14.release()
lock15.acquire()
check16 = canOrientation2
lock15.release()
if check16 == True:
sense.set_pixels(unlockedButton)
time.sleep(0.5)
lock15.acquire()
canOrientation2 = False
lock15.release()
lock10.acquire()
check11 = showName
lock10.release()
if check11 == False:
lock13.acquire()
check14 = showHelp
lock13.release()
if check14 == True:
sense.set_pixels(infoButton)
else:
lock11.acquire()
check12 = middleTime
lock11.release()
setTime1(check12)
break
lock1.acquire()
check2 = leave
lock1.release()
if check2 == True:
break
elif check14 == True and check11 == False:
lock12.acquire()
if angle != checkAngle:
sense.set_rotation(angle)
checkAngle = angle
lock12.release()
sense.set_pixels(infoButton)
lock4.acquire()
check5 = isNextTrack
lock4.release()
if check5 == True:
sense.set_pixels(nextTrackButton)
time.sleep(0.5)
sense.show_message("Next Track Button", text_colour = [255,0,0], scroll_speed = 0.05)
sense.set_pixels(infoButton)
lock4.acquire()
isNextTrack = False
lock4.release()
lock5.acquire()
check6 = isPreviousTrack
lock5.release()
if check6 == True:
sense.set_pixels(previousTrackButton)
time.sleep(0.5)
sense.show_message("Previous Track Button", text_colour = [255,0,0], scroll_speed = 0.05)
sense.set_pixels(infoButton)
lock5.acquire()
isPreviousTrack = False
lock5.release()
lock2.acquire()
check3 = isPlay
lock2.release()
if check3 == True:
sense.set_pixels(playButton)
time.sleep(0.5)
sense.set_pixels(pauseButton)
time.sleep(0.5)
sense.show_message("Play/Pause Button", text_colour = [255,0,0], scroll_speed = 0.05)
sense.set_pixels(infoButton)
lock2.acquire()
isPlay = False
lock2.release()
lock6.acquire()
check7 = whatSound1
lock6.release()
if check7 == True:
sense.set_pixels(noSoundButton)
time.sleep(0.5)
sense.show_message("Decrease Volume", text_colour = [255,0,0], scroll_speed = 0.05)
sense.set_pixels(infoButton)
lock6.acquire()
whatSound1 = False
lock6.release()
lock9.acquire()
check10 = whatSound4
lock9.release()
if check10 == True:
sense.set_pixels(highSoundButton)
time.sleep(0.5)
sense.show_message("Increase Volume", text_colour = [255,0,0], scroll_speed = 0.05)
sense.set_pixels(infoButton)
lock9.acquire()
whatSound4 = False
lock9.release()
lock14.acquire()
check15 = canOrientation1
lock14.release()
if check15 == True:
sense.set_pixels(lockedButton)
time.sleep(0.5)
sense.show_message("Orientation Lock", text_colour = [255,0,0], scroll_speed = 0.05)
sense.set_pixels(infoButton)
lock14.acquire()
canOrientation1 = False
lock14.release()
lock15.acquire()
check16 = canOrientation2
lock15.release()
if check16 == True:
sense.set_pixels(unlockedButton)
time.sleep(0.5)
sense.show_message("Orientation Lock", text_colour = [255,0,0], scroll_speed = 0.05)
sense.set_pixels(infoButton)
lock15.acquire()
canOrientation2 = False
lock15.release()