Double Click Single Switch Code
Moderator: Benj
Double Click Single Switch Code
I have been having a great time programing our new LED timer control board. We only have one control switch, a momentary push button, and I have been successful with single press and various press and hold timing functions but cannot get the double click function to work well at all. I have done various searches but cannot find a good example for double click with a single button. Any good code examples? Thanks, Howard
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Double Click Single Switch Code
We wont be able to post anything for you until we know what version of Flowcode, target device and osc.speed + type e.g internal. external etc.
By the way I would do this is have a timer interrupt that starts timing when switch is first detected resetting count to 0.
Every time switch is detected add 1 to a count variable up to a maximum of 2. this can be done by if count <2 then count = count +1
Then when timer times out after 1 second for example, use a decision branch:
If count = 1 then single switch is detected so do something
If count = 2 then double switch is detected so do something else.
Martin
By the way I would do this is have a timer interrupt that starts timing when switch is first detected resetting count to 0.
Every time switch is detected add 1 to a count variable up to a maximum of 2. this can be done by if count <2 then count = count +1
Then when timer times out after 1 second for example, use a decision branch:
If count = 1 then single switch is detected so do something
If count = 2 then double switch is detected so do something else.
Martin
Martin
Re: Double Click Single Switch Code
Hi Martin,
Thank you for the quick reply!
Sorry for the omissions:
Version 5.1
Using standard HP-488-00-3 on board PIC 16F88. I have not changed anything from start.
How does the counter accommodate a press, release, press again, release? This seems like a hold function similar to what I have now. I must be missing something.
Thanks, Howard
Thank you for the quick reply!
Sorry for the omissions:
Version 5.1
Using standard HP-488-00-3 on board PIC 16F88. I have not changed anything from start.
How does the counter accommodate a press, release, press again, release? This seems like a hold function similar to what I have now. I must be missing something.
Thanks, Howard
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Double Click Single Switch Code
No problem, Welcome to the forum.
If you post the flowchart you have created, then I will modify it for you so you can use a switch to double or single click it.
Also can you read this please:
http://www.matrixmultimedia.com/mmforum ... =46&t=9958
This topic will be moved to V5 section soon.
You should only post your own tips in this section and not start off with a question.
The reason is if anyone is looking for a tip it makes tips easier to find.
Its not a hold function as routine is not waiting to carry on after 1st switch is detected.
Its more of a time out function.
If switch is pressed once within a second, then single switch det.
If pressed twice within a second, then double switch det.
Martin
If you post the flowchart you have created, then I will modify it for you so you can use a switch to double or single click it.
Also can you read this please:
http://www.matrixmultimedia.com/mmforum ... =46&t=9958
This topic will be moved to V5 section soon.
You should only post your own tips in this section and not start off with a question.
The reason is if anyone is looking for a tip it makes tips easier to find.
Its not a hold function as routine is not waiting to carry on after 1st switch is detected.
Its more of a time out function.
If switch is pressed once within a second, then single switch det.
If pressed twice within a second, then double switch det.
Martin
Martin
Re: Double Click Single Switch Code
Hi Martin,
Thank you very much. I am really excited about programing again though it has been decades since my Z180 assembly days. I did fill out the form in the link with regards to V5.1. Yes please move it my apologies.
In the attached code you will see a single push turns on the LED and Lasers. A push and hold for short time turns only the LED on. A push and hold for a longer time turns the LED on in low power mode.
What I would like is to single click and the LED & Lasers come on, double click the button to have only the LED come on (Similar to a double left mouse button) push and hold for 1 to 2 seconds sets the LED to low power mode.
Thanks, Howard
Thank you very much. I am really excited about programing again though it has been decades since my Z180 assembly days. I did fill out the form in the link with regards to V5.1. Yes please move it my apologies.
In the attached code you will see a single push turns on the LED and Lasers. A push and hold for short time turns only the LED on. A push and hold for a longer time turns the LED on in low power mode.
What I would like is to single click and the LED & Lasers come on, double click the button to have only the LED come on (Similar to a double left mouse button) push and hold for 1 to 2 seconds sets the LED to low power mode.
Thanks, Howard
- Attachments
-
- Flowcode 12 PWM.fcf
- (22.38 KiB) Downloaded 436 times
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Double Click Single Switch Code
Hi Howard,Collimare wrote:Hi Martin,
Thank you very much. I am really excited about programing again though it has been decades since my Z180 assembly days. I did fill out the form in the link with regards to V5.1. Yes please move it my apologies.
Programming V5 is exciting, I'm loving evey minute of it.
As for moving, It's fine for now, I was going to give it a couple of days before moving to give your registration for V5 section time to be sorted, otherwise you won't be able to post on the V5 section.
Collimare wrote:What I would like is to single click and the LED & Lasers come on, double click the button to have only the LED come on (Similar to a double left mouse button) push and hold for 1 to 2 seconds sets the LED to low power mode.
I will post that for you, but may not be until tomorrow, as time is running out for staying up tonight.
Martin
Martin
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Double Click Single Switch Code
Hi Howard,
Do you need two switches as in your descriptions you describe using one switch, yet on your flowchart you have two switches.
If you only require one switch, is there a pin this switch must be connected to?
If necessary, is it OK to use RB0 or RB7 for connection of the switch?
I'm only asking in case I need to use port B0 INT or RB4 to RB7 interrupt on change (IOC)
Martin
Do you need two switches as in your descriptions you describe using one switch, yet on your flowchart you have two switches.
If you only require one switch, is there a pin this switch must be connected to?
If necessary, is it OK to use RB0 or RB7 for connection of the switch?
I'm only asking in case I need to use port B0 INT or RB4 to RB7 interrupt on change (IOC)
Martin
Martin
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Double Click Single Switch Code
Hi Howard,
I thought I would post a non interrupt version for you to have a play with.
It should be easier than an interrupt version to follow.
I have implemented single press, double press and long press all with just a single switch.
I have mapped key 0 to the switch, so whether your single stepping or running simulator, switch is activated all the time key 0 is held down.
Or you can just push switch with mouse as usual of course.
Not tried with hardware, will do that later.
Hope it what your after and have fun playing.
Martin
I thought I would post a non interrupt version for you to have a play with.
It should be easier than an interrupt version to follow.
I have implemented single press, double press and long press all with just a single switch.
I have mapped key 0 to the switch, so whether your single stepping or running simulator, switch is activated all the time key 0 is held down.
Or you can just push switch with mouse as usual of course.
Not tried with hardware, will do that later.
Hope it what your after and have fun playing.
Martin
- Attachments
-
- Flowcode 12 PWM Non INT.fcf
- (18.92 KiB) Downloaded 449 times
Martin
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Double Click Single Switch Code
Now you are registered as a V5 user, I have moved this topic to the V5 forum as it is more relevant.
Martin
Martin
Martin
Re: Double Click Single Switch Code
Hi Martin,
Thank you very much. The laser only switch is not standard, but a special add on for some customers. Normally there is just the one switch. I am very open to the interrupt version if it is better. I have not committed anything to hardware yet just using the demo board for now.
I will start playing with your non-interrupt version.
Thanks again, Howard
Thank you very much. The laser only switch is not standard, but a special add on for some customers. Normally there is just the one switch. I am very open to the interrupt version if it is better. I have not committed anything to hardware yet just using the demo board for now.
I will start playing with your non-interrupt version.
Thanks again, Howard
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Double Click Single Switch Code
Hi Howard,
If I get a chance a bit later I will see what I can sort out with interrupt version.
I have just tried on hardware the not interrupt version and it works very well indeed.
Seems 100% reliable
Hopefully you will agree, but you never know.
You may have a different opinion?
Martin
If I get a chance a bit later I will see what I can sort out with interrupt version.
I have just tried on hardware the not interrupt version and it works very well indeed.
Seems 100% reliable
Hopefully you will agree, but you never know.
You may have a different opinion?
Martin
Martin
Re: Double Click Single Switch Code
Hi Martin,
I have incorporated your double click design and it is working well as is. No need for interrupts. Note: The the loop time is 15 for the hardware and 75 for the simulator.
Thank you very much for your time and efforts.
Have a great weekend.
Cheers, Howard
I have incorporated your double click design and it is working well as is. No need for interrupts. Note: The the loop time is 15 for the hardware and 75 for the simulator.
Thank you very much for your time and efforts.
Have a great weekend.
Cheers, Howard
- Attachments
-
- Flowcode 14 PWM double click works.fcf
- (24.62 KiB) Downloaded 433 times
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Double Click Single Switch Code
Hi Howard,
Thanks & Your welcome.
I did not realise that you required active low. So if i/p is +5V then switch is not pressed.
I need to look in at the switch macro, as I was not happy with the way it simulated. I think there was a post about this, I will check it out.
So I have changed the Flowchart to work as active low both in simulator and hardware
I have just incorporated the laser + switch so that each time switch is pressed:
1) If laser is not running and PWM is >0 then PWM = 0 and laser will go on.
2) If laser is running and PWM is >0 then PWM goes to 0 and laser stays on
3) If PWM is not running, then laser will toggle. E.g if laser is on, it will go off. If laser is off it will go on etc.
Hope you like modification.
There should be no need to have different values for simulation and hardware. Should work well in both.
You have a good weekend to.
Martin
Edit:
The thing that is puzzling me is:
So try both Flowcharts and see which one works for your application.
Thanks & Your welcome.
I did not realise that you required active low. So if i/p is +5V then switch is not pressed.
I need to look in at the switch macro, as I was not happy with the way it simulated. I think there was a post about this, I will check it out.
So I have changed the Flowchart to work as active low both in simulator and hardware
I have just incorporated the laser + switch so that each time switch is pressed:
1) If laser is not running and PWM is >0 then PWM = 0 and laser will go on.
2) If laser is running and PWM is >0 then PWM goes to 0 and laser stays on
3) If PWM is not running, then laser will toggle. E.g if laser is on, it will go off. If laser is off it will go on etc.
Hope you like modification.
There should be no need to have different values for simulation and hardware. Should work well in both.
You have a good weekend to.
Martin
Edit:
The thing that is puzzling me is:
Looking at the circuit, that is active high and not active low. So pressing a switch will cause the voltage on the pin to go from 0V to +5V (well nearly!)Collimare wrote: Using standard HP-488-00-3 on board PIC 16F88. I have not changed anything from start.
So try both Flowcharts and see which one works for your application.
- Attachments
-
- Flowcode 12 PWM Non INT Active High.fcf
- (23.07 KiB) Downloaded 369 times
-
- Flowcode 12 PWM Non INT Active Low.fcf
- (23.07 KiB) Downloaded 330 times
Martin
Re: Double Click Single Switch Code
Hi Martin,
Thank you very much for your continued help. It looks like the active high version matches the simulator and hardware and this is great. You have simplified the program nicely, but pressing the main button after the LED and Lasers or LED in the on state should turn them back off and it does not appear to. It does appear that the LED only switch is working correctly. If the LED only switch has turned the LED on then pressing the main button should turn it back off as well. Then the main switch program should be back in the normal monitor mode. Hope this makes sense?
This is as far as I have gotten.
Warm regards, Howard
Thank you very much for your continued help. It looks like the active high version matches the simulator and hardware and this is great. You have simplified the program nicely, but pressing the main button after the LED and Lasers or LED in the on state should turn them back off and it does not appear to. It does appear that the LED only switch is working correctly. If the LED only switch has turned the LED on then pressing the main button should turn it back off as well. Then the main switch program should be back in the normal monitor mode. Hope this makes sense?
This is as far as I have gotten.
Warm regards, Howard
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Double Click Single Switch Code
Hi Howard,
But that could be just my misinterpretation, so sorry if that was not right.
Try this one, I have changed it so every time you keep pressing Main switch once, the laser and LED are toggled.
Except for: If only laser is on then pressing main switch will only shut laser off since pwm is already off.
Martin
Correct as that's what I thought you wanted?Collimare wrote: but pressing the main button after the LED and Lasers or LED in the on state should turn them back off and it does not appear to
But that could be just my misinterpretation, so sorry if that was not right.
Try this one, I have changed it so every time you keep pressing Main switch once, the laser and LED are toggled.
Except for: If only laser is on then pressing main switch will only shut laser off since pwm is already off.
Martin
- Attachments
-
- Flowcode 12 PWM Non INT Active High Rev2.fcf
- (23.54 KiB) Downloaded 349 times
Martin
Re: Double Click Single Switch Code
Hi Martin,
This is great. I will play with it for awhile.
Warm regards, Howard
This is great. I will play with it for awhile.
Warm regards, Howard