Automatic Switch Toggling

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Automatic Switch Toggling

Postby medelec35 » Tue Jan 24, 2012 1:29 am

I have developed a way to automatically toggle any switch in Flowcode simulator, which can toggle an i/p very rapidly without you toggling the switches yourself!
This is just like like a Clock generator which I believe is long overdue .
Clock generator or Automatic Switch toggling works by using a third parties software called AutoHotkey.
AutoHotkey can be programmed to control any key with any key presses.

First download AutoHotkey from:
http://www.autohotkey.com/download/
I downloaded Installer for AutoHotkey Basic (1.95 MB)

Please note this software is freeware and appears to be genuine with a support forum. I have used it on a couple of PC's with no issues whatsoever. I have even scanned with Microsoft Security Essentials with nothing found. But as with all software downloaded from the internet, it's at your own risk.
After downloaded and installed you don't need to save sample scrip when prompted since you will be using the attached script (.ahk extension) I developed just for the Automatic Switch toggling.

Save Flowcode Toggle Keys.ahk to any folder on your PC.when saved you can double click file to run AutoHotkey software. When running there will be a green square Icon with a White H in the tray or your PC.
HotKeys1.png
HotKeys1.png (4.37 KiB) Viewed 1662 times


Now load the flowchart that's also contained within the attached zip file.
I have set up the flowchart with key mapping which I have explained about here:
viewtopic.php?f=31&t=7873&p=21219#p21219

With the Key mapping set up, you press key 5 to toggle switch thats it's mapped to.
key mapping1.png
key mapping1.png (62.47 KiB) Viewed 1660 times

Every time that key 5 is pressed then since the switch is assigned to port B5 interrupt-on -change, number on LCD is incremented by one.
Now for the automation part.
I have set up AutoHotkeys so if click run on Flowcode then hold Ctrl and Alt and press number 5 on the top row of keyboard, then the number 5 will be rapidly repeated.
To stop 5 from being constantly activated then press Space bar.

Note: it is not advisable to click on any text input box after you have activated the repeating key or you will just see 555555555555555555555555 going across the input box or text editor. You will need to press space bar to stop repeat function first.
You can also stop the the script by right clicking on AutoHotkeys icon that's in the windows task bar.

Here is what the script looks like I have created for AutoHotkeys:
Code: Select all
;Auto Toggle Switches

;By Medelec35



^!$0::  ; Make the Ctrl Alt 0 key into a hotkey (the $ symbol facilitates the "P" mode of GetKeyState below).
sleep 100
Loop  ; Since no number is specified with it, this is an infinite loop unless "break" or "return" is encountered

inside.
{
    if GetKeyState("space", "P")  ; If this statement is true, the user has just pressed the space bar to stop.
        break  ; Break out of the loop.
    ; Otherwise (since the above didn't "break"), keep sending 0
    send 0  ;
sleep 60 ; time in ms between activation key 1
}
sleep 100
return


^!$1:: 
sleep 100
Loop 
{
    if GetKeyState("space", "P") 
        break 
    send 1 
sleep 60
}
sleep 100
return


^!$2:: 
sleep 100
Loop 
{
    if GetKeyState("space", "P") 
        break 
    send 2 
sleep 60
}
sleep 100
return

^!$3:: 
sleep 100
Loop 
{
    if GetKeyState("space", "P") 
        break 
    send 3 
sleep 60
}
sleep 100
return

^!$4:: 
sleep 100
Loop 
{
    if GetKeyState("space", "P") 
        break 
    send 4 
sleep 60
}
sleep 100
return

^!$5:: 
sleep 200
Loop 
{
    if GetKeyState("space", "P") 
        break 
    send 5 
sleep 60
}
sleep 100
return

^!$6:: 
sleep 100
Loop 
{
    if GetKeyState("space", "P") 
        break 
    send 6 
sleep 60
}
sleep 100
return

^!$7:: 
sleep 100
Loop 
{
    if GetKeyState("space", "P") 
        break 
    send 7 
sleep 60
}
sleep 100
return

^!$8:: 
sleep 100
Loop 
{
    if GetKeyState("space", "P") 
        break 
    send 8 
sleep 60
}
sleep 100
return

^!$9:: 
sleep 100
Loop 
{
    if GetKeyState("space", "P") 
        break 
    send 9 
sleep 60
}
sleep 100
return


I have set the script to work with numbers 0 to 9 (in conjunction with Ctrl and Alt)

As a test I started the switch toggling and number on LCD went from 0 to 300 in 23 seconds.
Bearing in mind that count is increment only when key 5 is pressed and released.
The script can be altered to go even faster if required.

Have fun and don't forget you use the space bar to stop key 5 being repeat pressed.

Hope I have giving enough information as it took me a little while to work out the script, and its late for me.

Martin
Attachments
Flowcode Toggle Keys.zip
(2.89 KiB) Downloaded 169 times
If you're hardware is not working as expected, try looking here first:
viewtopic.php?f=26&t=6936

If you find any posts that are useful, please click on the 'thumbs up' icon next to Quote button on that post.

For this message the author medelec35 has received thanks: 3
Benj(Tue Jan 24, 2012 12:43 pm), ncc1502(Sun Apr 22, 2012 6:21 pm), Steve(Wed Jan 25, 2012 9:13 am)
Rating:18.75%
 
User avatar
medelec35
Valued Contributor
Valued Contributor
 
Posts: 5312
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire
Has thanked: 1408 times
Have thanks: 1654 times

Advertisement

Re: Automatic Switch Toggling

Postby echase » Wed Jan 25, 2012 3:41 pm

I have never understood Key mapping and not found the Help button enlightening on this point. But if I understand your description a keymap is linking a PC keyboard key to an action in Flowcode. If so what is the “Element” entry in your picture and why do both SWITCH(0) and SWITCH(1) have zero for Element?
echase
Flowcode v5 User
 
Posts: 405
Joined: Mon Jun 11, 2007 11:55 am
Has thanked: 46 times
Have thanks: 0 time

Re: Automatic Switch Toggling

Postby medelec35 » Wed Jan 25, 2012 4:19 pm

echase wrote:But if I understand your description a keymap is linking a PC keyboard key to an action in Flowcode.


I agree with that statement.
If I have got it correct, then the switch only has 1 element since it's either activated or not and only requires 1 Key to operate. You could think of an element as number of keys less 1( so with 1 key, element = 1-1 =0) mapped to it. So any component that contains a on/off action e.g switch keypad etc. will always have 0 for element.
A pot will have 2 elements ( 0 = counter clockwise & 1 = clockwise) since there are two keys mapped to it. One key for clockwise and another key for counter clockwise.
The number on the left is the keyboard number that's mapped to component.
So if you have 5 for switch(0) then pressing 5 will activate switch(0) just select element 0

Hope I have helped.

Martin
If you're hardware is not working as expected, try looking here first:
viewtopic.php?f=26&t=6936

If you find any posts that are useful, please click on the 'thumbs up' icon next to Quote button on that post.
User avatar
medelec35
Valued Contributor
Valued Contributor
 
Posts: 5312
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire
Has thanked: 1408 times
Have thanks: 1654 times


Return to Programming Tips & Tricks

Who is online

Users browsing this forum: No registered users and 1 guest