Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : MM Magic Switchboard
Author | Message | ||||
Bill.b Senior Member Joined: 25/06/2011 Location: AustraliaPosts: 226 |
Hi all is is a project I built using a PICAXE 18M2 so I though I would convert the code into MMbasic and try is out on my Maximite. for those who donot know what a magic switchboar is, have a look at this on utube www.youtube.com/watch?v=0lGP8nQLANU this picture is of my PICAXE version. I will follow uo with a schematic soon. ' Magic Switchboard - original source by "Technical" from PicAxe Forum ' Modified for PicAxe 18x by Wayne Thomason of Addison, TX USA ' 7/15/2009 ' Modified for Maximite MMBasic by Bill Brown bill.b ' 19/01/2012 ' ' mods: 1. Now is easily configurable via switch? and bulb? variables ' 2. "timeout" functions even without learning all 4 switches ' 3. starting point and sequence direction dependent on last switch turned off ' 4. Now has Audience_lockdown feature. If power is turned on while switch-4 ' is set, each light will respond only to corresponding switch position ' until circuit is reset. ' ' Assumptions ' 1. Times out after 10 seconds of all switches in the off position ' regardless of whether all switches are learned yet ' 2. All switches must be off at start ' (If switch 4 on when started, it starts up in audience-mode.) ' 3. All 4 switches must be switched on before that sequence is learned ' 4. Set bulb/LED outputs using bulb1, bulb2, bulb3 & bulb4 ' 5. Set switch inputs using switch1, switch2, switch3 and switch4 ' 6. first pattern is left to right, bulbs 1, 2, 3, 4 ' 7. subsequent patterns are determined by last SWITCH turned off: ' Switch 1 = 1234 order (bulb 1 first, then right in sequence) ' Switch 2 = 2143 order (bulb 2 first, then left in sequence, wrapping after first) ' Switch 3 = 3412 order (bulb 3 first, then right in sequence, wrapping after last) ' Switch 4 = 4321 order (bulb 4 first, then left in sequence) timeout = 750 'loop reset time approx 10 seconds timeout_counter = 0 SetPin 11,2 SetPin 12,2 SetPin 13,2 SetPin 14,2 SetPin 15,8 SetPin 16,8 SetPin 17,8 SetPin 18,8 Pin(15) = 0:Pin(16)=0:Pin(17)=0:Pin(18)=0 If Pin(14) = 1 Then GoTo Audience_Lockdown starting_lite = 1 ' Start of program do_reset: ' reset position counter If starting_lite = 1 Then position = 0 ' if starting with bulb 1, position reset to 0. EndIf If starting_lite = 2 Then position = 1 ' if starting with bulb 2, position reset to 1. EndIf If starting_lite = 3 Then position = 2 ' if starting with bulb 3, position reset to 2. EndIf If starting_lite = 4 Then position = 3 ' if starting with bulb 4, position reset to 3. EndIf flag0 = 0 : flag1 = 0 :flag2 = 0:flag3 = 0 ' Learning loop waiting_to_learn_loop: If (Pin(11) = 1) And (flag0 = 0) Then GoTo learn0 If (Pin(12) = 1) And (flag1 = 0) Then GoTo learn1 If (Pin(13) = 1) And (flag2 = 0) Then GoTo learn2 If (Pin(14) = 1) And (flag3 = 0) Then GoTo learn3 ' we have learnt that switch so light output accordingly If flag0 = 1 Then If Pin(11) = 1 Then Pin(light0) = 1 Else Pin(light0) = 0 EndIf EndIf If flag1 = 1 Then If Pin(12) = 1 Then Pin(light1) = 1 Else Pin(light1) = 0 EndIf EndIf If flag2 = 1 Then If Pin(13) = 1 Then Pin(light2) = 1 Else Pin(light2) = 0 EndIf EndIf If flag3 = 1 Then If Pin(14) = 1 Then Pin(light3) = 1 Else Pin(light3) = 0 EndIf EndIf If (Pin(11) = 0) And (Pin(12) = 0) And (Pin(13) = 0) And (Pin(14) = 0) Then Pause 10 timeout_counter = timeout_counter + 1 If timeout_counter > timeout Then timeout_counter = 0 GoTo do_reset EndIf Else timeout_counter = 0 EndIf GoTo waiting_to_learn_loop ' Learn a light position and set flag so we know that switch is done learn0: GoSub bulbset flag0 = 1 light0 = bulb GoTo learn_end learn1: GoSub bulbset flag1 = 1 light1 = bulb GoTo learn_end learn2: GoSub bulbset flag2 = 1 light2 = bulb GoTo learn_end learn3: GoSub bulbset flag3 = 1 light3 = bulb GoTo learn_end learn_end: If starting_lite = 1 Then 'if starting with 1st lamp, sequence = 1-2-3-4 position = position + 1 If position > 3 Then GoTo have_learnt_all GoTo waiting_to_learn_loop EndIf If starting_lite = 2 Then 'if starting with 2nd lamp, sequence = 2-1-4-3 If position > 0 Then 'don't dec if position=0, will cause error position = position - 1 Else position = 3 EndIf If position = 1 Then GoTo have_learnt_all GoTo waiting_to_learn_loop EndIf If starting_lite = 3 Then 'if starting with 3rd lamp, sequence = 3-4-1-2 position = position + 1 If position > 3 Then position = 0 EndIf If position = 2 Then GoTo have_learnt_all GoTo waiting_to_learn_loop EndIf If starting_lite = 4 Then 'if starting with 4th lamp, sequence = 4-3-2-1 If position > 0 Then position = position - 1 Else GoTo have_learnt_all EndIf GoTo waiting_to_learn_loop EndIf ' now simply loop reacting to the switches ' timeout_counter value will increment every 10ms ' however if any light is on the timeout_counter is reset ' so this means the timeout will only ' occur after 10 secoonds of all switches off have_learnt_all: If Pin(11) = 1 Then Pin(light0) = 1 timeout_counter = 0 Else Pin(light0) = 0 EndIf If Pin(12) = 1 Then Pin(light1) = 1 timeout_counter = 0 Else Pin(light1) = 0 EndIf If Pin(13) = 1 Then Pin(light2) = 1 timeout_counter = 0 Else Pin(light2) = 0 EndIf If Pin(14) = 1 Then Pin(light3) = 1 timeout_counter = 0 Else Pin(light3) = 0 EndIf If (flag0=1) And (flag1=1) And (flag2=1) And (flag3=1) Then all_flags = 1 EndIf If (all_flags=1) And (Pin(11)=1) And (Pin(12)=0) And (Pin(13)=0) And Pin(14)=0) Then starting_lite = 1 EndIf If (all_flags=1) And (Pin(11)=0) And (Pin(12)=1) And (Pin(13)=0) And Pin(14)=0) Then starting_lite = 2 EndIf If (all_flags=1) And (Pin(11)=0) And (Pin(12)=0) And (Pin(13)=1) And Pin(14)=0) Then starting_lite = 3 EndIf If (all_flags=1) And (Pin(11)=0) And (Pin(12)=0) And (Pin(13)=0) And Pin(14)=1) Then starting_lite = 4 EndIf Rem Print starting_lite;all_flags Pause 10 timeout_counter = timeout_counter + 1 If timeout_counter > timeout Then GoTo do_reset GoTo have_learnt_all bulbset: If position = 0 Then bulb = 15 EndIf If position = 1 Then bulb = 16 EndIf If position = 2 Then bulb = 17 EndIf If position = 3 Then bulb = 18 EndIf Rem Print position;bulb Return audience_lockdown: If Pin(11) = 1 Then Pin(15) = 1 Else Pin(15) = 0 EndIf If Pin(12) = 1 Then Pin(16) = 1 Else Pin(16) = 0 EndIf If Pin(13) = 1 Then Pin(17) = 1 Else Pin(17) = 0 EndIf If Pin(14) = 1 Then Pin(18) = 1 Else Pin(18) = 0 EndIf GoTo audience_lockdown In the interests of the environment, this post has been constructed entirely from recycled electrons. |
||||
Bill.b Senior Member Joined: 25/06/2011 Location: AustraliaPosts: 226 |
Schematic for the Magic Switchboard In the interests of the environment, this post has been constructed entirely from recycled electrons. |
||||
Bill.b Senior Member Joined: 25/06/2011 Location: AustraliaPosts: 226 |
sorry wrong schematic in previous post this is the correct schematic for the Maximite In the interests of the environment, this post has been constructed entirely from recycled electrons. |
||||
Gizmo Admin Group Joined: 05/06/2004 Location: AustraliaPosts: 5078 |
Well I watched the video and I was stumped! How did it work? Then I had a look at your software Bill, and I worked it out Brilliant project. Glenn The best time to plant a tree was twenty years ago, the second best time is right now. JAQ |
||||
Vikingboy Regular Member Joined: 23/09/2011 Location: AustraliaPosts: 82 |
Hi, I have only had a quick read through the code, but isn't there a missing subroutine "bulbset" it is referenced in 'learn 0' etc and it dosn't appear anywhere in your code ? Andrew |
||||
CircuitGizmos Guru Joined: 08/09/2011 Location: United StatesPosts: 1425 |
It is the 2nd to the last subroutine. bulbset: If position = 0 Then bulb = 15 EndIf If position = 1 Then bulb = 16 EndIf If position = 2 Then bulb = 17 EndIf If position = 3 Then bulb = 18 EndIf Rem Print position;bulb Return Micromites and Maximites! - Beginning Maximite |
||||
Vikingboy Regular Member Joined: 23/09/2011 Location: AustraliaPosts: 82 |
Just looked closer, it seems the code you have posted is truncated, at least here ? these are the last lines I see: xxxxxSNIPxxxxx WOW ! how strange. I was just about to cut and paste to show the last lines I can see in my window here, I can only see the first half of the 'learn_end' subroutine, when I copied and then pasted those lines, lo and behold, all the rest of the code appeared including the missing subroutines etc, very strange, don't know what was happening there, anyone else see this ? Andrew |
||||
Vikingboy Regular Member Joined: 23/09/2011 Location: AustraliaPosts: 82 |
Hi, A very cool trick :) , I see you use a more complicated program than that used on the ones demonstrated on you-tube, even the simple version shown in the you tube link is very convincing until you know the method, but while looking around I saw this version of the trick : you tube I can only guess that either it is being controlled by someone off stage or it has some sensors which detect the position of the discs in this case ??? Andrew |
||||
ArtBecker Regular Member Joined: 25/08/2011 Location: PhilippinesPosts: 47 |
"WOW ! how strange." Using Firefox beta 10 I only see about 75% of the code in the box. Doing a select all and copying to a programming text editor (NotePad2) gives me all the code, but the last 20% is all jumbled together. Using Internet Explorer 9, all the code displays properly in the window, and can be copied to a text editor, with the formatting intact. Using Chrome 15 I also get the complete code in the box, and can copy it to a text editor with no problem. |
||||
Gizmo Admin Group Joined: 05/06/2004 Location: AustraliaPosts: 5078 |
It seams the latest version of Firefox has a few bugs, I've had a few comments similar to this. The forum software is formatting the page correctly, so there is nothing I can change to fix the problem, its just a Firefox bug. Glenn The best time to plant a tree was twenty years ago, the second best time is right now. JAQ |
||||
Gizmo Admin Group Joined: 05/06/2004 Location: AustraliaPosts: 5078 |
I've made a change to the forum software to make Firefox render the code text correctly. Basically, I've broken the HTML code. But it seams to work OK with Firefox. Glenn The best time to plant a tree was twenty years ago, the second best time is right now. JAQ |
||||
Vikingboy Regular Member Joined: 23/09/2011 Location: AustraliaPosts: 82 |
very strange, yes It now looks fine, I haven't noticed it before even looking at longer quotes. Thanks for the fix. FYI I am not using the latest firefox I am a couple versions behind as I had some trouble with later versions ,so it is maybe a more basic Firefox incompatibility. Andrew |
||||
Bill.b Senior Member Joined: 25/06/2011 Location: AustraliaPosts: 226 |
If any one is interested in the PICAXE code for then Magic Switchboard, let me know and I will post the code. In the interests of the environment, this post has been constructed entirely from recycled electrons. |
||||
shoebuckle Senior Member Joined: 21/01/2012 Location: AustraliaPosts: 189 |
Bill's Magic Switchboard program and schematic will be included in the next version of the Maximite User Program library, which should be uploaded soon. Cheers, Hugh |
||||
Print this page |