-->
Page 1 of 1

For Next loop problem (I think...)

PostPosted: Fri Nov 25, 2016 7:42 pm
by robert badiduwitz
Having a problem with for next loop on an esp-01 (1 meg black pcb, 8 pins). I a simply trying to flash a neopixel connected to pin 2. When I use the x = x + 1 loop, the unit works perfectly, however when I use a for-next loop to do the same thing, it does not flash the neopixel, but it does seem to run as I get "done" after a short period of time. Any ideas would be useful. I understand that the 1 meg is a "cut down" version, but the for-next should work I think...

First version of code that works fine...

Code: Select allneo.setup(2)
x = 0
[start]
neo(0,255,0,0)
delay 200
neo(0,0,0,0)
delay 200
x = x + 1
if x = 10 then end
goto [start]


This one does not work, but seems to run (no flashing, but gets "done" after a bit...

Code: Select allneo.setup(2)
for x = 0 to 10
neo(0,255,0,0)
delay 200
neo(0,0,0,0)
delay 200
next x
end

Re: For Next loop problem (I think...)

PostPosted: Sat Nov 26, 2016 2:09 pm
by Mmiscool
It seems this is specific to the neo pixel library. I was able to make it work in a for next loop by adding a button and making it so that it exicuted the loop whe. Yhe button was pressed.

Have not figured out the conection as all the other functions seem to work. It might be some thing tied to internal arduino interupts or some thing. For now we can co firm that there is an issue here.

Re: For Next loop problem (I think...)

PostPosted: Sun Nov 27, 2016 6:39 am
by Luc Volders
Mike and Robert,

I had to try this and found a solution.
The problem is not in the delay functrion but somewhere else.

If you replace:
Code: Select allneo(0,255,0,0)


and
Code: Select allneo(0,0,0,0)


by adding the extra 0 in the command it works:

Code: Select allfor x = 0 to 10
neo(0,255,0,0,0)
delay 200
neo(0,0,0,0,0)
delay 200
next x
end


Maybe that makes your search a bit easier Mike.

Luc

Re: For Next loop problem (I think...)

PostPosted: Sun Nov 27, 2016 11:38 am
by robert badiduwitz
I can confirm that adding the extra 0 at the end works fine with the for-next loop. Weird....