Priority Queue with BS2
NZmbe
Posts: 7
Is it possible to write a priority queue within PBasic? Honestly I'm not even sure that I'm asking the right question here. Still very new to this realm and I'm hitting walls head on left and right with this project.
The idea is I'd like to take a 9 LED array (3 rows of 3), with one push button per row, and have the order in which a button is pressed show up on the array. Example: When button 'a' is pressed the first LED of its corresponding row goes high. When the next button is pressed (whether it be 'B' or 'C') the second LED for the corresponding row goes High. And the last button would illuminate LED 3.
The reason I ask about priority queueing is when button 'a' in this case goes low, the LED (in the case position 1) should go low and the remaining "high" LED's shift positions to reflect the new order of priority.
Is this type of code even possible in PBasic? Any help would be greatly appreciated.
The idea is I'd like to take a 9 LED array (3 rows of 3), with one push button per row, and have the order in which a button is pressed show up on the array. Example: When button 'a' is pressed the first LED of its corresponding row goes high. When the next button is pressed (whether it be 'B' or 'C') the second LED for the corresponding row goes High. And the last button would illuminate LED 3.
The reason I ask about priority queueing is when button 'a' in this case goes low, the LED (in the case position 1) should go low and the remaining "high" LED's shift positions to reflect the new order of priority.
Is this type of code even possible in PBasic? Any help would be greatly appreciated.
Comments
x=button 0=LED
x oooo
x oooo
x oooo
So for example
a-c=button LED=1 / 0
a 1000
b 0100
c 0010
then button 'a' is released
a 0000
b 1000
c 0100
Its that shift thats got me stumped
No, actually the opposite. The LEDs need to follow the buttons, following FIFO.
Think of having three boxes in which you are going to place objects in with random order over an extended period of time. You need to know which order the items went in so that they can be removed in order of FIFO (thus three LEDs per box/ button) To keep the cycle flowing without pulling all the items and reseting, you'd want to be able to cancle the 'priority' setting of the item you pulled, and in doing so shift the priority of the other boxes to reflect said action. I know the easiest way to achieve this is to have timers on the boxes but this is not a project based on time sensitivity, just priority sensitive.
As you decribed most recently (columns shifting left), older data on the right is moving left toward the buttons. Not sure what that is supposed to indicate or where that data came from.
Am I confused?
'P = Priority Level
'inputs - 'led array
.......'p1 'p2 'p3
IN1 - 0...0...1
IN2 - 1...0...0
IN3 - 0...1...0
Ok so, if this were the real thing, what just happened was IN2 was set High before IN1 and IN3, then IN3 was set High, then IN1 was set High last out of all three. So, by looking at the array we can see the order in which the buttons where pressed. Now, if I were to set IN2 Low, it would turn its corresponding LED low, and shift the other two priority columns like this:
.......'p1 'p2 'p3
IN1 - 0...1...0
IN2 - 0...0...0
IN3 - 1...0...0
Creating what I want to call a cycle although I know thats not PBasic correct. What I mean is, if I were to set IN2 High again it would show up on its row as Priority 3. Creating a cycle of 'priority' commands. If IN3 is set low, then what ever button/s are still set High will shift to accomodate the new priority status.
I hope that makes sence. Thanks again
Still easily done, except I think your expectations on the high/low might need adjusting. If all your switches are normally low, they will momentarily go high when pushed. So pressing a button will instantly light the corresponding LED in the rightmost column, and the previous data shifts left. Nothing happens when you release the button, that just advances the program to the "scan keyboard" portion of the program.
Can you live with that?
I thought it over last night, and came up with a "flow sketch."
"Crunching" means to remove all '0' values in the queue by shifting non-zero values down.
Copying the queue to the LEDs may need to be done in the L1 section.
The case of one key being down steady as a second key goes up and down needs to be addressed, OR just the changed key will need to be saved to the queue (L2).
HTH,
--Rich
I can't figure out how to 'link' the I/O pins to specific constants.
e.g.:
Rooma = dig0todig2
Roomb = dig3todig5
Roomc = dig6todig8
The idea being that Rooma display cant spill into roomb display. I was trying to accomplish this though an Alias/Mod but its not going anywhere. Or, can I make three different counters??? hmmm
Second question: To RiJoRi, thanks for the input! I understand the concept but not the application. Like I said before I'm still very new at this and thus I have no idea how to 'crunch the queue':smilewinkgrin: Are your 'queue' ideas done through Write/Read?
(n00b alert) If I'm running 9 LEDs out OUTH how can I get the remaining LED to follow suit? OUTH=8-15 so how can get out7 involved?
Plus I'm all ears for any other suggestions that you may have.
Thanks again for the help!