Last active
September 9, 2017 15:45
-
-
Save jake-walker/accb7b1684b6381894dadfa562dc9069 to your computer and use it in GitHub Desktop.
Bulb Pi Simple Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
# Variable for storing what LIRC remote to use | |
lirc_remote = "bulb" | |
# Dictionary to make the commands easy to read | |
commands = { | |
"on": "KEY_POWER", | |
"off": "KEY_POWER2", | |
"brightness up": "KEY_UP", | |
"brightness down": "KEY_DOWN", | |
"red": "KEY_RED", | |
"green": "KEY_GREEN", | |
"blue": "KEY_BLUE" | |
# I didn't put them all in yet. | |
} | |
# Function for sending a command that is passed in | |
def send_command(command): | |
# Check if the command given is in the dictionarys keys (the first value) | |
if command in commands.keys(): | |
# Execute the irsend command with the remote and command passed in | |
subprocess.call(["irsend", "SEND_ONCE", lirc_remote, commands[command]]) | |
# Return true to tell the program that it (probably) worked | |
return True | |
else: | |
# Return false to tell the program that the command passed in isn't valid | |
return False | |
# Descriptive start message to tell the user how to use the program | |
print("Enter a command to send it to the bulb. Press CTRL+C to exit.") | |
# Forever loop | |
while True: | |
# Ask the user for a command | |
command = input("> ") | |
# Call the function and pass in what the user typed, then store the result in a variable | |
result = send_command(command) | |
# We know the variable is either True or False and we also know if it's True it worked. | |
if result == True: | |
print("Executed command successfully!") | |
else: | |
print(command + " not found!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment