Barber Pole Lamp Controller Picaxe Basic Program

Declarations and Data

#rem 4-Light-transmitterPole.bas

New version to control the Barber Pole Lamp

John Saunders 4/26/2022

#endrem

#PICAXE 08M2


'Ports

symbol TX_Data_Port     = C.0        'Idle low serial transmission at 2400 baud

symbol Sw_2             = pinC.1    'Switch BCD bit 2

symbol Sw_1             = pinC.3    'Switch BCD bit 1

symbol Sw_0             = pinC.4    'Switch BCD bit 1  

symbol PWM_Port         = C.2        'Keeps the power flowing, charges the gate with a 10 KHz square wave


'Variables

symbol swPos             = b1        'The value of the code for switch position

symbol index        = b2        'For loop counter

symbol dataAddr        = b3        'Addree of string to be transmitted

symbol char            = b4


'Constants

symbol TX_Interval    = 500      'Time between transmissions

symbol TX_Times        = 2        'The number of transmissions before shutoff

symbol TX_Preamble      = 20        'A long pulse before the serial transmission to trigger an interrupt

symbol TX_Ser_Setup     = 10        'Gives time to execute the serial in command in the interrupt procedure


'Transmitted character

DATA  0,("40,00,F4")

DATA  8,("41,00,40")

DATA 16,("19,1E,40")

DATA 24,("42,00,40")

DATA 32,("12,16,9A")

DATA 40,("45,00,9A")

DATA 48,("10,13,D9")

DATA 56,("46,00,D9")

 Init and Main

Init:

SETFREQ m4

PWMOUT  PWM_Port,100,200        'Time to start up = 30 ms, freq = 10 KHz 

LET swPos = 2*Sw_1 + Sw_0

LET swPos = 4*Sw_2 +swPos

LET bptr = 100

FOR index = 0 TO 7

    LET dataAddr = 8 * swPos + index

    READ dataAddr, char

    LET @bptrinc = char

NEXT


main:

FOR Index = 1 TO TX_Times

    LET bptr = 100

    HIGH TX_Data_Port            'This pulse unlocks the receiver

    PAUSE TX_Preamble

    LOW TX_Data_Port

    PAUSE TX_Ser_Setup

    SEROUT TX_Data_Port,N2400_4,("82&me<",@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptr,">",13,10)        'The CR,LF is for debugging

    PAUSE TX_Interval

NEXT

LOW TX_Data_Port

PWMOUT PWM_Port,OFF

PAUSE 300

END