bobbyblank
New Member
I have been getting some help in the forums and they have all been pretty much relateing to one project. I am trying to randomly PWM 3 LEDs hooked up to pins 0, 1, 2, off and on. With some help, i have gotten it almost hammered out. Its randomly chooseing a pin and then running a PWM on it but the LED never totaly goes out. it stays on very faintly and moves to the next pin. eventually, all three pins are very faintly on. Not the look im going for haha. I have included my code and a video of the leds. They look much brighter in the video, they are faint in the circut. Still, not what im going for though lol. Any help would be very much appreciated.
bobby
http://s170.photobucket.com/albums/u261/bobbyblank/?action=view¤t=MVI_0807.flv
bobby
http://s170.photobucket.com/albums/u261/bobbyblank/?action=view¤t=MVI_0807.flv
Code:
'#########################################################
'Setup routine
setup:
dirs=%00010111
'#########################################################
'#########################################################
'Main loop code
main:
DO 'Choose a number between 0-3 and put value in b2
RANDOM w0
b2 = w0 / 199 // 3 + 1 'b2 will be used as a pin to PWM and fade the LED connected to the pin
LOOP UNTIL b2 <> b3
b3 = b2
IF b2 = 3 THEN 'If random number is 3, run sub routine
GOSUB zero
END IF
FOR b4=1 to 254 STEP 1
SERVO b2,b4
PAUSE 10
NEXT b4
FOR b4=254 to 1 STEP -1
SERVO b2,b4
PAUSE 10
NEXT b4
b2 = 0
pause 500
GOTO main
'#########################################################
zero: 'Change b2 to zero because pin3 is an input and
'cant be used to PWM an LED, so it is changed
b2 = 0 'to pin0
RETURN
'#########################################################