Using a V1 micro:bit, is it possible to have two independent LEDs? I want one to act as a heartbeat (flash once a second), the other to indicate, for example, go/nogo.
Whatever pairings I’ve tried, other LEDs come on when both of my chosen LEDs are on, which is ugly!
I was misled by the way the 'standard' examples of LED control manipulate both the 'row' and 'column' GPIOs.
The central LED is at external position (3, 3), and the bottom left at (5, 1), which correspond to GPIOs (r2, c3) and (r3, c3) respectively. If I use the bottom left as the heartbeat, then whenever I switch it off (c3 set high) I’ll also switch (3, 3) off.
The answer (to my problem: hardly a general-purpose solution) is to leave c3 set low permanently and control the two LEDs using r2 and r3 respectively.
I could use the top right button (1, 5) => (r1, c3) as well.
Or, for more choice, leave r1 set high permanently and use c1 .. c9 for control.
Related
I know that you can turn on a vehicle signal (for example, the left indicator) in traci using:
traci.vehicle.setSignals(vehID, int)
where the integer related to the specific signal can be found using the following link (https://sumo.dlr.de/docs/TraCI/Vehicle_Signalling.html#signaling), but is there a way of turning off a specific signal that would be otherwise turned on by the program (i.e., a setSignalOff)?
I think that there is a function in the underlying C++ code (switchOffSignal() in MSVehicle.h) but there doesn't appear to be a traci command that turns off a specific signal.
I appreciate that it is (generally) a pleasant visual aesthetic and has no impact on vehicle behaviour, but it would be very useful for what I am trying to do!
Switching off signals should work from traci. By using sometihng like traci.vehicle.setSignals("ego", 0), I can switch them off. Be aware that this will be reset after the step, so you may have to do that in every timestep.
So, Michael is right in that:
traci.vehicle.setSignals("ego", 0)
should turn off all signals (although the signals still appeared on for me visually, which confused me initially).
To turn off individual signals but keep the others on you need to:
For all the "on" signals find the value of 2^n, where n is the bit integer (which can be found using the following link: https://sumo.dlr.de/docs/TraCI/Vehicle_Signalling.html)
Sum all these 2^n values (let's call this variable x) and use this value in the setSignals function: traci.vehicle.setSignals("ego", x).
So for example, if we want the brake light, the right indicator and the high beam on (but all the other signals off) we would do:
RightIndicatorValue = pow(2,0)
BrakeLightValue = pow(2,3)
HighBeamValue = (2,6)
SignalValue = RightIndicatorValue + BrakeLightValue + HighBeamValue
traci.vehicle.setSignals(("ego", SignalValue)
There are such bindings in mc.keymap, which don't describe a meaningful shift-like key combination, but something that looks like a raw character sequence that starts with a letter, and ends with a digit, e.g.:
Top = home; alt-g; a1 # ← the sequence in question, i.e.: "a1"
Bottom = end; alt-shift-g; c1
I wonder what do they describe, i.e.: how are they triggered? What key-combination is, e.g., "c1"?
A1 is the "Home" key on the keypad (numpad 7 with Num Lock turned off), which is decoded as a different key from the regular "Home". Likewise C1 is keypad "End", C1 is keypad "Page Up", C3 is keypad "Page Down", and B2 is documented to "center of keypad", i.e. the 5 key, though I don't know whether any keyboards actually use that. They are documented for the curses library here (search for "keypad").
Other libraries tend to name these keys something like KP_HOME, KP_END, etc. but curses took a different tack of caring more about the physical layout than the key labels. Midnight commander just inherited this from (n)curses.
In any case, it should be clear now why the "Top" command would get a default binding for both "home" and "a1" — they are the two keys labeled "Home" on a common PC keyboard.
I'm trying to figure out if there's a simple way to modify several bits of an 8051 port at once.
I'll re-explain my dilemma more concrete style.
My application has Port 2 divided for two functions. Let's call them FA and FB.
FA relies on the output value of the low three bits, and FB relies on the remaining 5 bits but they can be I/O.
Because one bit in FB is an output bit that controls a clock, I don't want to modify any part of FB when I'm modifying FA and vice-versa.
The following kinds of commands won't work for me:
mov P2,#07h
mov P2,#80h
This is because such commands will overwrite the values for both functions possibly triggering one function at the wrong time.
I could get away with something like the following:
setb P2.7
setb P2.6
clr P2.5
clr P2.4
setb P2.3
setb P2.2
clr P2.1
clr P2.0
Because I know those commands can set individual bits one by one without affecting the remaining bits, but I'd like to try to set more than one bit at a time.
I read about read-modify-write and the internet tells me MOV is different from logic operations on port pins, so I'm going to try to take a guess here to see if I'm right based on my example:
Say for FB I want to output all logic highs and for FA I want to output all logic lows except that lowest bit=1. I want to operate on one function at a time.
I know this won't work since it sets everything at once:
mov P2, #0F9h
But somehow I think using logic on the ports might work, but I want to know if my thinking is correct. Let's assume in the two cases below that P2 has the value set to #0A1h via the mov command, and the pins of P2 are all connected to ground.
Is this correct?:
anl P2,#F8h ;value of P2 = #0A1h AND #F8h = #0A0h
orl P2,#F9h ;value of P2 = #0A0h OR #F9h = #0F9h
anl P2,#F0h ;value of P2 = #0F9h AND #F0h = #0F0h
Or is this more correct?:
anl P2,#F8h ;value of P2 = #00h AND #F8h = #00h
orl P2,#F9h ;value of P2 = #00h OR #F9h = #0F9h
anl P2,#F0h ;value of P2 = #00h AND #F0h = #00h
In the second example I started the equations with #00h because thats the value P2 would produce if I used MOV A,P2 and then wanted value for A, but I'm not sure if that value will be used in the anl and orl calculations.
So overall, my question is, can I use anl and orl to modify only certain bits of a port without disturbing the rest of the bits? or am I stuck with using bit manipulation commands like setb and clr?
First of all, I want to add the following aspect. The approach involving SETB and CLR instructions will require more machine cycles to execute, and might be infeasible in some cases (ie. clock generation, sync issues).
The 8051 ports are rather primitive compared to contemporary MCUs. The 'port' has a latch that stores the pin state and that latch tries to condition the output. This does not necessarily mean that the port is at desired state. For instance if it is driven low externally the latch may be high but the port will be low. This is exactly how we set a port to be an input.
When we MOVe data to a port, we write to the latch, when we MOVe from the port into a register, we read the actual state regardless of the state of the latch. Read-modify-write operations are an exception to this, as they specifically read the latch, perform desired operation and write back to the latch. Therefore the scenario given under "Is this correct?:" is the correct one.
If instead we were to MOV A, P2 and then execute anl P2,#F8h "Or is this more correct?:" would be correct.
As a result we can use logic operations to modify ports for the cases given in this question.
I'm doing a Cloud Gaming solution that works kind of "good".
At the moment our servers runs a game, encode the video using VCE (AMD hardware encoding), chunk the video frames and send it in UDP to the player. The player receives the packets, rebuid the data and decode it. So we have no problems if there is no packet loss.
In the case of a wired connexion everything is smooth, but people like to use Wifi (5ghz, we can't handle 2Ghz). Even if you have a good Wifi, you may experience packet loss. We have a redundancy plan that works "okish" but it will take too much network.
Here is a small explanation:
Original encoding (only P frames):
F1 - F2 - F3 - F4 - F5
What we do at the moment if we lose F2:
F1 - empty - F3(ugly) - F4(ugly) - F5(ugly)
What we want to do, replace F2:
F1 - F1' - F3 - F4 - F5
Would it work if the third frame refers to F1' (thinking it is F2)? At least I think it better than doing nothing. Is there a way to change the reference of F3 (so it refers to F1 and not F2), or creating F1' with the "header" of F2?
Your solution would be largely ineffective. You should adopt the same solution as the others in your space. That being periodic intra refresh, reference frame invalidation and FEC.
I am really stuck with some state based testing concepts...
I am trying to calculate some checking sequences that will cover all transitions from each state and i have the answers but i dont understand them:
alt text http://www.gam3r.co.uk/1m.jpg
Now the answers i have are :
alt text http://www.gam3r.co.uk/2m.jpg
I dont understand it at all. For example say we want to check transition a/x from s1, wouldnt we do ab only? As we are already in s1, we do a/x to test the transition to s2, then b to check we are in the previous right state(s1)? I cant understand why it is aba or even bb for s1...
Can anyone talk me through it?
Thanks
There are 2 events available in each of 4 states, giving 8 transitions, which the author has decided to test in 8 separate test sequences. Each sequence (except the S1 sequences - apparently the machine's initial state is S1) needs to drive the machine to the target state and then perform either event a or event b.
The sequences he has chosen are sufficient, in that each transition is covered. However, they are not unique, and - as you have observed - not minimal.
A more obvious choice would be:
a b
ab aa
aaa aab
ba bb
I don't understand the author's purpose in adding superfluous transitions at the end of each sequence. The system is a Mealy machine - the behaviour of the machine is uniquely determined by the current state and event. There is no memory of the path leading to the current state; therefore the author's extra transitions give no additional coverage and serve only to confuse.
You are also correct that you could cover the all transitions with a shorter set of paths through the graph. However, I would be disinclined to do that. Clarity is more important than optimization for test code.