Created
January 7, 2018 17:18
-
-
Save iampaulidrobo/75b6811485bb984dbccc2d7a28346457 to your computer and use it in GitHub Desktop.
Adafruit MQTT ,esp8266,Motor speed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Code by Piyush Tailor | |
#include "config.h" | |
/************************ Example Starts Here *******************************/ | |
// this should correspond to a pin with PWM capability | |
#define Motor_sense 13 | |
// set up the 'analog' feed | |
AdafruitIO_Feed *Motor = io.feed("Motor"); | |
void setup() { | |
// start the serial connection | |
Serial.begin(115200); | |
// wait for serial monitor to open | |
while(! Serial); | |
// connect to io.adafruit.com | |
Serial.print("Connecting to Adafruit IO"); | |
io.connect(); | |
// set up a message handler for the 'analog' feed. | |
// the handleMessage function (defined below) | |
// will be called whenever a message is | |
// received from adafruit io. | |
Motor->onMessage(handleMessage); | |
// wait for a connection | |
while(io.status() < AIO_CONNECTED) { | |
Serial.print("."); | |
delay(500); | |
} | |
// we are connected | |
Serial.println(); | |
Serial.println(io.statusText()); | |
} | |
void loop() { | |
// io.run(); is required for all sketches. | |
// it should always be present at the top of your loop | |
// function. it keeps the client connected to | |
// io.adafruit.com, and processes any incoming data. | |
io.run(); | |
} | |
// this function is called whenever an 'analog' message | |
// is received from Adafruit IO. it was attached to | |
// the analog feed in the setup() function above. | |
void handleMessage(AdafruitIO_Data *data) { | |
// convert the data to integer | |
int reading = data->toInt(); | |
Serial.print("received <- "); | |
Serial.println(reading); | |
analogWrite(Motor_sense, reading); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment