I am trying to create a python program to do the following:
- accept a list of instruction inputs and length of time to execute the instructions from the user
- read the instructions from the list, assign its time value and execute in a first in first out structure
- all instructions must be on the list before any instructions are executed
The goal of the program is to use the Explorer Hat Pro and its LEDs and capacitive buttons to input the instruction (activate an LED) and a keyboard to add a time value, use the return / enter key on the keyboard to end data input and start the execution of instructions. As an example the user might press button 1 on the explorer hat, enter 5 on a keyboard then button 2 on the hat followed by 2 on the keyboard. When enter is selected an LED with name '1' is turned on for 5 seconds followed by led '2' for 2 seconds. Below is an example of what i want to achieve in pseudo code:
The part I am having difficulty with is getting the data entry into a list or array with a time value then recovering the instruction and executing it with a given time value. I hope the pseudo code above helps explain what I am trying to do. Any questions please ask and thank you in advance to anyone who can help.
Code: Select all
#This is pseudo code # create to lists or arrays to store data define instruction list / array define time list / array #instruction list up_arrow = led1.on down_arrow = led2.on right_arrow = led3.on left_arrow = led4.on x = execute commands p = pulse all leds #get user input and add to relevant list / array print - "please enter instruction: " get user input # via keyboard add input to instruction list / array print - "how long will this instruction last: " get user input # via keyboard add time value to time list / array #execute commands count items in both lists #both lists should have the same number of values if instruction_list_count = time_list_count: #error checking l = total values in list while true: For i in range(l): get first value from instruction list get first value from time list execute instruction for specified time remove executed instruction and time from lists repeat loop until all instructions have been completed end