Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remote control servo with Particle Photon. Apache License, copyright 2015 Sean Beck
Servo serv;
int pos = 0;
void setup() {
serv.attach(D0);
Spark.function("setpos", setPos);
Spark.variable("getpos", &pos, INT);
}
void loop() {
}
int setPos(String pstn) {
pos = pstn.toInt();
serv.write(pos);
return pos;
}
<html>
<head>
<style>
body {
margin: 1em auto;
max-width: 45em;
padding: 0.8em;
background: white;
}
</style>
</head>
<body>
<h1>Photon servo control</h1>
<input type="range" min="0" max="180" value="0" onchange="showValue(this.value)"/>
<span id="range">0</span>
<script type="text/javascript">
function showValue(newValue) {
document.getElementById("range").innerHTML=newValue;
var request = new XMLHttpRequest();
var dev_id = '<your device id here>';
var access = '<your access token here>';
var data = 'params='+newValue+'&access_token='+access;
var url = 'https://api.particle.io/v1/devices/'+dev_id+'/setpos/';
request.open('POST', url, true);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
request.send(data);
}
</script>
</body>
</html>
@ThaWeatherman

This comment has been minimized.

Show comment
Hide comment
@ThaWeatherman

ThaWeatherman Sep 7, 2015

See it in action here. Hook up 4 AA battery to servo. Connect servo to pin D0 on the Photon.

Owner

ThaWeatherman commented Sep 7, 2015

See it in action here. Hook up 4 AA battery to servo. Connect servo to pin D0 on the Photon.

@bendespain

This comment has been minimized.

Show comment
Hide comment
@bendespain

bendespain Feb 27, 2016

Hey, I can't seem to get this to work, is serv a missing library?

bendespain commented Feb 27, 2016

Hey, I can't seem to get this to work, is serv a missing library?

@dreamtwerks

This comment has been minimized.

Show comment
Hide comment
@dreamtwerks

dreamtwerks May 20, 2016

Hi i have edited your html to use 3 servos at same time and i gived the credits to you, can see it here:
https://community.particle.io/t/photon-3-servos-controlled-by-html/23032/1

dreamtwerks commented May 20, 2016

Hi i have edited your html to use 3 servos at same time and i gived the credits to you, can see it here:
https://community.particle.io/t/photon-3-servos-controlled-by-html/23032/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment