# Project#12 - Infrared Remote Controls # Information - In this project we're going to continuously query the RPInoRPI for TV remote signal data # The RPI_no_RPI needs two pieces of code for this project and you'll need to download and import the irremote.h... # Arduino library from github. The first piece of code is stand-alone for the RPI_no_RPI and allows for you to # program in signals 0 through 9 + the power button from a standard TV remote control. Please see the project video # to see how this is done. From there, upload the second piece of software to the RPI_no_RPI. The second piece # of code simply acts to decode incoming IR data and send a value of 0-9 to the PC. That is where this code comes # into play. In this code, you can run programs that you write based on the incoming data. You just need to # use your imagination... import time # The 'time' module is included with pycharm and allows for us to create delays. import serial # The 'serial' or 'pyserial' module needs to be imported. See the project video for more info. try: # Try to establish communication with the RPInoRPI board. if successful, only the 'try:' will be executed MCU = serial.Serial(port='COM10', baudrate=115200, timeout=0.01) # Timeout = 0.01. More on this later. time.sleep(5) # Wait 5 seconds. except: # If communication with the RPInoRPI could not be established, then perform the following instead: print('System Locked - Cannot communicate with MCU. Close this program, then reconnect to MCU and restart program') while True: # Forever loop. Close the program and start again. Check connection to the RPInoRPI pass # Do nothing # This is the start of the code data = 0 # Do the same for a variable named 'data' while True: # Execute the following forever until you stop the program data = MCU.readline() # Wait for a response from the MCU, and store the returned value in 'data data = str(data) # Ensure that the value in 'data' is a string. #print(data) # print it to the shell if you want to see it. if data == "b'0'": # If the returned value is 0, then run the following program print('Button#0 has been pressed. Running program 0 now...') # Write any code you'd like here. You can run an entire program when the 0 button is pressed. elif data == "b'1'": # else if the returned value is 1, then run the following program print('Button#1 has been pressed. Running program 1 now...') # Write any code you'd like here. You can run an entire program when the 1 button is pressed. elif data == "b'2'": # else if the returned value is 2, then run the following program print('Button#2 has been pressed. Running program 2 now...') # Write any code you'd like here. You can run an entire program when the 1 button is pressed. elif data == "b'3'": # else if the returned value is 3, then run the following program print('Button#3 has been pressed. Running program 3 now...') # Write any code you'd like here. You can run an entire program when the 1 button is pressed. elif data == "b'4'": # else if the returned value is 4, then run the following program print('Button#4 has been pressed. Running program 4 now...') # Write any code you'd like here. You can run an entire program when the 1 button is pressed. elif data == "b'5'": # else if the returned value is 5, then run the following program print('Button#5 has been pressed. Running program 5 now...') # Write any code you'd like here. You can run an entire program when the 1 button is pressed. elif data == "b'6'": # else if the returned value is 6, then run the following program print('Button#6 has been pressed. Running program 6 now...') # Write any code you'd like here. You can run an entire program when the 1 button is pressed. elif data == "b'7'": # else if the returned value is 7, then run the following program print('Button#7 has been pressed. Running program 7 now...') # Write any code you'd like here. You can run an entire program when the 1 button is pressed. elif data == "b'8'": # else if the returned value is 8, then run the following program print('Button#8 has been pressed. Running program 8 now...') # Write any code you'd like here. You can run an entire program when the 1 button is pressed. elif data == "b'9'": # else if the returned value is 9, then run the following program print('Button#9 has been pressed. Running program 9 now...') # Write any code you'd like here. You can run an entire program when the 1 button is pressed. elif data == "b'10'": # else if the returned value is 10, then run the following program print('Power Button has been pressed. Running power program now...') # Write any code you'd like here. You can run an entire program when the power button is pressed. elif data == "b''": pass # No nothing as this means that the RPI_no_RPI didn't send anything back else: pass # No nothing as this means that the signal received wasn't one of the programmed numbers (Was invalid)