예제 #1
0
    def __init__(self):
        # connect to your Arduino via serial
        # Arduino can be found with ls /dev/tty* in LXTerminal
        self.ser = serial.Serial('/dev/ttyACM0', 9600)
        self.the_button = TheButton()

        self.last_lowest = 60.0
예제 #2
0
 def __init__(self):
     CONTROLLER_ADDRESS = "192.168.1.119"
     self.led = ledcontroller.LedController(CONTROLLER_ADDRESS)
     self.group = 0  #Limitless LED Bulb Bridge Group of LEDs to use. 0 is all.
     # Create a new instance of the button client. Does nothing until start() is called
     self.the_button = TheButton()
     self.last_lowest = 60.0
예제 #3
0
class ButtonApp():
    def __init__(self):
        # connect to your Arduino via serial
        # Arduino can be found with ls /dev/tty* in LXTerminal
        self.ser = serial.Serial('/dev/ttyACM0',9600)
        self.the_button = TheButton()

        self.last_lowest = 60.0


    def run(self):
        # The WebSocketApp loop runs in it's own thread,
        # so make sure you call TheButton.close() when you're done with it!
        self.the_button.start()

        try:
            while True:
                #tmnw=round(self.the_button.current_time*10)
                tmnw=round((math.floor(self.the_button.current_time) + (1-((self.the_button.current_time-math.floor(self.the_button.current_time))/0.36)))*10) # weird calculation because of time.clock
                print tmnw
                tmnw2=str(round(tmnw)).rstrip('0').rstrip('.') # strip decimal places
                #print time.clock()
                self.ser.write(bytearray(tmnw2,'ascii')) # write deciseconds to serial
                #self.ser.write(tmnw)
                time.sleep(0.5) # necessary, or else serial will collapse. however this makes tmnw round to seconds, deciseconds get lost.
        except (KeyboardInterrupt,SystemExit):
            pass
        self.close()

    def close(self):
        # The Button WebSocketApp runs in it's own thread, so make sure it's closed. This also closes the socket
        self.the_button.close()
    def __init__(self):
        # Find your BT device's address using 'hcitool lescan' (requires su)
        self.playbulb = gatt.connect('AB:CD:EF:01:23:45')
        # Create a new instance of the button client. Does nothing until start() is called
        self.the_button = TheButton()

        self.last_lowest = 60.0
예제 #5
0
    def __init__(self, lights):
        self.lights = lights; 
        for light in self.lights:
            light.brightness = 255
            light.transitiontime = 2

        # Create a new instance of the button client. Does nothing until start() is called
        self.the_button = TheButton()
        self.last_lowest = 60.0
    def __init__(self):
        # Find your BT device's address using 'hcitool lescan' (requires su)
        PLAYBULB_ADDRESS_1 = "AB:CD:EF:01:02:03"
        #PLAYBULB_ADDRESS_2 = "AB:CD:EF:01:02:03"
        #PLAYBULB_ADDRESS_3 = "AB:CD:EF:01:02:03"
	# Add bulbs to use to list
        self.bulb_list = []
        self.bulb_list.append(gatt.connect(PLAYBULB_ADDRESS_1))
        #self.bulb_list.append(gatt.connect(PLAYBULB_ADDRESS_2))
        #self.bulb_list.append(gatt.connect(PLAYBULB_ADDRESS_3))
        # Create a new instance of the button client. Does nothing until start() is called
        self.the_button = TheButton()
        self.last_lowest = 60.0
