BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

How to use Stroboscope with Timer 1 w/ ESP8266 and Arduino?

Hello,

I have created a strobe light that uses hardware timers to be very accurate on Arduino UNO.

I’ve created preset ‘programs’ that the light runs through (flash for 10 seconds at 30hz, then take 30 seconds to go from 10hz to 20hz, for example).

The way these adjust the speed is using an int for frequency, and incrementing a step counter with each run of the loop.

Now that I am looking to implement Blynk, I have moved the program into its own function.

However, when I try this, the variables to not increment, and the frequency doesn’t change.

How can I increment inside of a function, or is there a better way to accomplish this? Thank you!

An example custom program:

void menuItem2() { // Function executes when you select the 2nd item from main menu
  int activeButton = 0;

  lcd.clear();
  lcd.setCursor(3, 0);
  lcd.print("Gamma Meditation");
//Custom Program 1//
//Custom step 1 and template for static frequency

  if (stepNumber==1) {  // If you are on 'Step 1' in Program 1
  startFreq = 20 ; // Starting Frequency in hz 
  endFreq = 22;    // End frequency in hz
  segTime = 5;    // Length of segment in seconds
  segTime = (segTime*1000); // seconds into milliseconds
     stepCount = ++stepCount; // Add 1 to the stepOne counter
     if (stepCount == 1){            // If this is the first time through, set the frequency to the start Frequency
      freq = startFreq*10;
     }
     
     if (endFreq-startFreq >= 0 ) {         // If the End Frequency is greater than the Start Frequency, increment the frequency up.
      stepTotal = (endFreq-startFreq)*10;
        freq = ++freq; // increase the frequency by .1hz}
     }
   
    else {         / If the End Frequency is less than the Start Frequency, decrement the frequency down.
       stepTotal = (startFreq-endFreq)*10;
       freq = --freq; // increase the frequency by .1hz}
       
    }
    delayTime = segTime/stepTotal;
    change=true;
    
     // calculated above
    if (stepCount == stepTotal){  //If this is the last time running the step...
        stepCount = 0;
        stepNumber = ++stepNumber; 
        }  // Change to next step starting frequency
  }
//Custom step 2 and template for static frequency

  if (stepNumber==2) {  // If we are on step 1, and step 1 has NOT run 20 times...
  startFreq = 8 ; // Starting Frequency in hz
  
  segTime = 8;    // Length of segment in seconds
  
    } 

if (change) setfreq(freq,len);
while (activeButton == 0) {
    int button;
    readKey = analogRead(0);
    if (readKey < 790) {
      delay(100);
      readKey = analogRead(0);
    }
    button = evaluateButton(readKey);
    switch (button) {
      case 4:  // This case will execute if the "back" button is pressed
        button = 0;
        activeButton = 1;
        break;
    }
  }
}

You should post your complete sketch.

Pete.