def update(self):
        if time.monotonic() - self.checkin > self._debounce:
            self.button_a = check("A")

            # b button was pressed
            if not self.button_b and check("B"):
                print("B button pressed")
                self.random_color()
                self.button_b = True
            else:
                self.button_b = False

            self.checkin = time.monotonic()

            if self.button_a:
                print("LED on")
                self.led = True
            else:
                self.led = False

            if self.button_b:
                print("RGB on. Color: {}".format(self.color))
                self.rgb = True
            else:
                self.rgb = False
Example #2
0
    def __init__(self):
        self.a = check("A")
        self.b = check("B")
        self.enabled = True
        self.mode = "temperature"

        self.checkin = time.monotonic()
Example #3
0
    def update(self):
        if time.monotonic() - self.checkin > 0.2:
            self.a = check("A")
            self.b = check("B")
            self.checkin = time.monotonic()

            if state.a:
                print("Button 'A' pressed")

            if state.b:
                print("Button 'B' pressed")
Example #4
0
    def update(self):
        if time.monotonic() - self.checkin > self._debounce:
            if not self.state and check("B"):
                self.press()

            if self.state and not check("B"):
                self.release()

            self.state = check("B")

            self.checkin = time.monotonic()
Example #5
0
 def update(self):
     if time.monotonic() - self.checkin > 0.2:
         self.a = check("A")
         self.b = check("B")
         self.checkin = time.monotonic()
         
         if state.a:
             self.enabled = not self.enabled
             
         if state.b:
             self.rotate_color()
Example #6
0
    def check(self, what):
        if what == THERMISTOR:
            return self.temperature()

        if what == PHOTOCELL:
            return photocell.value

        if what == BUTTON_A:
            return check("A")

        if what == BUTTON_B:
            return check("B")
Example #7
0
    def update(self):
        if time.monotonic() - self.checkin > self._debounce:
            if self.a and not check("A"):
                self.enabled = not self.enabled

            if self.b and not check("B"):
                if self.mode == "temperature":
                    self.mode = "light"
                else:
                    self.mode = "temperature"

            self.a = check("A")
            self.b = check("B")

            self.checkin = time.monotonic()
Example #8
0
# The setup.py Abstraction In Practice
from setup import check, led, rgb
import time

while True:
    if check("A"):
        led.value = True
    else:
        led.value = False

    if check("B"):
        rgb[0] = (255, 255, 255)
    else:
        rgb[0] = (0, 0, 0)
Example #9
0
 def check(self):
     return check("B")
Example #10
0
 def check(self):
     return check("A")
Example #11
0
# Using Simple State To Reduce Button Sample Frequency
from setup import check, led, rgb
import time

button_a = False
button_b = False

checkin = time.monotonic()

while True:
    if time.monotonic() - checkin > 0.2:
        button_a = check("A")
        button_b = check("B")
        checkin = time.monotonic()

    if button_a:
        print("Button 'A' pressed")

    if button_b:
        print("Button 'B' pressed")
Example #12
0
import time
from setup import led, rgb, check

while True:
    led.value = check("A")

    if check("B"):
        rgb[0] = (255, 255, 255)
    else:
        rgb[0] = (0, 0, 0)

    time.sleep(0.2)
Example #13
0
# Button Event Detection: Simple Variables
from setup import check
import time

checkin = time.monotonic()
a = False
b = False

while True:
    if time.monotonic() - checkin > 0.2:
        if not a and check("A"):
            print("'A' button pressed")
            
        if a and not check("A"):
            print("'A' button released")
        
        if not b and check("B"):
            print("'B' button pressed")
            
        if b and not check("B"):
            print("'B' button released")
            
        a = check("A")
        b = check("B")
        checkin = time.monotonic()
        
        
Example #14
0
def check_b():
    return check("B")
Example #15
0
def check_a():
    return check("A")