-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVolume_Servo.ino
170 lines (129 loc) · 4.25 KB
/
Volume_Servo.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
You can send/receive any data using WidgetTerminal object.
App project setup:
Terminal widget attached to Virtual Pin V1
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h> // Library for Servo
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "AUTH";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "SSID";
char pass[] = "PASSWORD";
int rudPos = 90;
Servo rudderServ;
// Attach virtual serial terminal to Virtual Pin V1
WidgetTerminal terminal(V1);
// You can send commands from Terminal to your hardware. Just use
// the same Virtual Pin as your Terminal Widget
BLYNK_WRITE(V1)
{
// if you type "Marco" into Terminal Widget - it will respond: "Polo:"
if (String("Marco") == param.asStr()) {
terminal.println("You said: 'Marco'") ;
terminal.println("I said: 'Polo'") ;
} else {
// Send it back
terminal.print("You said:");
terminal.write(param.getBuffer(), param.getLength());
terminal.println();
}
// Ensure everything is sent
terminal.flush();
}
BLYNK_WRITE(V2)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
rudderServ.attach(4);
int newRudPos = pinValue;
delay(100);
// Turn Up Volume
if ( newRudPos > rudPos )
{
int increment = newRudPos - rudPos;
for (int i = 0; increment > i; i++)
{
int newAmount = rudPos + i;
rudderServ.write(newAmount);
terminal.println(i);
delay(10d);
}
rudderServ.detach();
}
// Turn Down Volume
if ( newRudPos < rudPos )
{
int increment = rudPos - newRudPos;
for (int i = 0; increment > i; i++)
{
int newAmount = rudPos - i;
rudderServ.write(newAmount);
terminal.println(i);
delay(10);
}
rudderServ.detach();
}
rudPos = newRudPos;
//rudderServ.detach();
terminal.println("Servo Detached");
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
// Clear the terminal content
terminal.clear();
rudderServ.attach(4);
rudPos = rudderServ.read();
terminal.println("Rudder Position ");
terminal.println(rudPos);
/* if (rudPos > 90) {
// for (int i = 0; rudPos - 90; i++)
// {
// rudderServ.write(90 + i);
// delay(100);
}
}
if (rudPos < 90) {
for (int i = 0; 90 - rudPos; i++)
{
rudderServ.write(rudPos + i);
delay(100);
}
}*/
rudderServ.detach();
// This will print Blynk Software version to the Terminal Widget when
// your hardware gets connected to Blynk Server
terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
terminal.println(F("-------------"));
terminal.println(F("Type 'Marco' and get a reply, or type"));
terminal.println(F("anything else and get it printed back."));
terminal.flush();
}
void loop()
{
Blynk.run();
}