No problem, I'm just here to offer some advice, not to crack the whip.piesoup:
I haven’t forgotten Mac, unfortunately work is getting the way of my hobbies!
The latter is your wife’s job ! :mrgreen:
No problem, I'm just here to offer some advice, not to crack the whip.piesoup:
I haven’t forgotten Mac, unfortunately work is getting the way of my hobbies!
The latter is your wife’s job ! :mrgreen:
Haha! You know it!
I’m back! Spent the weekend wrestling with my 3D printer, now that’s that’s sorted! I sat down and had a go at this. I hope this makes it clearer. I certainly like the State Machine way of thinking.
The device will be a FSM with 3 states, Climb, Trail and Descend. The device is fitted to a Fox shock on a mountain bike, and a servo moves a lever on the shock to select the different compression rates.
After reset or power-up, the FSM will be initialized to the trail state. Independent of the present state the device will monitor one dpdt latching rocker switch (on-off-on), which in turn will control the transition from one state to the next. The switch has three positions, 1, 2 and 3.
A press on the switch, into position 1 (on), the device transitions from trail to climb. Blue LED turns on. Red and green LEDs turn off.
A press on the switch, into position 2 (off), the device transitions from climb to trail. Green LED turns on, blue and red LEDs turn off.
A press on the switch, into position 3 (on), the device transitions from trail to descend. Red LED turns on, blue and green LEDs turn off.
No other transitions are allowed. The software will also provide some form of debouncing for the switches.
Independent of the present state, the software monitors the battery voltage via an analog input to it’s A/D converter. Also independent of the present state the device will provide a blink timing function for an LED. The LED that blinks, is dependant on which state the machine is in. Climb, blue LED blinks. Trail, green LED blinks and Descend, red LED blinks.
Independent of the present state, the code will use the monitored battery voltage to set the blink rate. When above a threshold of 7.2 volts the blinking will be disabled. When between 7.2 and 6.8 volts the blink rate will be set to {2} Hz.
Lastly when the battery voltage is less the 6.8 volts the blink rate will be set to {4} Hz. The servo will be commanded to the {trail} position. The {trail} LED will be activated and blink at 4 Hz. No further selection will be possible until battery voltage is above 6.8 volts again.
When in the climbing state the code will use the monitored battery voltage and if above a threshold, disable the blinking function. It will command a servo to the {climbing} position (45°) and activate the {climbing} LED.
When in the trail state the code will use the monitored battery voltage and if above a threshold, disable the blinking function. It will command a servo to the {trail} position (90°) and activate the {trail} LED.
When in the descending state the code will use the monitored battery voltage and if above a threshold, disable the blinking function. It will command a servo to the {descend} position (135°) and activate the {descend} LED.
As I’ve written there, is how it stands at the moment. In a much more jumbled state!
There one thing I want to implement though. Either now or in the future.
Replace the rocker switch with one momentary push button switch. I can then have a smaller profile on the handle bars.
FSM starts in Trail, a click on the button (~0.1 sec) cycles between Trail and Climb states. Independent of the selected position, a press (~2 sec) transitions into Descend. A further click transitions into Climb mode. Further clicks cycle between Trail and Climb states.
LEDs and battery monitoring as above.
I hope I have made it clear to read. Cheers!
OK, that’s good … and different … from how I had thought it all was supposed to work. Which is why I ‘whipped you’ into that direction. So now let me think about it but given the prior posts I think you can come up with (at least) some pseudo-code to implement that functionality. And then code that follows from that.
Hi Mac
Sorry for the huge period of absence. Work has been getting in the way of my hobbies!
I’m looking at using a single push button so the need to write my code in FSM is very necessary now. Best get reading. Do you have any links that are a good place to start?
Just so you know I really appreciate your help so far and I hadn’t just disappeared!