Help! Im almost there!

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&current=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
 
'#########################################################
 

alband

Senior Member
kudos on the random 0-3 generator.
Why not just put
Code:
low     0
low     1
low     2
just before RETURN?
 

westaust55

Moderator
To save having the subroutine "Zero"

change the line:
b2 = w0 / 199 // 3 + 1​
to read
b2 = w0 / 199 // 3​
then you will have a value of 0 , 1 or 2 only


From you comment about pin 3 being an input only I assume you are using an 08M. Is that correct?
 

bobbyblank

New Member
kudos on the random 0-3 generator.
Why not just put
Code:
low     0
low     1
low     2
just before RETURN?
wow, i must have been getting tired last night haha! i thought i did drop them low before returning to the main loop. Guess i over looked that. Thanks for noticeing lol. I added it back into my code and all is working fine. i cant take credit for the generator i found it lurking in these forums somewhere, i think it was written by hippy. Thanks again for your help.

bobby
 
Last edited:
Top