-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTreatDispenser.ino
69 lines (50 loc) · 1.19 KB
/
TreatDispenser.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>
// Auth Token from the Blynk App.
char auth[] = "{InsertAuthTokenHere}";
// WiFi credentials.
char ssid[] = "{InsertSSID}";
char pass[] = "{InsertPassword}";
// Declare the Servo pin
#define SERVO_PIN D7
Servo Servo1;
void setup() {
// Attach the servo to the specified pin number
pinMode(SERVO_PIN, OUTPUT);
Blynk.begin(auth, ssid, pass);
}
void loop() {
Blynk.run();
}
// Handler for Virtual Pin 1 (Button)
BLYNK_WRITE(V1)
{
int pinValue = param.asInt();
// Virtual button was pressed, dispense treat
if (pinValue == 1) {
Servo1.attach(SERVO_PIN);
// Reset position
Servo1.write(5);
delay(500);
// Turn servo position all the way around
Servo1.write(180);
// Wait for servo to finish moving
delay(2000);
// Return servo to starting position
Servo1.write(5);
// Wait for servo to finish moving
delay(1500);
Servo1.detach();
}
}
// Handler for virtual slider, used for testing positions
BLYNK_WRITE(V3)
{
int pinValue = param.asInt();
Servo1.attach(SERVO_PIN);
Servo1.write(pinValue);
delay(500);
Servo1.detach();
}