My version of Magic Switchboard

voltar

New Member
Magic Switchbox-now see-through!

Hi all, I thought this might interest you, as I see some have made your own versions of this. There are several different commercially available versions of wooden magic switch-boxes, This is the only clear one, I hope you enjoy it, and it does not give you sleepless nights. Is this real magic? http://www.youtube.com/watch?v=lw9MGa7iQq4
 
Clear Magic Switchbox

Hi all, I thought this might interest you, as I see some have made your own versions of this. There are several different commercially available versions of wooden magic switch-boxes, This is the only clear one, I hope you enjoy it, and it does not give you sleepless nights. Is this real magic? http://www.youtube.com/watch?v=lw9MGa7iQq4
Hi there,
When will you be offering this device for sale? I noticed that www.voltarsmagic.co.uk is not currently active as a domain name.
You certainly have done a great job with concealing the microcircuit. Do you have a picture of the bottom of the unit? Can a spectator examine the box?
Thanks
Doug
 

cyclone411

New Member
Has anyone tried to use this circuitry to operate line voltage lamps (as in 120v)? This would not affect the programming of the PICAXE - it's a question of interfacing the outputs to some form of relay that would switch 120v. Perhaps the transistor is sufficient to do this depending on what relay is chosen. I am thinking a SSR would be the likely choice as it would require a low gate current as opposed to a mechanical relay.

Paul
 

nick12ab

Senior Member
Has anyone tried to use this circuitry to operate line voltage lamps (as in 120v)? This would not affect the programming of the PICAXE - it's a question of interfacing the outputs to some form of relay that would switch 120v. Perhaps the transistor is sufficient to do this depending on what relay is chosen. I am thinking a SSR would be the likely choice as it would require a low gate current as opposed to a mechanical relay.

Paul
A mechanical relay can be interfaced using a transistor and a back emf diode. I haven't tried using it with this yet but as the switching is code based there should be no problems.
 

hippy

Ex-Staff (retired)
Has anyone tried to use this circuitry to operate line voltage lamps (as in 120v)?
As this is a "magic trick" there are potential problems with running on mains -

1) How to maintain the faked simplicity of it being nothing more than switch and bulb

2) Swapping bulbs around which may get hot quite quickly

3) The dangers of inquisitive or careless audience members sticking their fingers in live sockets while participating in its demonstration.
 

nick12ab

Senior Member
1) How to maintain the faked simplicity of it being nothing more than switch and bulb
He could stick an inverter inside the case

2) Swapping bulbs around which may get hot quite quickly
CFLs could be used

3) The dangers of inquisitive or careless audience members sticking their fingers in live sockets while participating in its demonstration.
That can be part of the show!


...


my joke's over now, running yours on mains doesn't seem like a good idea in all seriousness.
 
Last edited:

hippy

Ex-Staff (retired)
Welcome to the PICAXE forum.

I would guess that's monitoring the actual bulbs to determine if present or not. Briefly reading as an input with a large pull-up should not cause any noticeable flicker when a bulb is on nor light the bulb when it is off.

The software can then detect which bulb has been removed first and then tell which bulb has been replaced first, then readjust the switch to bulb mapping.
 

fredgt6

New Member
Thank you Hippy for your comment ! What would be the command to detect if the bulb is present or missing?
Thanks
 

hippy

Ex-Staff (retired)
I would expect something like ...

Code:
Input C.0
bulbMissingC.0 = pinC.0
If bulbLitC.0 = 1 Then
  High C.0
Else
  Low C.0
End If
That is just generic code and would depend on the hardware and existing code used. It may not be a solution which can drop into any existing magic switchboard code.
 

Pererobert

New Member
Hello, I am novice of 72 year an I have a big problem. I built de magic switchboard like plan and program from Wayne Thomason. But Picaxe 18X is replace with a Picaxe 18M2+.
The program is loading without problem but never work ! The hardware is correct. Have somebody use a 18M2+ with this project ?
 

Bill.b

Senior Member
This code is for the 14m2. You may have to change the input and output allocation in the 'Symbol' section to suit the 18m2

Code:
#picaxe 14m2
 
' 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 Picaxe 14m2 By Bill Brown
'			    12/8/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)
 
symbol switch1 = pinc.3  ' input pin for switch 1  (pinc.0, pinc.1, pinc.2 and pinc.3)    For 18m2  - pinc.1
symbol switch2 = pinc.2  ' input pin for switch 2                                                                        pinc.0
symbol switch3 = pinc.1  ' input pin for switch 3                                                                        pinc.6
symbol switch4 = pinc.0  ' input pin for switch 4                                                                        pinc.7

symbol bulb1 = b.3       ' output for bulb 1  (b.0, b.1, b.2 and b.3)                             For 18m2  B.4
symbol bulb2 = b.2       ' output for bulb 2                                                                               b.5
symbol bulb3 = b.1       ' output for bulb 3                                                                               b.6
symbol bulb4 = b.0       ' output for bulb 4                                                                               b.7

symbol timeout = 250  ' each loop takes a little more than twice as long as original code
                      ' by "Technical (about 2ms per loop).  450 x 2ms x 10ms = about 10
                      ' seconds. Your mileage may vary - tweak timeout if needed.
                      
'Change "timeout" to smaller number when simulating or you will get bored!


symbol flags = b0  ' flags to remember whether a switch has been learnt yet
symbol flag0 = bit0
symbol flag1 = bit1
symbol flag2 = bit2
symbol flag3 = bit3
 
symbol light0 = b1 ' variable to remember which switch is which light
symbol light1 = b2
symbol light2 = b3
symbol light3 = b4
 

symbol bulb = b7
symbol starting_lite = b6 ' variable to set starting light position (and direction)
symbol position = b5  ' position counter
symbol timeout_counter = w6 ' timeout counter

if switch4=1 then audience_lockdown



starting_lite = 1
 
' Start of program
do_reset:
'                ' reset position counter       
 if starting_lite = 1 then  ' if starting with bulb 1, position reset to 0.
    position = 0 
 end if
 
 if starting_lite = 2 then  ' if starting with bulb 2, position reset to 1.
    position = 1
 end if
 
 if starting_lite = 3 then  ' if starting with bulb 3, position reset to 2.
    position = 2
 end if
 
 if starting_lite = 4 then  ' if starting wtih bulb 4, position reset to 3.
    position = 3
 end if
 
 flags = 0  ' reset flags
 
' Learning loop
waiting_to_learn_loop:
' if not learnt switch learn it
 if switch1 = 1 and flag0 = 0 then learn0
 if switch2 = 1 and flag1 = 0 then learn1
 if switch3 = 1 and flag2 = 0 then learn2
 if switch4 = 1 and flag3 = 0 then learn3
 
 ' we have learnt that switch so light output accordingly
 if flag0 = 1 then
  if switch1 = 1 then
   high light0
  else
   low light0
  end if
 end if 
 if flag1 = 1 then
  if switch2 = 1 then
   high light1
  else
   low light1
  end if
 end if 
 
 if flag2 = 1 then
  if switch3 = 1 then
   high light2
  else
   low light2
  end if
 end if 
 
 if flag3 = 1 then
  if switch4 = 1 then
   high light3
  else
   low light3
  end if
 end if
 
  if switch2=0 and switch1=0 and switch3=0 and switch4=0 then    ' count down to timeout even while in learning loop
    pause 10   'wait 10ms
    inc timeout_counter  'inc timeout
    if timeout_counter > timeout then 
       timeout_counter=0
       goto do_reset
    end if
 else
    timeout_counter=0
 end if
 
 
 goto waiting_to_learn_loop
 
' Learn a light position and set flag so we know that switch is done
learn0:
gosub bulbset
 ' position gives you the output for this switch
 flag0 = 1    ' set flag
 light0 = bulb   ' remember position for this switch
 goto learn_end
 
learn1:
gosub bulbset
 ' position gives you the output for this switch
 flag1 = 1    ' set flag
 light1 = bulb   ' remember position for this switch
 goto learn_end
 
learn2:
gosub bulbset
 ' position gives you the output for this switch
 flag2 = 1    ' set flag
 light2 = bulb   ' remember position for this switch
 goto learn_end
 
learn3:
gosub bulbset
 ' position gives you the output for this switch
 flag3 = 1    ' set flag
 light3 = bulb   ' remember position for this switch
 'goto learn_end
 
learn_end:

if starting_lite = 1 then    'if starting with 1st lamp, sequence = 1-2-3-4
   inc position
   if position > 3 then have_learnt_all
   goto waiting_to_learn_loop
end if


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
      dec position
   else
      position = 3                       'position was 0 before dec, set to "3"
   end if
   if position = 1 then have_learnt_all  'if position=1 then we have come full circle
   goto waiting_to_learn_loop            'not finished, loop and learn more switches
end if

if starting_lite = 3 then                'if starting with 3rd lamp, sequence = 3-4-1-2
   inc position
   if position > 3 then                  'if position greater greater than 4th lamp, reset to "0"
      position = 0
   end if
   if position = 2 then have_learnt_all  'if position=2 then we have come full circle
   goto waiting_to_learn_loop            'not finished, loop and learn more switches
end if

if starting_lite = 4 then                'if starting with 4th lamp, sequence = 4-3-2-1
   if position > 0 then                  'don't dec if position=0, will cause error
      dec position
   else
      goto have_learnt_all               'position is "0", we have learned last position.
   end if
   goto waiting_to_learn_loop
end if
  
 
' 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 switch1 = 1 then
  high light0
  timeout_counter = 0
 else
  low light0
 end if
 
 if switch2 = 1 then
  high light1
  timeout_counter = 0
 else
  low light1
 end if
 
 if switch3 = 1 then
  high light2
  timeout_counter = 0
 else
  low light2
 end if
 
 if switch4 = 1 then
  high light3
  timeout_counter = 0
 else
  low light3
 end if
 
 'Set which bulb will start next round. (only if switches all learned)
 if b0 = 15 and switch1=1 and switch2=0 and switch3=0 and switch4=0 then  ' if switch 1 on alone, set lamp 1 first
   starting_lite=1
 end if
 
 if b0 = 15 and switch1=0 and switch2=1 and switch3=0 and switch4=0 then  ' if switch 2 on alone, set lamp 2 first
   starting_lite=2
 end if
 
 if b0 = 15 and switch1=0 and switch2=0 and switch3=1 and switch4=0 then  ' if switch 3 on alone, set lamp 3 first
   starting_lite=3
 end if
 
 if b0 = 15 and switch1=0 and switch2=0 and switch3=0 and switch4=1 then  ' if switch 4 on alone, set lamp 4 first
   starting_lite=4
 end if
 
 pause 10   ' wait 10ms
 inc timeout_counter ' inc timeout
 
 ' if timed out then reset else loop
 if timeout_counter > timeout then do_reset
 goto have_learnt_all

bulbset:
if position=0 then 
   bulb = bulb1
end if

if position=1 then
   bulb = bulb2
end if

if position=2 then
   bulb = bulb3
end if
   
if position=3 then
   bulb = bulb4
end if
return

audience_lockdown:
  if switch1 = 1 then
   high bulb1
  else
   low bulb1
  end if

  if switch2 = 1 then
   high bulb2
  else
   low bulb2
  end if

  if switch3 = 1 then
   high bulb3
  else
   low bulb3
  end if

  if switch4 = 1 then
   high bulb4
  else
   low bulb4
  end if
goto audience_lockdown
Bill
 
Last edited:

hippy

Ex-Staff (retired)
I built de magic switchboard like plan and program from Wayne Thomason. But Picaxe 18X is replace with a Picaxe 18M2+.
The program is loading without problem but never work !
It would be worth posting your code so members can take a look at that to see if there is anything obvious which should have been changed when replacing the 18X with 18M2.

Pin identifiers changed and port B is no longer automatically output only on the 18M2. I would suspect not working issues would likely relate to those changes.
 

Pererobert

New Member
This is de initial code : No problem for loading in a Picaxe 18M2+ but nothing work (but I am a beginner !)

Code:
 Magic Switchboard - original source by "Technical" from PicAxe Forum
'                     Modified for PicAxe 18x by Wayne Thomason of Addison, TX USA
'
'                      mods: different inputs and outputs from original (easier to wire circuit)
'                            timeout functions even without learning all 4 switches
'                            starting point and sequence direction dependent on last switch turned off
'
' 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
' 3. All 4 switches must be switched on before that sequence is learned
' 4. bulbs/LEDs on outputs 7, 6, 5 & 4
' 5. switches on inputs 1, 0, 7 and 6
' 6. first pattern is left to right, bulbs 1, 2, 3, 4  (outputs 7,6,5,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)
 
symbol flags = b0  ' flags to remember whether a switch has been learnt yet
symbol flag0 = bit0
symbol flag1 = bit1
symbol flag2 = bit2
symbol flag3 = bit3
 
symbol light0 = b1 ' variable to remember which switch is which light
symbol light1 = b2
symbol light2 = b3
symbol light3 = b4
symbol starting_lite = b6 ' variable to set starting light position (and direction)
 
symbol position = b5  ' position counter
 
symbol timeout_counter = w6 ' timeout counter
symbol timeout = 500    ' timeout set to 10s = 10 000ms = 1000 x 10ms

'Change to smaller number when simulating or you will get bored!
 
starting_lite = 1

' Start of program
do_reset:
'                ' reset position counter       
 if starting_lite = 1 then  ' if starting with bulb 1, position reset to 15.
    position = 15 
 end if
 
 if starting_lite = 2 then  ' if starting with bulb 2, position reset to 14.
    position = 14
 end if
 
 if starting_lite = 3 then  ' if starting with bulb 3, position reset to 13.
    position = 13
 end if
 
 if starting_lite = 4 then  ' if starting wtih bulb 4, position reset to 12.
    position = 12
 end if
 
 flags = 0  ' reset flags
 light0=0   ' reset all lights to off.
 light1=0
 light2=0
 light3=0
 
' Learning loop
waiting_to_learn_loop:
' if not learnt switch learn it
 if pin1 = 1 and flag0 = 0 then learn0
 if pin0 = 1 and flag1 = 0 then learn1
 if pin7 = 1 and flag2 = 0 then learn2
 if pin6 = 1 and flag3 = 0 then learn3
 
 ' we have learnt that switch so light output accordingly
 if flag0 = 1 then
  if pin1 = 1 then
   high light0
  else
   low light0
  end if
 end if 
 if flag1 = 1 then
  if pin0 = 1 then
   high light1
  else
   low light1
  end if
 end if 
 
 if flag2 = 1 then
  if pin7 = 1 then
   high light2
  else
   low light2
  end if
 end if 
 
 if flag3 = 1 then
  if pin6 = 1 then
   high light3
  else
   low light3
  end if
 end if
 
 if pin0=0 and pin1=0 and pin7=0 and pin6=0 then    ' count down to timeout even while in learning loop
    pause 10   'wait 10ms
    inc timeout_counter  'inc timeout
    if timeout_counter > timeout then 
       timeout_counter=0
       goto do_reset
    end if
 else
    timeout_counter=0
 end if
 	
 goto waiting_to_learn_loop
 
' Learn a light position and set flag so we know that switch is done
learn0:
 ' position gives you the output for this switch
 flag0 = 1    ' set flag
 light0 = position   ' remember position for this switch
 goto learn_end
 
learn1:
 ' position gives you the output for this switch
 flag1 = 1    ' set flag
 light1 = position   ' remember position for this switch
 goto learn_end
 
learn2:
 ' position gives you the output for this switch
 flag2 = 1    ' set flag
 light2 = position   ' remember position for this switch
 goto learn_end
 
learn3:
 ' position gives you the output for this switch
 flag3 = 1    ' set flag
 light3 = position   ' remember position for this switch
 'goto learn_end
 
learn_end:
if starting_lite = 1 then                    ' if starting with bulb 1
   dec position                              ' subtract 1 to position counter
   if position < 12 then have_learnt_all     ' all done
end if

if starting_lite = 2 then                    ' if starting with bulb 2
   inc position                              ' add 1 to position counter
   if position > 15 then                     ' if position counter is greater than 15 
      position = 12                          ' make it 12 instead (loop around to bulb 4)
   else 
      if position = 14 then have_learnt_all  ' else if position equals 14 then all bulbs learned
   end if
end if

if starting_lite = 3 then                    ' if starting with bulb 3
   dec position                              ' subtract 1 from position counter
   if position < 12 then                     ' if position counter is less than 12
      position = 15                          ' make it 15 instead (loop around to bulb 1)
   else
      if position = 13 then have_learnt_all  ' else if position equals 13 then all bulbs learned
   end if
end if

if starting_lite = 4 then                    ' if starting with bulb 4
   inc position                              ' add 1 to position counter
   if position > 15 then have_learnt_all     ' all done
end if
  
    
 goto waiting_to_learn_loop   ' not all done so back to loop
 
' 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 pin1 = 1 then
  high light0
  timeout_counter = 0
 else
  low light0
 end if
 
 if pin0 = 1 then
  high light1
  timeout_counter = 0
 else
  low light1
 end if
 
 if pin7 = 1 then
  high light2
  timeout_counter = 0
 else
  low light2
 end if
 
 if pin6 = 1 then
  high light3
  timeout_counter = 0
 else
  low light3
 end if
 
 
 'Set which bulb will start next round. (only if switches all learned)
 if b0 = 15 and pin1=1 and pin0=0 and pin7=0 and pin6=0 then  ' if switch 1 on alone, set bulb 1 first
   starting_lite=1
 end if
 
 if b0 = 15 and pin1=0 and pin0=1 and pin7=0 and pin6=0 then  ' if switch 2 on alone, set bulb 2 first
   starting_lite=2
 end if
 
 if b0 = 15 and pin1=0 and pin0=0 and pin7=1 and pin6=0 then  ' if switch 3 on alone, set bulb 3 first
   starting_lite=3
 end if
 
 if b0 = 15 and pin1=0 and pin0=0 and pin7=0 and pin6=1 then  ' if switch 4 on alone, set bulb 4 first
   starting_lite=4
 end if
 
 pause 10   ' wait 10ms
 inc timeout_counter ' inc timeout
 
  	' if timed out then reset else loop
 if timeout_counter > timeout then do_reset
 goto have_learnt_all
 

hippy

Ex-Staff (retired)
Thanks for the code. From briefly simulating that as an 18X it seems to use some rather specific 18X tricks, such as putting values $0D through $0F in variables 'light1' through 'light4' to control output pins 4 through 7 via "HIGH light1" and similar.

I haven't analysed that fully, do not know if that is intentional, an error, or result of simulating code while being unfamiliar with how it is meant to work, but that will cause problems for an 18M2 where the values used will control different pins to what they would on the 18X.

How to resolve that would require some further effort to determine what the code is meant to be doing and figuring out how it should be doing the same but using an 18M2.

It also appear to have thrown up a minor issue with 18X simulation and simulating this code which we will need to investigate.
 
Top