Beispiel #1
0
# Import the necessary libraries.
# gpiozero contains our JamHat object.
from gpiozero import JamHat
from time import sleep

# Initialise the JamHat object.
jh = JamHat()

# Setup a try/except block so we can run until CTRL+C is pressed.
try:
    # Initialise counter
    counter = 0
    while True:
        if jh.button_1.is_pressed or jh.button_2.is_pressed:
            # If either button is pressed...
            if jh.button_1.is_pressed:
                # If the left button is pressed, increment the counter.
                counter += 1
                # Wait until the button is released before moving on.
                jh.button_1.wait_for_release()
            if jh.button_2.is_pressed:
                # If the right button is pressed, increment the counter.
                counter -= 1
                # Wait until the button is released before moving on.
                jh.button_2.wait_for_release()
            # Print out the counter value to the screen.
            print("Counter: %d" % counter)
        sleep(0.1)
except KeyboardInterrupt:
    # If someone presses CTRL+C, close the JamHat, freeing of the Pins for use elsewhere.
    jh.close()
# Import the necessary libraries.
# gpiozero contains our JamHat object.
from gpiozero import JamHat
from time import sleep

# Initialise the JamHat object.
jh = JamHat()

# Setup a try/except block so we can run until CTRL+C is pressed.
try:
    while True:
        if (jh.button_1.is_pressed):
            # If the button on the left is pressed, beep midi note 80.
            jh.buzzer.play(80)
        elif (jh.button_2.is_pressed):
            # If the button on the right is pressed, beep midi note 60.
            jh.buzzer.play(60)
        else:
            # Turn off the buzzer.
            jh.off()
except KeyboardInterrupt:
    # If someone presses CTRL+C, close the JamHat, freeing of the Pins for use elsewhere.
    jh.close()
def lightsJamHat(response):
    # sonosUri = SONOS_BASE_URI + "/%s/nfc/%s" % (room, command)

    if response == "success":
        try:
            # # For Jam-HAT
            # Initialise the JamHat object.
            jh = JamHat()
            # # End JamHat
            #
            # i is the counter for the LED row.
            i = 2
            # j is the counter for the LED column.
            j = 2
            # Create counter
            x = 0

            # Setup a try/except block so we can run until CTRL+C is pressed.
            # try:
            for x in range(7):
                #while True:
                # Using modular arithmetic, decrease the light counter.
                # Our lights are in a matrix with rows 0-1 and columns 0-2.
                # Eg. [0][1] is the top yellow LED.
                if (j == 2):
                    # If we're at the end of the column, increment to the next row.
                    i = (i + 1) % 2
                # Increment the column.
                j = (j + 1) % 3
                sleep(0.2)
                # Turn the hat off.
                jh.off()
                # Turn on the LED at i j on the board.
                jh[i][j].on()
                # Turn the hat off.
                #jh.off()
                # Increment by 1
                x = x + 1
            jh.close()
        except:
            print(
                "There was a JamHat Error in nfcpy_SonosController.lightsJamHat"
            )
            try:
                lightsBlinkstick("error")
            except:
                print(
                    'Blinkstick had some sort of error in nfcpy_SonosController.lightsJamHat'
                )

    elif response == "error":
        try:
            # # For Jam-HAT
            # Initialise the JamHat object.
            jh = JamHat()
            # # End JamHat
            #
            # Build an array of notes in hertz.
            NOTES = [440.000, 391.995, 349.228, 329.628, 293.665, 261.626]

            # Function to play beep for one second
            def play_buzzer():
                end_time = datetime.now() + timedelta(seconds=0.5)
                while datetime.now() < end_time:
                    jh.buzzer.play(NOTES[1])

            # Run function
            play_buzzer()
            # Close Jam-Hat
            jh.close()
            # # End Jam-HAT
        except:
            print("There was a JamHat error in nfcpy_SonosController")