Skip to content

Instantly share code, notes, and snippets.

@structure7
Created June 19, 2017 15:51
Show Gist options
  • Save structure7/0bed9de88ee2df82d62f739f81197d7b to your computer and use it in GitHub Desktop.
Save structure7/0bed9de88ee2df82d62f739f81197d7b to your computer and use it in GitHub Desktop.
Feeds a little betta fish! Pics at http://imgur.com/a/3TzZ8
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <BlynkSimpleEsp8266.h>
const char* auth = "fromBlynkApp";
const char* ssid = "ssid";
const char* pw = "pw";
#define IN1 5 // Motor board brown to WeMos pin D1
#define IN2 4 // Motor board red to WeMos pin D2
#define IN3 14 // Motor board orange to WeMos pin D5
#define IN4 12 // Motor board yellow to WeMos pin D6
void setup()
{
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
Serial.begin(9600);
Blynk.begin(auth, ssid, pw);
while (Blynk.connect() == false) {
// Wait until connected
}
}
void loop()
{
Blynk.run();
}
BLYNK_WRITE(V1)
{
int pinData = param.asInt();
if (pinData == 0) // Triggers when button is released only
{
for (int x = 0; x < 64; x++) { // This running 64 times equals 1/8 rotation of the motor's output shaft
digitalWrite(IN1, HIGH);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
delay(15);
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
delay(15);
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, HIGH);
delay(15);
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
delay(15);
Serial.println(x);
if (x == 63) { // This stops the motors (all lights off) to save power
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
//break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment