problem with switch (14M2)

rob53

New Member
Hey guys, for some reason one of my switches isn't working in this program. I've checked and double checked my connections on the breadboard and everything is hooked up correctly, but I'm not getting any response from the switch on pin B.1, the switch on pin C.3 is working just fine. I even tried swapping them to make sure the problem wasn't in the switch itself. The problem has to be in the code. Is there something special I need to do to make pin B.1 an input? Can someone tell me what I'm doing wrong?

Code:
#Picaxe 14M2 Voyager Model Torpedo Effects 

Symbol switchA = pinC.3
Symbol switchB = pinB.1

Symbol buttonA = b0
Symbol ButtonB = b1
Symbol pwmA    = w1
Symbol pwmB    = w2

; ====== Button Handler ===================

Start0:
  Do
    If switchA = 1 Then : Resume 1 : End If
    If switchB = 1 Then : Resume 2 : End If
    Pause 50
  Loop
  
  ; ====== Front Torpedoes ==========================

Start1:
  Do
    Suspend 1
    buttonA = buttonA + 1
    Select Case buttonA
      Case 1
        PwmOut PWMDIV4, C.0, 99, 0
        For pwmA = 0 To 400
          PwmDuty C.0, pwmA
          Pause 2
        Next
        High C.1
        Pause 100
        Low C.1
        For pwmA = 400 To 0 Step -1
          PwmDuty C.0, pwmA
          Pause 2
        Next
        PwmDuty C.0, 0
      Case 2
        PwmOut PWMDIV4, C.2, 99, 0
        For pwmA = 0 To 400
          PwmDuty C.2, pwmA
          Pause 2
        Next pwmA
        High C.4
        Pause 100
        Low C.4
        For pwmA = 400 To 0 Step -1
          PwmDuty C.2, pwmA
          Pause 2
        Next
        PwmDuty C.2, 0
        buttonA = 0
    End Select
  Loop
  
  ; ====== Rear Torpedoes ==========================

Start2:
  Do
    Suspend 2
    buttonB = buttonB + 1
    Select Case buttonB
      Case 1
        PwmOut PWMDIV4, B.2, 99, 0
        For pwmB = 0 To 400
          PwmDuty B.2, pwmB
          Pause 2
        Next
        High B.3
        Pause 100
        Low B.3
        For pwmB = 400 To 0 Step -1
          PwmDuty B.2, pwmB
          Pause 2
        Next
        PwmDuty B.2, 0
      Case 2
        PwmOut PWMDIV4, B.4, 99, 0
        For pwmB = 0 To 400
          PwmDuty B.4, pwmB
          Pause 2
        Next pwmB
        High B.5
        Pause 100
        Low B.5
        For pwmB = 400 To 0 Step -1
          PwmDuty B.4, pwmB
          Pause 2
        Next
        PwmDuty B.4, 0
        buttonB = 0
    End Select
  Loop
 

rob53

New Member
Aw crap, nevermind guys. I figured it out. I took out the second Word Variable and just used w1 on all of the pwms and it started working.
 

hippy

Technical Support
Staff member
I figured it out. I took out the second Word Variable and just used w1 on all of the pwms and it started working.
Are you sure it is working or just appears to be working, only for it to not do what is expected in some circumstance ?

I cannot see why it wouldn't work unchanged so that might be worthy of some investigation.
 
Top