The purpose of the following code is to cause a red LED to go from dim to brite and back to dim in about two seconds. At the same time, a greed LED is supposed to go from bright to dim and back to bright. In other words, while one LED is getting brighter, the other is getting dimmer, and vice versa.
Amazingly, the code is working with one minor glitch: as each LED gets to its maximum brightness, it switches off for a tiny, but discernable amount of time. I guess it probably does the same thing as it gets to its minimum brightness, but I can't see that.
Is it an arithmetic problem in my for next loops?
Thanks for your input.
BTW, this is for an RC model aircraft, so Mods, don't be alarmed.
Amazingly, the code is working with one minor glitch: as each LED gets to its maximum brightness, it switches off for a tiny, but discernable amount of time. I guess it probably does the same thing as it gets to its minimum brightness, but I can't see that.
Is it an arithmetic problem in my for next loops?
Thanks for your input.
Rich (BB code):
' Name : Aviation Nav Lights 1.pbp
' Compiler : PICBASIC PRO Compiler 3.0
' Assembler : MPASM
' Target PIC : 8-pin PIC12F675 or similar types
' Hardware : CRH Breadboard
' Oscillator : 4MHz internal
' Description :
Define OSCCAL_1K 1 ' Calibrate internal oscillator
Green Var GPIO.1 ' Green LED pin
Red var GPIO.0 ' Red LED pin
highval Var byte ' Create highval to store high start value
lowval var byte ' Create lowval to store low start value
increment var byte ' Create increment to store steps
ANSEL = %00111111 ' Set all digital
CMCON = 7 ' Analog comparators off
highval = 255
lowval = 0
mainloop:
for increment = 1 to 128
pwm green, highval, 1 ' PWMs Grn LED at highval for 1 cycle (about 5 ms.)
pwm Red, lowval, 1 ' PWMs Red LED at lowval for 1 cycle (about 5 ms.)
highval = highval - 2 ' Green LED is dimming; RED is brightening.
lowval = lowval + 2
next increment
for increment = 1 to 128
pwm Red, highval, 1 ' PWMs Red LED at highval for 1 cycle (about 5 ms.)
pwm Green, lowval, 1 ' PWMs Grn LED at lowval for 1 cycle (about 5 ms.)
lowval = lowval + 2 ' Red LED is dimming; Green is brightening.
highval = highval - 2
next increment
Goto mainloop ' Do it forever
End
Last edited: