For...........Next

The bear

Senior Member
Hi Everyone,
What I'm trying to do, with For ..next, is to switch on a light for approx. 3 mins.
Then the succeeding For ..next, switch off the light for a long period, approx. 2hours.
The program times have been reduced, for testing the code.
What is happening, the light (LED) is flashing on & off with the counter, I need it to stay on
until the counter has finished. Works fine in the simulator 6.0.7.3
Regards, Bear..
Code:
	#Picaxe 14M2 ;08M2		
	#No_data
	LET dirsC =0000111
	let dirsB =0011111
		
SYMBOL SWITCH_ER = C.2
SYMBOL SEN_SOR = C.4
SYMBOL ADC_VAL = b0
SYMBOL  COUNTER = b1

MAIN:
	ReadADC C.4, ADC_VAL
	if ADC_VAL > 80 then gosub STAND_BY
	PAUSE 500
	if ADC_VAL < 80 then gosub LIGHT_ON
GOTO MAIN

LIGHT_ON:
				
	FOR COUNTER = 1 TO 3
		HIGH SWITCH_ER		;LIGHT ON short period
		PAUSE 1000			;60000 x 3 = 3min
	NEXT COUNTER

		
	FOR COUNTER =  1 TO 5		 ;60000 x 120 = 2hrs
		LOW  SWITCH_ER			;LIGHT OFF long period				
		PAUSE 1000 			;60000 = 1min
	NEXT COUNTER
RETURN

STAND_BY:
	PAUSE 1000
RETURN
 
Last edited:

nick12ab

Senior Member
Those let dirsC/B statements don't have the % before the binary digits, which could well cause problems if this isn't your complete program.

Why set a symbol for the ADC pin and not use it?
 

The bear

Senior Member
@ nick12ab,
Thank you. Symbol was a slip-up, as was the % signs. It is the complete program at this stage.
If or when it's working, I would like to add some more "For..nexts". 14M2 in use, out of 08M2's.
 

nick12ab

Senior Member
@ nick12ab,
Thank you. Symbol was a slip-up, as was the % signs. It is the complete program at this stage.
If or when it's working, I would like to add some more "For..nexts". 14M2 in use, out of 08M2's.
By flashing on and off with the counter, do you mean that it turns on after 60 seconds then turns off again after 60 seconds, and that it speeds up if you reduce the pause intervals to less than 60000?
 

The bear

Senior Member
@ nick12ab,
It's flashing every second, more than the three counts, it just keeps on flashing. Nothing happens if the LDR is exposed to light, its got that bit!
 

nick12ab

Senior Member
@ nick12ab,
It's flashing every second, more than the three counts, it just keeps on flashing. Nothing happens if the LDR is exposed to light, its got that bit!
Do you have decoupling capacitors fitted, and does the problem persist if the binary numbers are corrected (% added)?
 

The bear

Senior Member
Do you have decoupling capacitors fitted, and does the problem persist if the binary numbers are corrected (% added)?
Capacitors fitted, good power supply, running @ 4 volts. Symbol & %'s sorted, re programmed and still the same. Its not urgent, appreciate your help.
 

lbenson

Senior Member
You might try putting a sertxd statement before main to make sure that the picaxe isn't resetting: sertxd("starting",cr,lf)

This is surely not causing your particular problem, but you might want to include in your tests the condition when ADC_VAL = 80.
 

premelec

Senior Member
The value 80 is not in the selection process - make it equal to 80 either on the > or < conditions... [i.e. >= 80 or <=80]
 

The bear

Senior Member
Thanks Everyone,
My test values were too small, (1000mS). Increasing them to 10000 gives it time to perform. (As Tex would say).
 

lbenson

Senior Member
Thanks Everyone,
My test values were too small, (1000mS). Increasing them to 10000 gives it time to perform. (As Tex would say).
Glad it's working, but I don't understand what you're saying in the context of the program you posted (which appears to me to work fine in simulation).
 

The bear

Senior Member
Glad it's working, but I don't understand what you're saying in the context of the program you posted (which appears to me to work fine in simulation).
@lbenson,
It worked fine in the simulator, but not in real life. I had the simulator on the slowest speed, (And my brain too).
 
Top