Help with Virtual button

hello am trying to use the virtual button
to turn the LED strip on and off
and its working good but when I turn it on its just cycling one time
I know that it should be in the void loop but am trying to do it and no luck
can any one help me with that where to place so it run continues

this is the code

// This #include statement was automatically added by the Particle IDE.
#include "SparkCorePolledTimer/SparkCorePolledTimer.h" //that should be include for the virtual PIN to work in the app

// This #include statement was automatically added by the Particle IDE.
#include "blynk/blynk.h"
#include "application.h"

char auth[] = "xxxxx";

//const int led1 = D7;

#define VODKA D0 //inergize relay for PLC input (vodka shot)
#define WHYSKI D1 //inergize relay for PLC input (whyski on rock)
#define CADILLAC D2 //inergize relay for PLC input (cadillac margerita)
#define LONG_ISLAND D3 //inergize relay for PLC input (strowbery long island)
#define PUMP6_PIN D4 //
#define PUMP7_PIN D5
#define PUMP6_PIN D6
#define PUMP6_PIN D7

#define ON 255   // to run the void on 
#define OFF 0    // to run the void off

#define CLOCK A5
#define DATA A3 

SparkCorePolledTimer updateTimer(1000); //Create a timer object and set it's timeout in milliseconds //this for the V timer also 
void OnTimer(void); //Prototype for timer callback method  // for the V also

bool isFirstConnect = true;    //for the v also


void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth);
  delay(1000);
  updateTimer.SetCallback(OnTimer);  //  for the v also
  
  
    SPI.begin();
    SPI.setBitOrder(MSBFIRST);
    SPI.setDataMode(SPI_MODE0);
    SPI.setClockDivider(SPI_CLOCK_DIV128);
  
  
  
  
  pinMode(CLOCK,OUTPUT);
  pinMode(DATA,OUTPUT);
  
  
  
  pinMode(D0,OUTPUT);
  pinMode(D1,OUTPUT);
  pinMode(D2,OUTPUT);
  pinMode(D3,OUTPUT);
  pinMode(D4,OUTPUT);
  pinMode(D5,OUTPUT);
  pinMode(D6,OUTPUT);    
  pinMode(D7,OUTPUT); 
  
  Particle.function("VODKA", VODKA1);
  Particle.function("WHYSKI", WHYSKI1);
  Particle.function("CADILLAC", CADILLAC1);
  Particle.function("LONG_ISLAND", LONG_ISLAND1);
}


