servomotor.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
int servoPin = A3;
Servo myServo;
int servoPos = 0;
void setup() {
// attaches the servo on the A3 pin to the servo object
myServo.attach( A3 );
//Register our Particle to control the servo
Particle.function("servo", servoControl);
// Keep a cloud variable for the current position
Particle.variable( "servoPos" , &servoPos , INT );
}
void loop()
{
delay(100);
}
int servoControl(String command)
{
// Convert
int newPos = command.toInt();
// Make sure it is in the right range
// And set the position
servoPos = constrain( newPos, 0 , 180);
// Set the servo
myServo.write( servoPos );
// done
return 1;
}
Ready.Last Event: particle/device/updates/pending = false SHAMASPARTICLE v5.9.0
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .