summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bridge.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/bridge.py b/bridge.py
new file mode 100644
index 0000000..0ab5b4a
--- /dev/null
+++ b/bridge.py
@@ -0,0 +1,59 @@
+#!/usr/bin/python3
+"""Simple demo of oscillating colors."""
+import lumiversepython
+import random
+import time
+
+def get_all_lights(rig):
+ """Return a list of all panels."""
+ return [rig.select('$panel={}'.format(i)) for i in range(32)]
+
+
+def restrict(low, x, high):
+ """Return a value low <= v <= high, and equal to x if possible."""
+ return max(low, min(x, high))
+
+
+def random_change():
+ """Return a random amount that a light should change each frame."""
+ return random.random() / 30
+
+
+def demo(lights, rig):
+ """Do some light things."""
+ light_status = [
+ {
+ 'is_increasing': True,
+ 'change': random_change(),
+ 'light': light,
+ 'current_value': 0,
+ }
+ for light in lights
+ ]
+ while True:
+ for light_s in light_status:
+ is_increasing = light_s['is_increasing']
+ change = light_s['change']
+ light = light_s['light']
+ current_value = light_s['current_value']
+ new_value = restrict(
+ 0, current_value + change * (int(is_increasing) * 2 - 1), 1), 1
+ )
+ light.setRGBRaw(0, 0, new_value)
+ light_s['current_value'] = new_value
+ if new_value == 1:
+ light_s['is_increasing'] = not is_increasing
+ light_s['change'] = random_change()
+ rig.updateOnce()
+ time.sleep(1 / 60)
+
+
+def main():
+ """Run show."""
+ rig = lumiversepython.Rig('/home/teacher/Lumiverse/PBridge.rig.json')
+ rig.init()
+ lights = get_all_lights(rig)
+ demo(lights, rig)
+
+if __name__ == '__main__':
+ main()