Thank you, Gunner. I got it working! Yahoo!. I followed your tips, yes it works. Here is the updated code. The way it is right now, the pot is not working, but I think I can figure out how to correct that. I never had any problem setting up the pot, my problem was controlling the motor with the slider. As a matter of fact, the entire pot code has been commented out. Blynk is awesome! With Blynk you can eliminate expensive hard-to-get hardware.
I moved these two lines to void loop, and I declared “speed” as a global variable.
Blynk.virtualWrite(V21, speed); // Check Slider value
analogWrite(motorPin, speed); // <== Blynk controlling the motor speed. Yahoo!
I know the code can be improved now that is working. Once again, Thanks a lot!
// This #include statement was automatically added by the Particle IDE.
#include "blynk/blynk.h"
/*
Motor Speed Control
Jan 21, 2017
*/
int potPin = A0;
int motorPin = D0;
int potValue = 0;
int motorValue = 0;
int motorValue2 = 0;
int speed = 0;
char auth[] = "xxxxzzzzyyyy";
//--------------Read Slider, store value in the global variable "speed" ----------------
BLYNK_WRITE(V20) // Virtual pin value set to 255
{
speed = param.asInt();
}
/* ---------------- SETUP ---------------------------- */
void setup() {
Serial.begin(9600);
Blynk.begin(auth);
pinMode(motorPin, OUTPUT);
pinMode(potPin, INPUT);
}
/* ----------------- VOID LOOP ---------------------*/
void loop()
{
Blynk.run();
/*
potValue = analogRead(potPin);
// The Photon analogRead values go from 0 to 4095. The Photon analogRead is 12 bits resolution, so 2^12 = 4095
//analogWrite values are from 0 to 255, 255 represents the MAX voltage input, in this case: +3.2V
// The next two entries basically acomplish the same result. Use one or the other
motorValue = map(potValue, 0, 4096, 0, 255);
// motorValue2 = potValue/16;
analogWrite(motorPin, motorValue);
Serial.print("Motor Value "); Serial.println(motorValue);
*/
Blynk.virtualWrite(V21, speed); // Just Checking Slider Values
analogWrite(motorPin, speed); // <== Blynk Slider controlling the motor speed. Yahoo!
delay(1000);
}
The whole thing is very interesting to me. I had trouble grasping the following: D0 declared as an OUTPUT it does not care how it gets its value from 0 to 255 range. It can be real such is using the pot and A0 as an INPUT, or virtual such is the case that is setup now. This is like vudĂş, man! Magic! Am scare now