Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
and separate data lines for the different colored Leds
}
'Program: CHRISTMAS STAR:
Device = 18F43K22
Clock = 8
// int osc and IO pin libraries
Include "intosc.bas"
#option DIGITALIO_INIT = true // automatically call setalldigital
Include "setdigitalio.bas"
// hardware
Dim INDEX As LongWord //4294967295
Dim Counter As Word
Dim Counter_up As Word
Dim Counter_down As Word
Dim m As Byte
Dim w As Byte
Dim x As Byte
Dim y As Byte
Dim z As Byte
Dim bright As Word
Dim dimmer As Word
Dim Bright_1 As LongWord // a wider range of settings FOR A SMOOTHER TRANSITION
Dim Dimmer_1 As LongWord
Dim Bright_2 As LongWord // a wider range of settings
Dim Dimmer_2 As LongWord
Dim SUB_COUNT As LongWord
Const BLUE_A(16)As Byte= (%00000000,
%00000000,
%00100000, //
%00010000, //
%00000000,
%00000000,
%00000000,
%00000000, //xxxxxxxxxxxx2
%00000000,
%00000000,
%00100000, //
%00010000, //
%00000000,
%00000000,
%00000000,
%00000000)
Const BLUE_B(16)As Byte= (%10000000, //
%01000000, //
%00100000, //
%00010000, //
%00001000, //
%00000000,
%00000000,
%00000000, //xxxxxxxxxxx5
%10000000, //
%01000000, //
%00100000, //
%00010000, //
%00001000, //
%00000000,
%00000000,
%00000000)
Const BLUE_C(16) As Byte= (%10000000, //
%01000000, //
%00100000, //
%00000000,
%00001000, //
%00000100, //
%00000010, //
%00000000, //xxxxxxxxxxxxxxxxxxxx6
%10000000, //
%01000000, //
%00100000, //
%00000000,
%00001000, //
%00000100, //
%00000010, //
%00000000)
Const BLUE_D(16) As Byte= (%10000000,
%01000000,//
%00100000, //
%00010000, //
%00000000,
%00000000,
%00000000,
%00000001, // xxxxxxxxxx5
%10000000,
%01000000,//
%00100000, //
%00010000, //
%00000000,
%00000000,
%00000000,
%00000001) //
Const WHITE_A(8)As Byte= (%10000000,
%01000000,
%00000000,
%00010000,
%00001000,
%00000100,
%00000010,
%00000001)
Const WHITE_B(8)As Byte= (%00000000,
%00000000,
%00000000,
%00000000,
%00000000,
%00000100,
%00000010,
%00000001)
Const WHITE_C(8) As Byte= (%00000000,
%00000000,
%00000000,
%00010000,
%00000000,
%00000000,
%00000000,
%00000001)
Const WHITE_D(8) As Byte= (%10000000,
%00000000,
%00000000,
%00000000,
%00001000,
%00000100,
%00000010,
%00000000)
Const BLUE_E(16)As Byte = (%00000100,
%00000010,
%00000001, //3
%00000000,
%00000000,
%00000100,
%00000010,
%00000001,
%00000100,
%00000010,
%00000001,
%00000000,
%00000000,
%00000100,
%00000010,
%00000001)
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Const WHITE_Af(1)As Byte=(%11100111)
//-------------------------------------
//PATTERN SUBROUTES
Sub FLICKER_1()
INDEX = 1
Repeat
For x = 0 To 7 //WHITE
For z = 0 To 7 //BLUE
PORTA = WHITE_A(x)
DelayMS(1000)
PORTA = BLUE_A(z)
DelayUS(50)
PORTB = WHITE_B(x)
DelayMS(1000)
PORTB = BLUE_B(z)
DelayUS(50)
PORTC = WHITE_C(x)
DelayMS(1000)
PORTC = BLUE_C(z)
DelayUS(50)
PORTD = WHITE_D(x)
DelayMS(1000)
PORTD = BLUE_D(z)
DelayUS(50)
PORTE = BLUE_E(z)
DelayUS(50)
INDEX = (INDEX + 1)
Next
Next
Until INDEX >= 10000
End Sub
Sub FLICKER_2()
INDEX =1
Counter_down = 1
Repeat
For x = 0 To 7
For z = 0 To 16 //all the blue leds
PORTA = WHITE_A(x)
DelayUS(Counter_down)
PORTA = BLUE_A(z)
DelayUS(25)
PORTB = WHITE_B(x)
DelayUS(Counter_down)
PORTB = BLUE_B(z)
DelayUS(25)
PORTC = WHITE_C(x)
DelayUS(Counter_down)
PORTC = BLUE_C(z)
DelayUS(25)
PORTD = WHITE_D(x)
DelayUS(Counter_down)
PORTD = BLUE_D(z)
DelayUS(25)
PORTE = BLUE_E(z)
DelayUS(10)
INDEX = (INDEX + 1)
Counter_down = (Counter_down + 1) //dimming effect
Next
Next
If Counter_down >= 2000
Then
Counter_down = 1 //reset counter_down back to 1
End If
Until INDEX >= 10000
End Sub
Sub FLICKER_3() //gradual dim to bright
INDEX = 1
Counter = 5
Repeat
For x = 0 To 7
For z = 0 To 7
PORTA = WHITE_A(x)
DelayUS(Counter)
PORTA = BLUE_A(z)
DelayUS(50)
PORTB = WHITE_B(x)
DelayUS(Counter)
PORTB = BLUE_B(z)
DelayUS(50)
PORTC = WHITE_C(x)
DelayUS(Counter)
PORTC = BLUE_C(z)
DelayUS(50)
PORTD = WHITE_D(x)
DelayUS(Counter)
PORTD = BLUE_D(z)
DelayUS(50)
PORTE = BLUE_E(z)
DelayUS(50)
INDEX = (INDEX + 1)
Next
Next
Counter = (Counter +1)
Until INDEX >= 10000
End Sub
//zzzzzzzzzzzzzzzzzzzzzzzzzz
Sub All_off()
PORTE=%000
PORTD=%00000000
PORTC=%00000000
PORTA=%00000000
PORTB=%00000000
End Sub
//zzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Sub Fade()
bright = 5000
dimmer = 1
Bright_1 = 1 // bright_1 is ON time variable
Dimmer_1 = 5000 //dimmer_1 is OFF time variable
Repeat
PORTA = %11011111
PORTB = %00000111
PORTC = %00010001
PORTD = %10001110
PORTE = %000
DelayUS(Bright_1)
PORTA = %00000000
PORTB = %00000000
PORTC = %00000000
PORTD = %00000000
// DIMMING
DelayUS (Dimmer_1)
Bright_1 = (Bright_1 +1) // increase ON time BY 1
Dimmer_1 = (Dimmer_1 - 1) //decrease OFF time BY 1
Until
Bright_1 >= 3000 //HIGH BRIGHT
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//reset values
Bright_2 = 5000
Dimmer_2 = 1
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Repeat
PORTA = %11011111
PORTB = %00000111
PORTC = %00010001
PORTD = %10001110
DelayUS(Bright_1)
PORTA = %00000000
PORTB = %00000000
PORTC = %00000000
PORTD = %00000000
DelayUS(Dimmer_2) // full dim FIRST PASS IN LOOP
Bright_2 = (Bright_2 - 1)
Dimmer_2 = (Dimmer_2 + 1)
Until
Bright_2 = 1
//reset valuesxxxxxxxxxxxxxx
Bright_2 = 1
Dimmer_2 = 5000
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
End Sub
//zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
//-------------------------------------
// start of main program
//-------------------------------------
main:
// init hdw
// LED port - all outputs 2 LEDs per port in parallel 330 ohm resistor
TRISA = 0 // SET ALL PORTS AS OUTPUTS
TRISB = 0
TRISC = 0
TRISD = 0
TRISE = 0
PORTE=%000 //TURN OFF ALL PORTS
PORTD=%00000000
PORTC=%00000000
PORTA=%00000000
PORTB=%00000000
Bright_1 = 0
Dimmer_1 = 0
Bright_2 = 0
Dimmer_2 = 0
setalldigital
While true
Fade() //ADD A COUNTER TO MAKE IT LONGER
FLICKER_1()
All_off() // indicates sequence change
DelayMS(50)
FLICKER_2()
All_off() // indicates sequence change
DelayMS(50)
FLICKER_3()
Wend
{
All_off() // indicates sequence change
DelayMS(50)
Wend
{
While TRUE
bright_1 = 1 // bright_1 is ON time variable
dimmer_1 = 5000 //dimmer_1 is OFF time variable
repeat
led1 = 1 //ON
delayus(bright_1) //AMOUNT OF TIME ON
led1 = 0 // OFF
delayus (dimmer_1) //AMOUNT OF TIME OFF
bright_1 = (bright_1 +1) // increase ON time BY 1
dimmer_1 = (dimmer_1 - 1) //decrease OFF time BY 1
until
bright_1 >= 5000 //HIGH BRIGHT
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//reset values
bright_2 = 5000
dimmer_2 = 1
LED2 = 1 // LED2 COMES ON WHEN LED1 STARTS FROM HIGH BRIGHT TO FULL DIM
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
repeat
led1 = 1 //ON TIME
delayus(BRIGHT_2) // LED is full brightness FIRST PASS IN LOOP
led1 = 0 //OFF TIME
delayus(DIMMER_2) // full dim FIRST PASS IN LOOP
bright_2 = (bright_2 - 1)
dimmer_2 = (dimmer_2 + 1)
until
bright_2 = 1 // FULL DIM
//reset valuesxxxxxxxxxxxxxx
bright_2 = 1 //RESET VARIABLES
dimmer_2 = 5000
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
wend
void LoadClock(int _Data){
for (int Bit = 0; Bit < 8; Bit++){
digitalWrite(Data,bitRead(_Data,Bit));
digitalWrite(ShiftClock,HIGH);
digitalWrite(ShiftClock,LOW);
}
digitalWrite(RegClock,HIGH);
digitalWrite(RegClock,LOW);
}
If I have RED and GREEN LEDs on the perimeter chasing around the tree I need one data source
RED LEDs = 10101010
GREEN LEDs = 01010101
Device = 18F43K22
Clock = 8
// int osc and IO pin libraries
Include "intosc.bas"
#option DIGITALIO_INIT = true // automatically call setalldigital
Include "setdigitalio.bas"
Include "SHIFT.BAS"
Dim Clk As PORTB.3
Dim w-DATA As PORTA.1
Dim r-DATA As PORTA.4
Dim LATCH As PORTB.4
Dim RESET As PORTB.1
Dim Leds As Byte
Output (Clk)
Output (w-DATA)
Output (r-DATA)
Output (LATCH)
Output (Leds)
Leds = 0
update (shiftreister)
DelayMS(500)
update (shiftreister)
LATCH = 0
shiftout (DATA, Clock,lsbfirst, Leds)
LATCH = 1