Esempio n. 1
0
class Stop:
    ''' Create a object to store a stop with relation to its rgb pin mappings'''
    def __init__(self, name, arrival_time, red, green, blue):
        self.name = name
        self.arrival_time = arrival_time
        self.light = RGBLED(red, green, blue)
        self.colors = {
            'red': (1, 0, 0),
            'blue': (0, 0, 1),
            'green': (0, 1, 0),
            'yellow': (1, 1, 0),
        }

    def pulse(self, color):
        self.light.pulse(fade_in_time=.7,
                         fade_out_time=.3,
                         on_color=color,
                         off_color=(0, 0, 0),
                         background=True)
        return

    def color_decider(self):
        ''' Set light to be color/pulse depending on how long until the muni is coming'''
        self.light.on()
        if self.arrival_time in (0, 1, 2):
            self.pulse(self.colors['red'])
        elif self.arrival_time in (3, 4):
            self.pulse(self.colors['green'])
        elif self.arrival_time in (5, 6, 7, 8):
            self.light.color = self.colors['green']
        elif self.arrival_time in (9, 10, 11, 12, 13, 14, 15):
            self.light.color = self.colors['yellow']
        elif self.arrival_time > 15:
            self.light.color = self.colors['blue']
        else:
            raise Exception(
                'Unexpected else in color decider on arrival_time value: {}'.
                format(self.arriva_time))
        return

    def cycle_colors(self):
        '''
		 	Cycling colors indicates to users that the lights are updating 
		'''
        self.light.on()
        self.light.color = self.colors['red']
        time.sleep(.5)
        self.light.color = self.colors['green']
        time.sleep(.5)
        self.light.color = self.colors['blue']
        time.sleep(.5)
        self.light.color = self.colors['yellow']
        time.sleep(.5)
        self.light.off()
Esempio n. 2
0
    print('received %s bytes from %s' % (len(data), address))
    print(data)

    if data:
        print("data recvd")
        sent = sock.sendto(data, address)
        print('sent %s bytes back to %s' % (sent, address))

        packet_received_time = int(time.time())

        if data == b"servo;\n":
            swipe()
            print("Servod")
        else:
            #indicator.fadeIn()
            sol.trigger()
            print("solenoid triggered")

    print(indicator_state)
    if indicator_state == False and int(
            time.time()) - packet_received_time > 0.5:
        indicator_state = True
        time.sleep(0.1)
        indicator_state = False

    if indicator_state:
        indicator.on()
    else:
        indicator.off()
Esempio n. 3
0
from gpiozero import RGBLED
from time import sleep

led = RGBLED(22,27,17)

led.on()
sleep(0.5)
led.off()
led.red = 1
sleep(0.5)
led.red =0
led.green=1
sleep(0.5)
led.green = 0
led.blue = 1
sleep(0.5)
led.blue=0


Esempio n. 4
0
1) Candle light
2) 40W Tungsten bulb
3) 100W Tungsten bulb
4) Halogen bulb
5) Carbon Arc bulb

Press CTRL+C to exit and turn off.
""")

# main loop
try:
    while True:
        # present choice options to user
        choice = input()
        choice = int(choice)
        if choice == 1:
            rgblist = candle
        elif choice == 2:
            rgblist = fortyw
        elif choice == 3:
            rgblist = hundredw
        elif choice == 4:
            rgblist = halogen
        elif choice == 5:
            rgblist = carbon
        led.on(rgblist[0], rgblist[1], rgblist[2])
        time.sleep(1.0 / 60)

except KeyboardInterrupt:
    led.off()
Esempio n. 5
0
from gpiozero import RGBLED, Button
from time import sleep

led1 = RGBLED(14,15,18)
led2 = RGBLED(23,24,25)
led3 = RGBLED(8,7,12)

button = Button(21)

mode1 = (1, 0, 0) # Red
mode2 = (0, 1, 0) # Green

while True:	
	led1.on()
	led2.on()
	led3.on()

	button.wait_for_press()
	button.wait_for_release()

	led1.blink()
	sleep(0.4)
	led2.blink()
	sleep(0.4)
	led3.blink()

	button.wait_for_press()
	button.wait_for_release()
	
	led1.pulse()
	sleep(0.4)