예제 #7
0
class ButtonApp():
    def __init__(self):
        # Find your BT device's address using 'hcitool lescan' (requires su)
        PLAYBULB_ADDRESS_1 = "AB:CD:EF:01:02:03"
        PLAYBULB_ADDRESS_2 = "AB:CD:EF:01:02:03"
        PLAYBULB_ADDRESS_3 = "AB:CD:EF:01:02:03"
	# Add bulbs to use to list
        self.bulb_list = []
        self.bulb_list.append(PLAYBULB_ADDRESS_1)
        # Create a new instance of the button client. Does nothing until start() is called
        self.the_button = TheButton()
        self.last_lowest = 60.0

    def writeColour(self, colour):
        # Set Playbulb colour
        for e in self.bulb_list:
            subprocess.call(('gatttool -b ' + e + ' --char-write -a 0x0016 -n ' + colour).split())

    def writeEffect(self, command):
        # Set Playbulb colour
        for e in self.bulb_list:
            subprocess.call(('gatttool -b ' + e + ' --char-write -a 0x0014 -n ' + command).split())

    def run(self):
        # The WebSocketApp loop runs in it's own thread,
        # so make sure you call TheButton.close() when you're done with it!
        self.the_button.start()
        previous_colour='0'
        try:
            while True:
                # Colours are in hexadecimal but the PlayBulb Candle required saturation in front of the value
                colour = '00'+self.the_button.colour
                # Set the PlayBulb to the current flair colour
                # Resource: Protocols for PlayBulb products (https://github.com/Phhere/Playbulb)
                if colour != previous_colour:
                    self.writeColour(colour)
                previous_colour=colour
                # There's no built-in time persistence, so by default, lowest time is for the current session
                if self.the_button.lowest_time < self.last_lowest:
                    self.last_lowest = self.the_button.lowest_time
                    self.writeEffect(colour+'01000100')  # Flash when a new record is set
                    print("New button record! " + str(math.floor(self.last_lowest)))
        except KeyboardInterrupt:
            pass
        self.close()

    def close(self):
        # The Button WebSocketApp runs in it's own thread, so make sure it's closed. This also closes the socket
        self.the_button.close()
class ButtonApp():
    def __init__(self):
        # Find your BT device's address using 'hcitool lescan' (requires su)
        PLAYBULB_ADDRESS_1 = "AB:CD:EF:01:02:03"
        #PLAYBULB_ADDRESS_2 = "AB:CD:EF:01:02:03"
        #PLAYBULB_ADDRESS_3 = "AB:CD:EF:01:02:03"
	# Add bulbs to use to list
        self.bulb_list = []
        self.bulb_list.append(gatt.connect(PLAYBULB_ADDRESS_1))
        #self.bulb_list.append(gatt.connect(PLAYBULB_ADDRESS_2))
        #self.bulb_list.append(gatt.connect(PLAYBULB_ADDRESS_3))
        # Create a new instance of the button client. Does nothing until start() is called
        self.the_button = TheButton()
        self.last_lowest = 60.0


    def run(self):
        # The WebSocketApp loop runs in it's own thread,
        # so make sure you call TheButton.close() when you're done with it!
        self.the_button.start()
        previous_colour='0' # Initialise previous colour
        try:
            while True:
                # Colours are in hexadecimal but the PlayBulb Candle required saturation in front of the value
                colour = '00'+self.the_button.colour
                # Set the PlayBulbs to the current flair colour
                # Resource: Protocols for PlayBulb products (https://github.com/Phhere/Playbulb)
                if colour != previous_colour:
                    for e in self.bulb_list:
                        e.write('0016', colour)
                    previous_colour=colour
                # There's no built-in time persistence, so by default, lowest time is for the current session
                if self.the_button.lowest_time < self.last_lowest:
                    for e in self.bulb_list:
                        e.write('0014', colour+'01000100')  # Flash when a new record is set
                    self.last_lowest = self.the_button.lowest_time
                    print("New button record! " + str(math.floor(self.last_lowest)))
                    previous_colour='0' # Reset previous colour so flashing stops before next colour change
        except KeyboardInterrupt:
            pass
        self.close()

    def close(self):
        # The Button WebSocketApp runs in it's own thread, so make sure it's closed. This also closes the socket
        self.the_button.close()
        # Disconnect from the bluetooth device
        for e in self.bulb_list:
            e.disconnect()
