I think this is more accurate of the entire dev process here.
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.
Only one at a time. While you fade one, the rest just sit there.the code in post#108 will fade in and out multiple leds. No they are not included in post#108. With some rearanging it will fade in and out multiple leds at different rates if desired
{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2022 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 5/25/2022 *
* Version : 1.0 *
* Notes : *
* : *
*****************************************************************************
}
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 m As Byte
Dim w As Byte
Dim x As Byte
Dim y As Byte
Dim z As Byte
Dim Counter As LongWord
Dim LED1On As LongWord
Dim LED1Off As LongWord
Dim led1 As PORTA.0
Dim led2 As PORTB.0
Dim led3 As PORTC.0
Dim led4 As PORTD.0
Dim I As Byte
Dim led1offcount As Byte
Dim led1oncount As Byte
Dim led2oncount As Byte
Dim led2offcount As Byte
Dim led3oncount As Byte
Dim led3offcount As Byte
Dim led4offcount As Byte
Dim led4oncount As Byte
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
//turn off the leds
led1offcount = 0
led1oncount = 0
led2offcount = 0
led2oncount = 0
led3oncount = 0
led3offcount = 0
led4oncount = 0
led4offcount = 0
I = 0
I = Counter
//set the variabls Led1on and Led1off to zero
LED1Off = 0
Counter = 0
While 1 = 1
// some code will go here
If led2oncount = I
Then //first pass led1 = 0
led2 = ledon // led1 is on
led2oncount = I +900
led2offcount = I + 100
End If
If led2offcount = I
Then
led2 = ledoff
EndIf
If led3oncount = I
Then
led3 = led0n
led3oncount = I + 1900
led3offcount = I + 25
End If
If led3offcount = I
Then
led3 = ledoff
End If
If led4oncount = I
Then
led4 = ledon
led4offcount = I + 100
led4offcount = I + 100000
End If
If led4offcount = I
Then
led4 = ledoff
End If
Inc (I)
DelayUS(20)
Wend
Not with the code from post #108 they don't. It fades them one at a time.no I have 14 leds and they ALL DIM OR GO BRIGHT together
Boots Randolph would turn in his grave...I think this is more accurate of the entire dev process here.
Sub Fade()
Bright_1 = 1 // bright_1 is ON time variable
Dimmer_1 = 5000 //dimmer_1 is OFF time variable
Repeat
PORTA = %11001111
PORTB = %00000111
PORTC = %00010001
PORTD = %10001110
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 = %11001111
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
here is the completed SUB for multiple leds to fade from dim to full brightness
// bright is initial ON time
// dimmer is initial OFF time
// stop is end value (loop until bright = stop)
// A, B, C, and D are port values
Sub Fade(bright as word, dimmer as word, stop as word, A as byte, B as byte, C as byte, D as byte)
dim dir as boolean
// figure out direction and account for 'repeat-until' end
if (bright < dimmer) then
dir = true // increase ON time
stop = stop + 1
else
dir = false // increase OFF time
stop = stop - 1
endif
repeat
PORTA = A // ON time
PORTB = B
PORTC = C
PORTD = D
delayus(bright)
PORTA = 0 // OFF time
PORTB = 0
PORTC = 0
PORTD = 0
delayus(dimmer)
if (dir) then
bright = bright + 1 // increase ON time
dimmer = dimmer - 1 // decrease OFF time
else
bright = bright - 1 // decrease ON time
dimmer = dimmer + 1 // increase OFF time
endif
until (bright = stop)
end sub
main:
while (true)
// fade brightness up
Fade(1, 5000, 3000, %11001111, %00000111, %00010001, %10001110)
// fade brightness down
Fade(5000, 1, 1, %11001111, %00000111, %00010001, %10001110)
end while
{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2022 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 5/31/2022 *
* Version : 1.0 *
* Notes : *
* : *
*****************************************************************************
}
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_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 bright As Word
Dim dimmer As Word
Dim stop As Word
Dim A As Byte
Dim B As Byte
Dim C As Byte
Dim D As Byte
Dim dir As Boolean
Sub Fade1()
// figure out direction and account for 'repeat-until' end
If (bright < dimmer) Then
dir = true // increase ON time
stop = stop + 1
Else
dir = false // increase OFF time
stop = stop - 1
EndIf
Repeat
PORTA = A // ON time
PORTB = B
PORTC = C
PORTD = D
DelayUS(bright)
PORTA = 0 // OFF time
PORTB = 0
PORTC = 0
PORTD = 0
DelayUS(dimmer)
If (dir) Then
bright = bright + 1 // increase ON time
dimmer = dimmer - 1 // decrease OFF time
Else
bright = bright - 1 // decrease ON time
dimmer = dimmer + 1 // increase OFF time
EndIf
Until (bright = stop)
End Sub
main:
// init hdw
// LED port - all outputs 2 LEDs per port in parallel 330 ohm resistor
TRISA = 0
TRISB = 0
TRISC = 0
TRISD = 0
TRISE = 0
PORTE=%000
PORTD=%00000000
PORTC=%00000000
PORTA=%00000000
PORTB=%00000000
// bright is initial ON time
// dimmer is initial OFF time
// stop is end value (loop until bright = stop)
// A, B, C, and D are port values
'main:
While (true)
// fade brightness up
Fade1(1, 5000, 3000, %11001111, %00000111, %00010001, %10001110)
// fade brightness down
Fade2(5000, 1, 1, %11001111, %00000111, %00010001, %10001110)
End While