B4R Question Proper way to do this loop - ESP-12E (ESP2866)

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I am trying to control a RGB strip light.

Turns LEDs to Red, Waits then White, then waits, then Blue, waits then ALL off then does it again quickly

This code works fine, problem is when I am in this code I miss ANY push buttons (I would have thought that a push it would cause an interrupt and just to the AddListener routine but it seems to miss these pushes when in this loop

Is there a way to Delay and give up control so that if a push button happens I get that interrupt and my AddListener routine gets call?

When I am not in this loop I get the push button interrupts just fine.

B4X:
Private  Sub Patriot           Dim LongDelay       As Int    = 1000

           Dim DelayTimes()   As Int    = Array As Int(LongDelay, 250)   
           
           
           For Each DelayTime As Int In DelayTimes           
               RPin.AnalogWrite(255)
               GPin.AnalogWrite(0)
               BPin.AnalogWrite(0)
               Delay(DelayTime)
               
               RPin.AnalogWrite(255)
               GPin.AnalogWrite(255)
               BPin.AnalogWrite(255)
               Delay(DelayTime)
               
               RPin.AnalogWrite(0)
               GPin.AnalogWrite(0)
               BPin.AnalogWrite(255)               
               Delay(DelayTime)

               RPin.AnalogWrite(0)
               GPin.AnalogWrite(0)
               BPin.AnalogWrite(0)
               Delay(DelayTime)               
           Next
           
           Delay(LongDelay * 3)
End Sub
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Thanks, yes timers are the way to go.

Wish there was a way of calling Code Module routine from a main.

Just kicking around - but this works - again just learning here
 

Attachments

  • LEDStrip.zip
    4.8 KB · Views: 312
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
B4X:
Wish there was a way of calling Code Module routine from a main.
Use a code module or even a class, as you would with any b4x platform
 
Upvote 0
Top