BLYNK_CONNECTED() // runs every time Blynk connection is established  // V
{
if (isFirstConnect)   //  V
{
// Request server to re-send latest values for all pins  //V
Blynk.syncAll();          // V
isFirstConnect = false;   //V
}
}
//xxxxxxxxxxxx[ Push Button Widget using virtual pin V10 ]xxxxxxxxxxx
BLYNK_WRITE(V10) //Function to test status from BLYNK widget to PHOTON  //V
{
int state = param.asInt();   //V
if (state ==1)              //V
{
 TurnOn();                   //V
}
else if (state ==0)         //V
{
TurnOff();              //V
}
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
void OnTimer(void)     //V
{ //Handler for the timer, will be called automatically
// Serial.println("Hello timer");
}



void loop()
{
    
    Blynk.run(); 
    
 
    
    

    
    
    
}



//Alexa voice command for Vodka shot

int VODKA1(String args) {
 digitalWrite(VODKA, HIGH);
 delay(1000);
  digitalWrite(VODKA, LOW);
 return 1;
}

//Alexa voice command for Whyski on rock

int WHYSKI1(String args) {
 digitalWrite(WHYSKI, HIGH);
 delay(1000);
  digitalWrite(WHYSKI, LOW);
 return 1;
}
//Alexa voice command for Cadillac Margireta

int CADILLAC1(String args) {
 digitalWrite(CADILLAC, HIGH);
 delay(1000);
  digitalWrite(CADILLAC, LOW);
 return 1;

}
//Alexa voice command for Strewberry Long Island

int LONG_ISLAND1(String args) {
 digitalWrite(LONG_ISLAND, HIGH);
 delay(1000);
  digitalWrite(LONG_ISLAND, LOW);
 return 1;
}

void TurnOn()    //V // this would be ture wen the V10 been pushed 
{
Blynk.virtualWrite(V3, ON); // virtual LED

int timer = 2000;
    int i;
    
   
      
     
          delay(timer);
          
           for(i=0; i<3; i++) 
            {   
        SPI.transfer(0xFF);
        SPI.transfer(0xFF);
        SPI.transfer(0x00);  
        
        SPI.transfer(0xFF);
        SPI.transfer(0xFF);
        SPI.transfer(0x00);
        
        SPI.transfer(0xFF);
        SPI.transfer(0xFF);
        SPI.transfer(0x00);
        
        SPI.transfer(0xFF);
        SPI.transfer(0xFF);
        SPI.transfer(0x00);
        
        SPI.transfer(0xFF);
        SPI.transfer(0xFF);
        SPI.transfer(0x00);
        
        SPI.transfer(0xFF);
        SPI.transfer(0xFF);
        SPI.transfer(0x00);
        
           }
           
delay(timer);  
 for(i=0; i<3; i++) {
   
        SPI.transfer(0xFF);
        SPI.transfer(0xFF);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0xFF);
        
        SPI.transfer(0xFF);
        SPI.transfer(0xFF);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0xFF);
        
        
        SPI.transfer(0xFF);
        SPI.transfer(0xFF);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0xFF);
        
        SPI.transfer(0xFF);
        SPI.transfer(0xFF);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0xFF);
        
        
        SPI.transfer(0xFF);
        SPI.transfer(0xFF);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0xFF);
        
        SPI.transfer(0xFF);
        SPI.transfer(0xFF);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0xFF);
        
        
        SPI.transfer(0xFF);
        SPI.transfer(0xFF);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0xFF);
        
        SPI.transfer(0xFF);
        SPI.transfer(0xFF);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0xFF);
        
        SPI.transfer(0xFF);
        SPI.transfer(0xFF);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0xFF);

 }
        
//digitalWrite(led1, HIGH); // turn on photon LED D7
//Particle.publish("TurnOn subroutine executed : ", String(ON));
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
void TurnOff()    //V this would be false when the V10 been unpushed 
{
     int i;
Blynk.virtualWrite(V3, OFF); // virtual LED 

 for(i=0; i<3; i++) {
      
   
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        
        
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        
        
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        
        
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        
        
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        
        
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        
        
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        
        
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        
        
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        
        
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        
        
        SPI.transfer(0x00);
        SPI.transfer(0x00);
        SPI.transfer(0x00);
 
}
//digitalWrite(led1, LOW); // turn on photon LED D7 
//Particle.publish("TurnOff subroutine executed : ", String(OFF));
}

I think I’m seeing a lot of stuff which can be removed, for example, the SparkCore timer. I don’t see it used anywhere.

You better use the led widget for the led. That’s what it’s made for :slight_smile:

hello brother thanks for the respond
this code is not just for the LED strips that I have .
its code for controlling my robot bartender that can make 4 type of drinks by blynk and by voice command using Amazon Echo.
but I added in to the bar SW2801 Strip light
and I wanted to control this striplight by Virtual button .
its working but its just cycling one time I don’t know how to put it in void loop to keep continue flashing .
the sparkcortimer I need it for other stuff ,
thanks sir

Ah see it now. You just run through your on/off sequence once. So it’s doing exactly what you tell it. Run through it one time.

You should turn on/off the timer to keep it looping. And avoid the delays, so you have a timer to turn it on and one to turn it off.

edit-

Not sure how complicated sparktimer is, but SimpleTimer is really easy to use and turn it off/on, disable, enable etc.

So the delay am puting is coz it’s changing different colors
So when u say put timer for turn on where should I put it where it says
Int state = param.Asint();
If (state==1)
{
TurnOn ();
Delay (3000);

}
Like that ?
Thanks

No, there is an example for Blynk called PushData. Please have a look at that one. It uses SimpleTimer to execute a void periodically. Say, every 3 seconds. Avoid using delay! It will get your program in conjunction with Blynk killed.