예제 #9
0
class ButtonApp():
    def __init__(self):
        # Create a new instance of the button client. Does nothing until start() is called
        self.the_button = TheButton()
        self.last_lowest = 60.0

        self.ser = serial.Serial('/dev/tty.usbmodem621', 57600)
        
        self.prev_color = 0
        self.color_list = ['Purple','Blue','Green','Yellow','Orange','Red']


    def run(self):
        self.the_button.start()
        try:
            while True: 
                curr_color = self.the_button.colour
                if curr_color != self.prev_color:
                    self.prev_color = curr_color
                    print self.color_list[curr_color-2]
                    self.ser.write(str(curr_color))


        except KeyboardInterrupt:
            pass
        self.close()


    def close(self):
        self.the_button.close()

    def assignColor(self, button_sec):
        if 51.01 <= button_sec <= 60.00:
            button_color = 2
        elif 41.01 <= button_sec <= 51.00:
            button_color = 3
        elif 31.01 <= button_sec <= 41.00:
            button_color = 4
        elif 21.01 <= button_sec <= 31.00:
            button_color = 5
        elif 11.01 <= button_sec <= 21.00:
            button_color = 6 
        elif 0.01 <= button_sec <= 11.00:
            button_color = 7
        else:
            button_color = 0

        return button_color
예제 #10
0
    def __init__(self):
        # connect to your Arduino via serial
        # Arduino can be found with ls /dev/tty* in LXTerminal
        self.ser = serial.Serial('/dev/ttyACM0',9600)
        self.the_button = TheButton()

        self.last_lowest = 60.0
예제 #11
0
class HueButton():
    def __init__(self, lights):
        self.lights = lights; 
        for light in self.lights:
            light.brightness = 255
            light.transitiontime = 2

        # Create a new instance of the button client. Does nothing until start() is called
        self.the_button = TheButton()
        self.last_lowest = 60.0

    def set_color(self, hue):
        #Takes in a string for a color and sets all lights to that color
        for light in self.lights:
            light.xy = hue;

    def flash(self):
        for light in self.lights:
            light.xy = [0.2941, 0.1106]

    def run(self):
        # The WebSocketApp loop runs in it's own thread,
        # so make sure you call TheButton.close() when you're done with it!
        self.the_button.start()

        try:
            while True:
                color = self.the_button.hue_color  #Hue XY color space values
                # Set the Hue bulb to the current flair colour
                # Resource: Protocols for Hue bulbs from https://github.com/studioimaginaire/phue/
                self.set_color(color)

                # There's no built-in time persistence, so by default, lowest time is for the current session
                if self.the_button.lowest_time < self.last_lowest:
                    self.last_lowest = self.the_button.lowest_time
                    self.flash()  # Flash when a new record is set
                    print("New button record! " + str(math.floor(self.last_lowest)))
        except KeyboardInterrupt:
            pass
        self.close()

    def close(self):
        # The Button WebSocketApp runs in it's own thread, so make sure it's closed. This also closes the socket
        self.the_button.close()
        # Disconnect from the bluetooth device
        self.playbulb.disconnect()
예제 #12
0
    def __init__(self):
        # Create a new instance of the button client. Does nothing until start() is called
        self.the_button = TheButton()
        self.last_lowest = 60.0

        self.ser = serial.Serial('/dev/tty.usbmodem621', 57600)
        
        self.prev_color = 0
        self.color_list = ['Purple','Blue','Green','Yellow','Orange','Red']
예제 #13
0
    def __init__(self):
        # Find your BT device's address using 'hcitool lescan' (requires su)
        PLAYBULB_ADDRESS_1 = "AB:CD:EF:01:02:03"
        PLAYBULB_ADDRESS_2 = "AB:CD:EF:01:02:03"
        PLAYBULB_ADDRESS_3 = "AB:CD:EF:01:02:03"
	# Add bulbs to use to list
        self.bulb_list = []
        self.bulb_list.append(PLAYBULB_ADDRESS_1)
        # Create a new instance of the button client. Does nothing until start() is called
        self.the_button = TheButton()
        self.last_lowest = 60.0
