Hi All,
I’ll try and make this clear. I’m looking to setup a little program that takes the value from a couple of sliders on the Blynk app and implements them on an embedded chip (NodeMCU ESP8266) while developing with the Arduino IDE.
I’ve been able to get the basic functionality of a slider widget outputting its values to the board which is then driving a circuit with an analogWrite(function). It looks something like this:
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <SPI.h>
#include <BlynkSimpleEsp8266.h>
char auth[]= "#####################";
char ssid[] = "###########";
char pass[] = "#########";
int ledPin= 16;
BLYNK_WRITE(V3){
analogWrite(ledPin,param.asInt());
}
void setup() {
Serial.begin(115200);
// put your setup code here, to run once:
Blynk.begin(auth,ssid,pass);
}
void loop() {
Blynk.run();
}
And that’s all well and good. But what I’m looking to do is add another slider widget, as well as some buttons, and really adjusting what I can do! I want one slider to control the amplitude (which is working great as the implementation above) while another controls the frequency of the function I choose to output!
My initial thought was something like this:
BLYNK_WRITE(V3){
int amplitude = param.asInt();
}
BLYNK_WRITE(V6){
int frequency = param.asInt();
}
void pulse(){
int delayValue = 255-frequency;
analogWrite(ledPin,amplitude);
delay(delayValue*10);
analogWrite(ledPin,0);
delay(delayValue*10);
}
But that’s throwing the error:
frequency was not declared in this scope
I think my main issue is that I’m struggling with ordering these functions so that I can use them properly. My end goal is to have several button widgets which will select the function pattern, a slider for the frequency, and a slider for the amplitude. As it stands, however, I’m kind of at a loss of how to order functions, what values I can and can’t reference (and where I can and can’t) within the complete code. Any help is hugely appreciated, let me know if I can provide any more information or clarify what I have here!