-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
91 lines (68 loc) · 2.41 KB
/
run.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
#NeoPixel World
from neopixel import *
from time import (sleep, time)
from datetime import datetime
import RPi.GPIO as GPIO
import argparse
#Custom Classes
from mqtt_service import *
from base_classes import *
from continents import *
from day_and_night_mode import *
from rainbow_mode import *
from music_mode import *
init_allleds()
mqttClient = MQTTService()
#Global Variables
#mode = MusicMode(2, 0)
mode = DayAndNightMode(True, 1)
worlds["WORLD"].setMode(mode)
# ----------------MAIN-------------------
if __name__ == '__main__':
# Process arguments
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--clear', action='store_true', help='clear LEDs on exit')
args = parser.parse_args()
mqttClient.connect()
sleep(2)
mqttClient.loop_start()
strip.begin()
mqttClient.publishModes()
mqttClient.publishBrightness()
print ('Press Ctrl-C to quit.')
if not args.clear:
print('Use "-c" argument to clear LEDs on exit')
try:
mic_check_interval = 2 # s
mic_check_tmstmp = 0
while True:
if stream_active():
# mic_tm = time()##
microphone_update()
# print('microphone_update():', time() - mic_tm)##
# loop modes
#loop_tm = time()##
if World.same_mode: # same mode on all continents
worlds["WORLD"].loop()
else: # indivudual modes
for continent in continents.values():
continent.loop()
#print('modes.loop():', time() - loop_tm)##
# load LED color values
#led_tm = time()##
#for led in leds:
# led.load()
#print('leds.load():', time() - led_tm)##
#show_tm = time()##
#sleep(0.001)
strip.show()
#print('strip.show():', time() - show_tm)##
# stop microphone stream if no MusicMode active
if stream_active() and time() > mic_check_tmstmp + mic_check_interval:
if not 'MUSIC' in set(map(lambda x: x.mode.key, continents.values())):
stop_microphone_stream()
mic_check_tmstmp = time()
except KeyboardInterrupt:
if args.clear:
clear()
strip.show()