declare a variable for the throttle state, tState.
when you detect throttle forward set tState = 1 // forward
when you detect throttle backward
{
if tState >= 2 then tState = 3 // backup
else tState = 2; // brake
}
Some good suggestions above but, be aware that (each of) the GetPulse routine(s) could wait 20mS before returning. It may be simpler to have the variable LED fed by two pins and use two resistors and only switch 1 pin to output at any time.
The code I provided only samples when the loop counter is zero, there are 99 loop iterations between each sample. It could be changed to sample the streering at 0, the throttle at 33, and the brake at 66 sort of thing. Maybe he was using same input for throttle and brake, no matter. By sizing the per iteration delay and number of iterations one can get a lot of flexiablity in the spacing between samples.
I am not against using interrups but agree on not using them here.
Some good suggestions above but, be aware that (each of) the GetPulse routine(s) could wait 20mS before returning. It may be simpler to have the variable LED fed by two pins and use two resistors and only switch 1 pin to output at any time.
Hmm after I saw these posts I just realize that later I might reprogram my LEDs flashing modes.
I wonder if I can do a lot of different pulse while:
1. 1/4 forward
2. 1/2 forward
3. full forward
4. brake
5. reverse
6. left
7. right
There are like seven (7) modes that I can play here, I wonder each of them could be programmed nicely like having no delays or lag at all when lighting these leds.
This is kinda interesting, lol because this is my hobby and i love to learn when it is my hobby too. Nice huh.
Hmm after I saw these posts I just realize that later I might reprogram my LEDs flashing modes.
I wonder if I can do a lot of different pulse while:
1. 1/4 forward
2. 1/2 forward
3. full forward
4. brake
5. reverse
6. left
7. right
There are like seven (7) modes that I can play here, I wonder each of them could be programmed nicely like having no delays or lag at all when lighting these leds.
This is kinda interesting, lol because this is my hobby and i love to learn when it is my hobby too. Nice huh.
Hi, I don't know why but the led is turned off all the time. Do I have changed LATB to 0b11000000;
setting RB6 and RB7 as input port. I have put 1k and 330 Ohms resistor, it doesnt light up. I changed to smaller resistor, also doesnt light up. What happened actually?
I pulled down to 0 to light it up, but nothing happened. Weird...
Hi, I don't know why but the led is turned off all the time. Do I have changed LATB to 0b11000000;
setting RB6 and RB7 as input port. I have put 1k and 330 Ohms resistor, it doesnt light up. I changed to smaller resistor, also doesnt light up. What happened actually?
I pulled down to 0 to light it up, but nothing happened. Weird...
Did you set TRISB as needed?
VDD is connected to the annode + side of the LED. When TRISB =11XXXXXX
both RB6 and RB7 are inputs and the led is off. To use the path through RB7 set TRISB=01XXXXXX and LATB=0XXXXXXX. To use the path throubh RB6 use TRISB=10XXXXXX and LATB =X0XXXXXX. Where X is a don't care.
This will not work with a debugger because RB6 and RB7 are used for ICD (In Circuit Debug). What are you using for a programmer ?
it is weird, it doesnt work. I used 47 Ohms and 220 Ohms low value resistor, but it doesnt work. I connected as 3v0 drawed yesterday. The positive 5V connected to LED+ and the minus parallel to two resistors ended at RB6 and RB7.
you are correct, I was jumping to this PIC Programming cold water without bringing any swimming specs or even wearing the swimming shorts!!
By making one of pin Low, and the other side (anode) is VDD, it means there is potential difference and the current flows. And making the pin low is by setting the Tris to 0?? or LAT to 0?? Which is which, what are these basic meanings?