I’ve been playing with a program for a Raspberry Pi that will show a configuration of colors on an LED WS2812 strip based on pressing one of many buttons and recognizing the state of various toggle switches.
I have an xlsx file that has all of the conditions, but my program doesnt seem to be reading it correctly.
When a button is pressed, there will be multiple conditions based on a few of the toggle switches. For example, if the reset button is pressed, it will look for the Toggle1, and based on its orientation, will turn the LED YELLOW or ORANGE.
I’m looking for advice on whether my table is set up correctly, or if I need to format it differently. I’m not sure how the python code would match all of the toggle switch data when the button is pressed.
the table that you have provided reminds me of a truth table for logic circuits (i.e., AND, OR, XOR, etc.).
What you can do, instead of assigning strings (on, off), use zeros (0) and ones (1). This will simplify processing the results.
To read the values from the excel file, you have a few options. You can use the all popular pandas library package or the openpyxl library package (there are others of course). Here is a simple test script to read a cell from an existing excel file in one of your directories:
import openpyxl
# Arbitrary directory with misc. excel file
excel_path = r'C:\folder_1_etc\folder_2_etc\excel_file_name.xlsx'
# Manage file via excel object
srcfile = openpyxl.load_workbook(filename=excel_path) # Create object file
worksheet = srcfile['worksheet_name_here'] # specify worksheet from file
# Row number
row = 3
# Get value from Column 'C', row '3'
cell_value = worksheet["C" + str(index)].value
print('Cell value:', cell_value)
In this example, we are reading the cell contents from column C, row 3.
Once you have read the values for a particular row, apply logic to the results to determine the expected color.