' Name : LED_flasher_12.BAS ' Author : Christopher Good ' Notice : Copyright (c) 2018 ' : All Rights Reserved ' Date : 12 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 0 of LEDs - left wing tip ' Pin6 = GPIO.1 - i/o - control bank 1 of LEDs - left wing middle ' Pin5 = GPIO.2 - i/o - control bank 2 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 - control bank 3 of LEDs - right wing middle ' Pin2 = GPIO.5 - i/o - control bank 4 of LEDs - right wing tip ' Pin1 = Vcc - tie to +5v, connect to pin 8 via .1MF cap ' all off (< 1.05 ms) ' all on (> 1.95 ms) ' all blink (1.05 - 1.50 ms) - variable rate ' alternating blink (1.51 - 1.95 ms) back and forth like NightRider ' made of super bright LEDs (5 banks) on flying wings 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 50 - 320 ms Clear ' set all variables = 0 TRISIO = %00001000 ReadPWM: Pulselen = PulsIn GPIO.3, High ' pin 4 - read high pulse length, times out after .65535 seconds If Pulselen < 75 or pulselen > 225 then pulselen = 150 If Pulselen < 151 Then GPIO = %00000000 ' all off If Pulselen > 104 And Pulselen <151 Then DelayTime = ((Pulselen - 105) * 6) + 50 ' 50 + (0 to 45)*6 = 50 to 320 ms Delayms Delaytime GPIO = %00110111 EndIf If Pulselen > 150 And Pulselen < 196 Then DelayTime = ((195 - Pulselen) * 6) + 50 ' 50 + (0 to 45)*6 = 50 to 320 ms GPIO = %00000001 DelayMS DelayTime GPIO = %00000010 DelayMS DelayTime GPIO = %00000100 DelayMS DelayTime GPIO = %00010000 DelayMS DelayTime GPIO = %00100000 DelayMS DelayTime GPIO = %00010000 DelayMS DelayTime GPIO = %00000100 DelayMS DelayTime GPIO = %00000010 EndIf if pulselen > 195 then gpio = %00110111 Delayms Delaytime GoTo ReadPWM