-
Notifications
You must be signed in to change notification settings - Fork 4
/
sketchChangeList.py
90 lines (71 loc) · 3.54 KB
/
sketchChangeList.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
#!/usr/bin/env python
import RPi.GPIO as GPIO
import os
import time
import random as random
GPIO.setmode(GPIO.BCM)
GPIO.setup(0, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# Here's the master list of sketches to cycle through
sketchArray = [
'/home/pi/lavalamp/sketches/Fireworks/application.linux-armv6hf/Fireworks',
'/home/pi/lavalamp/sketches/rotatingRainbow/application.linux-armv6hf/rotatingRainbow',
'/home/pi/lavalamp/sketches/grid15x8z_clouds/application.linux-armv6hf/grid15x8z_clouds',
'/home/pi/lavalamp/sketches/wavyRainbow/application.linux-armv6hf/wavyRainbow',
'/home/pi/lavalamp/sketches/grid15x8_noise_simple/application.linux-armv6hf/grid15x8_noise_simple',
'/home/pi/lavalamp/sketches/verticalWaveyRainbowSoundReactive/application.linux-armv6hf/verticalWaveyRainbowSoundReactive',
'/home/pi/lavalamp/sketches/gradientBlender/application.linux-armv6hf/gradientBlender',
'/home/pi/lavalamp/sketches/winterIsComing/application.linux-armv6hf/winterIsComing',
'/home/pi/lavalamp/sketches/redFall/application.linux-armv6hf/redFall',
'/home/pi/lavalamp/sketches/kelp/application.linux-armv6hf/kelp',
'/home/pi/lavalamp/sketches/hotFluid/application.linux-armv6hf/hotFluid',
'/home/pi/lavalamp/sketches/blobbyLamp/application.linux-armv6hf/blobbyLamp',
'/home/pi/lavalamp/sketches/blobbyLampWarm/application.linux-armv6hf/blobbyLampWarm',
'/home/pi/lavalamp/sketches/blueBubbles/application.linux-armv6hf/blueBubbles',
'/home/pi/lavalamp/sketches/flocking/application.linux-armv6hf/flocking',
'/home/pi/lavalamp/sketches/simpleFire/application.linux-armv6hf/simpleFire',
'/home/pi/lavalamp/sketches/colourFire/application.linux-armv6hf/colourFire'
]
modesLength = len(sketchArray)
randomStartSketch = random.randint(0,modesLength)
sketchNumber = randomStartSketch
# here's the path to the startup array test sketch
arraySweep ='/home/pi/lavalamp/sketches/startupArraySweep/application.linux-armv6hf/startupArraySweep'
# start up the arraySweep as a 'power on self test' sorta thing
os.system(""+ arraySweep +" &")
# kill it and move on after a set time - this may vary if you change the sketch
time.sleep(10.85)
#rrrrrrrrrrrroll the flames
os.system("killall java")
# nothing to see here - start a random mode - make sure it's not the same as the one you already drew
firstSketch = random.randint(0,modesLength-1)
# launch it
if firstSketch == sketchNumber:
# have another go
firstSketch = random.randint(0,modesLength-1)
else:
os.system(""+str(sketchArray[firstSketch])+" &")
def changeMode(channel):
# make sure you got access to the sketchNumber variable
global sketchNumber
# make sure if you go past the end you come back around
if sketchNumber > modesLength-1:
sketchNumber = 0
#print 'end of the mode list reached, we going round again'
# here is where you execute the sketch change
#print 'switch detected - changing sketch to', sketchArray[sketchNumber]
os.system("killall java")
os.system(""+str(sketchArray[sketchNumber])+" &")
# increment
sketchNumber +=1
#***************************************************************************************************************************
# this is the main section for implementing GPIO button detection - plus the empty loop that constitutes the running program
#***************************************************************************************************************************
GPIO.add_event_detect(0, GPIO.RISING, callback=changeMode, bouncetime=500)
try:
while(True):
# avoid 100% CPU usage
time.sleep(1)
except KeyboardInterrupt:
# cleanup GPIO settings before exit
GPIO.cleanup()
# end