Can you please help me with the stroboscope script?
What if I want to control two different functions with two different buttons with the strobe script.
For example I want V1 & V2 to control D3, & and V3 & V4 to control D4?
I have only been able to control both D3 & D4 at the same time with either V1 or V2.
Here is the libraries that are included in the sketch.
[quote]// You could use a spare Hardware Serial on boards that have it (like Mega) #include <SoftwareSerial.h> //SoftwareSerial.h
SoftwareSerial SwSerial(2, 3); // RX, TX #define BLYNK_PRINT SwSerial #include <BlynkSimpleSerial.h> //BlynkSimpleSerial.h #include <SimpleTimer.h> //SimpleTimer.h
[/quote]
``` cpp <--put 3 backticks BEFORE your code starts ("cpp" means C++ language)
//Put your code here
//..................
//..................
``` <--insert 3 backticks AFTER your code
**This makes your code readable and with highlighted syntax, like this
@Erik_Hagstrom take a look at the following sketch which is in ESP format rather than Arduino format. You just need to convert it back to Arduino for you to use. For the ESP I used LED_PIN1 and LED_PIN2 both as the onboard LED and it is active LOW.
// Stroboscope.ino mod by Costas 9/10/16
//#define BLYNK_DEBUG
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
char auth[] = "xxxxxxxxxxxxxxx";
#define LED_PIN1 2 // was 3 for Arduino
#define LED_PIN2 2 // was 4 for Arduino
SimpleTimer timer;
int t1;
int t2;
// Enable/disable blinking using virtual pin 1
BLYNK_WRITE(V1)
{
if (param.asInt()) {
timer.enable(t1);
} else {
timer.disable(t1);
digitalWrite(LED_PIN1, HIGH); // LED active LOW
}
}
// Change blink interval using virtual pin 2
BLYNK_WRITE(V2)
{
long interval = param.asLong();
boolean wasEnabled = timer.isEnabled(t1);
timer.deleteTimer(t1);
t1 = timer.setInterval(interval, ledBlynk1);
if (!wasEnabled) {
timer.disable(t1);
}
}
BLYNK_WRITE(V3)
{
if (param.asInt()) {
timer.enable(t2);
} else {
timer.disable(t2);
digitalWrite(LED_PIN2, HIGH); // LED active LOW
//digitalWrite(LED_PIN1, HIGH); // LED active LOW
}
}
BLYNK_WRITE(V4)
{
long interval = param.asLong();
boolean wasEnabled = timer.isEnabled(t2);
timer.deleteTimer(t2);
t2 = timer.setInterval(interval, ledBlynk2);
if (!wasEnabled) {
timer.disable(t2);
}
}
// Toggle LED_PIN1
void ledBlynk1()
{
//digitalWrite(LED_PIN1, !digitalRead(LED_PIN1));
digitalWrite(LED_PIN2, !digitalRead(LED_PIN2));
}
// Toggle LED_PIN2
void ledBlynk2()
{
//digitalWrite(LED_PIN1, !digitalRead(LED_PIN1));
digitalWrite(LED_PIN2, !digitalRead(LED_PIN2));
}
void setup()
{
Serial.begin(115200);
Serial.println("\nStarted");
Blynk.begin(auth, "MTN WIFI 19996", "xxxxxx", "192.168.10.229", 8442);
int mytimeout = millis() / 1000;
while (Blynk.connect() == false) {
if((millis() / 1000) > mytimeout + 4){ // try for less than 5 seconds
break;
}
}
if(Blynk.connected()){
Serial.println("Connected to Blynk");
}
else{
Serial.println("Failed to connect to Blynk");
}
// Configure LED and timer
pinMode(LED_PIN1, OUTPUT);
digitalWrite(LED_PIN1, HIGH); // on board LED off
t1 = timer.setInterval(500L, ledBlynk1);
timer.disable(t1);
pinMode(LED_PIN2, OUTPUT);
digitalWrite(LED_PIN2, HIGH); // on board LED off
t2 = timer.setInterval(500L, ledBlynk2);
timer.disable(t2);
}
void loop()
{
Blynk.run();
timer.run();
}