class ButtonApp():
    def __init__(self):
        # Find your BT device's address using 'hcitool lescan' (requires su)
        self.playbulb = gatt.connect('AB:CD:EF:01:23:45')
        # Create a new instance of the button client. Does nothing until start() is called
        self.the_button = TheButton()

        self.last_lowest = 60.0

    def run(self):
        # The WebSocketApp loop runs in it's own thread,
        # so make sure you call TheButton.close() when you're done with it!
        self.the_button.start()

        try:
            while True:
                # Colours are in hexadecimal but the PlayBulb Candle required saturation in front of the value
                colour = '00' + self.the_button.colour
                # Set the PlayBulb to the current flair colour
                # Resource: Protocols for PlayBulb products (https://github.com/Phhere/Playbulb)
                self.playbulb.write('0016', colour)

                # There's no built-in time persistence, so by default, lowest time is for the current session
                if self.the_button.lowest_time < self.last_lowest:
                    self.last_lowest = self.the_button.lowest_time
                    self.playbulb.write(
                        '0014',
                        colour + '01000100')  # Flash when a new record is set
                    print("New button record! " +
                          str(math.floor(self.last_lowest)))
        except KeyboardInterrupt:
            pass
        self.close()

    def close(self):
        # The Button WebSocketApp runs in it's own thread, so make sure it's closed. This also closes the socket
        self.the_button.close()
        # Disconnect from the bluetooth device
        self.playbulb.disconnect()
예제 #15
0
class ButtonApp():
    def __init__(self):
        CONTROLLER_ADDRESS = "192.168.1.119"
        self.led = ledcontroller.LedController(CONTROLLER_ADDRESS)
        self.group = 0  #Limitless LED Bulb Bridge Group of LEDs to use. 0 is all.
        # Create a new instance of the button client. Does nothing until start() is called
        self.the_button = TheButton()
        self.last_lowest = 60.0

    def run(self):
        # The WebSocketApp loop runs in it's own thread,
        # so make sure you call TheButton.close() when you're done with it!
        self.the_button.start()
        previous_colour = '0'  # Initialise previous colour
        try:
            while True:
                # Colours are in hexadecimal but the PlayBulb Candle required saturation in front of the value
                colour = self.the_button.limitless_colour
                # Set the PlayBulbs to the current flair colour
                # Resource: Protocols for PlayBulb products (https://github.com/Phhere/Playbulb)
                if colour != previous_colour:
                    self.led.set_color(colour, self.group)
                    previous_colour = colour
                # There's no built-in time persistence, so by default, lowest time is for the current session
                if self.the_button.lowest_time < self.last_lowest:
                    self.led.set_color(
                        'white', self.group)  # Flash when a new record is set
                    self.led.set_color(colour, self.group)
                    self.last_lowest = self.the_button.lowest_time
                    print("New button record! " +
                          str(math.floor(self.last_lowest)))
                    previous_colour = '0'  # Reset previous colour so flashing stops before next colour change
        except KeyboardInterrupt:
            pass
        self.close()

    def close(self):
        # The Button WebSocketApp runs in it's own thread, so make sure it's closed. This also closes the socket
        self.the_button.close()
예제 #16
0
class ButtonSerial():
    def __init__(self):
        self.the_button = TheButton()
    
    def init_serial(self,interface,baud):
        self.interface = serial.Serial(interface, baud, timeout=1)
 
    def run(self):
        # The WebSocketApp loop runs in it's own thread,
        # so make sure you call TheButton.close() when you're done with it!
        self.the_button.start()

        try:
            while True:
                colour = self.the_button.ascii_colour
                self.interface.write(colour.encode()) 
        except KeyboardInterrupt:
            pass
        self.close()

    def close(self):
        # The Button WebSocketApp runs in it's own thread, so make sure it's closed. This also closes the socket
        self.the_button.close()
예제 #17
0
#!/usr/bin/python

from time import sleep
from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate

from thebutton import TheButton



# Initialize the LCD plate.  Should auto-detect correct I2C bus.  If not,
# pass '0' for early 256 MB Model B boards or '1' for all later versions
lcd = Adafruit_CharLCDPlate()

# turn on the lcd and declare thebutton
thebutton=TheButton()
lcd.backlight(lcd.ON)


while True: 
	lcd.clear()
	lcd.message(thebutton.get_current_time()) 
	sleep(.5)
예제 #18
0
 def __init__(self):
     self.the_button = TheButton()