' Name : LED_flasher_13.BAS ' Author : Christopher Good ' Notice : Copyright (c) 2018 ' : All Rights Reserved ' Date : 25 Oct 2018 ' Version : 1.0 ' Notes : Free source code. Compile with Proton IDE Lite (also free). Program your PIC with IC-Prog (also free). ' ' Pin8 = Ground - tie to common, connect to pin 1 via .1MF cap ' Pin7 = GPIO.0 - i/o - control bank 1 of LEDs, connect to base of NPN transistor via 2.2k ohm resistor ' Pin6 = GPIO.1 - i/o - control bank 2 of LEDs, connect to base of NPN transistor via 2.2k ohm resistor ' Pin5 = GPIO.2 - i/o - control bank 3 of LEDs - left / right wing center (two LEDs) ' Pin4 = GPIO.3 - input only - RC PWM signal - tie to RC signal via 4.7k ohm resistor ' Pin3 = GPIO.4 - i/o - RC PWM signal - tie to RC signal via 4.7k owm resistor ' Pin2 = GPIO.5 - i/o - control bank 4 of LEDs, connect to base of NPN transistor via 2.2k ohm resistor ' Pin1 = Vcc - tie to +5v, connect to pin 8 via .1MF cap Device 12C508 Config INTRC_OSC, MCLRE_OFF, WDT_OFF, CP_OFF ' set config fuses OPTION_REG.5 = 0 ' clock source internal Dim Pulselen As Byte ' Pulselen can be 0 - 255, 100 = 1 ms, 200 = 2 ms Dim DelayTime As Word ' DelayTime can be 75 - 225 ms Dim Mask as byte TRISIO = %00011000 ' input on gpio.3 and gpio.4 ReadPWM: Pulselen = PulsIn GPIO.3, High ' pin 4 - read high pulse length for light pattern selection DelayTime = Pulsin GPIO.4, High ' pin 3 - read high pulse length for delaytime If Pulselen < 75 or pulselen > 225 then pulselen = 105 ' outside of bounds, set to blink selection if DelayTime < 75 or DelayTime > 225 then Delaytime = 150 ' outside of bounds, set to middle value mask = %00000000 If Pulselen < 112 Then GPIO = mask ' all off if pulselen > 96 and pulselen < 112 then delayms delaytime ' delay for blink if pulselen > 111 and pulselen < 127 then gosub cw ' all flash in circle, one light on if pulselen > 126 and pulselen < 157 then gosub ccw ' all flash in circle the other way, one light on if pulselen > 141 and pulselen < 157 then gosub Bridge ' back and forth, one light on mask = %00100111 if pulselen > 156 and pulselen < 172 then gosub cw ' all flash in circle, one light off if pulselen > 171 and pulselen < 202 then gosub ccw ' all flash in circle the other way, one light off if pulselen > 186 and pulselen < 202 then gosub bridge ' back and forth, one light off if pulselen > 96 and pulselen < 112 then gpio = mask ' all on if pulselen > 201 then GPIO = mask ' all on delayms delaytime GoTo ReadPWM ' if mask = 00000000, then XOR ^ will give the same output - one LED on at a time ' if mask = 00100111, then XOR ^ will give the inverted output - one LED off at a time CW: ' 1 2 3 4 GPIO = %00000001 ^ mask Delayms delaytime GPIo = %00000010 ^ mask delayms delaytime GPIo = %00000100 ^ mask delayms delaytime gpio = %00100000 ^ mask return CCW: ' 4 3 2 1 GPIO = %00100000 ^ mask Delayms delaytime GPIo = %00000100 ^ mask delayms delaytime GPIo = %00000010 ^ mask delayms delaytime gpio = %00000001 ^ mask return Bridge: ' 4 3 2 1 - 2 3 - 4 3 2 1 - 2 3 ... used to bridge CCW pattern for back and forth Delayms Delaytime GPIo = %00000010 ^ mask Delayms Delaytime GPIO = %00000100 ^ mask Return