blynkkk / blynk-library

Blynk library for IoT boards. Works with Arduino, ESP32, ESP8266, Raspberry Pi, Particle, ARM Mbed, etc.
https://blynk.io
MIT License
3.83k stars 1.39k forks source link

Add NodeMCU + Motor Shield - Sample #346

Closed andregm3 closed 7 years ago

andregm3 commented 7 years ago

Please add NodeMCU + Motor Shield sample

nodemcu-motor-shield-16609-60-b

Source: https://surak.wordpress.com/2016/12/18/robot-car-controlled-by-iphone-using-blynk-and-nodemcu/

nodmoto

/**

define BLYNK_PRINT Serial // Comment this out to disable prints and save space

include

include

define RightMotorSpeed 5

define RightMotorDir 0

define LeftMotorSpeed 4

define LeftMotorDir 2

// You should get Auth Token in the Blynk App. // Go to the Project Settings (nut icon). char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; char ssid[] = "MyWifi"; char pass[] = "MyWifiPassword";

void setup() { Serial.begin(9600); Blynk.begin(auth, ssid, pass);

pinMode(RightMotorSpeed, OUTPUT); pinMode(RightMotorDir, OUTPUT); pinMode(LeftMotorSpeed, OUTPUT); pinMode(LeftMotorDir, OUTPUT); }

void loop() { Blynk.run(); }

void halt() { digitalWrite(RightMotorSpeed, LOW); digitalWrite(LeftMotorSpeed, LOW); }

void forward() { digitalWrite(RightMotorDir, HIGH); digitalWrite(LeftMotorDir, HIGH); digitalWrite(RightMotorSpeed, HIGH); digitalWrite(LeftMotorSpeed, HIGH); }

void reverse() { digitalWrite(RightMotorDir, LOW); digitalWrite(LeftMotorDir, LOW); digitalWrite(RightMotorSpeed, HIGH); digitalWrite(LeftMotorSpeed, HIGH); }

void right() { digitalWrite(RightMotorDir, LOW); digitalWrite(LeftMotorDir, HIGH); digitalWrite(RightMotorSpeed, HIGH); digitalWrite(LeftMotorSpeed, HIGH); }

void left() { digitalWrite(RightMotorDir, HIGH); digitalWrite(LeftMotorDir, LOW); digitalWrite(RightMotorSpeed, HIGH); digitalWrite(LeftMotorSpeed, HIGH); }

BLYNK_WRITE(V0) { if (param[0]) forward(); else halt(); }

BLYNK_WRITE(V1) { if (param[0]) reverse(); else halt(); }

BLYNK_WRITE(V2) { if (param[0]) right(); else halt(); }

BLYNK_WRITE(V3) { if (param[0]) left(); else halt(); }

vshymanskyy commented 7 years ago

Pull Requests are welcome!

vshymanskyy commented 7 years ago

Thanks, please contribute it as a Pull Request!