Last active
June 7, 2018 07:45
-
-
Save seanmckaybeck/483ab96039046a4269c5 to your computer and use it in GitHub Desktop.
Remote control servo with Particle Photon. Apache License, copyright 2015 Sean Beck
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
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
Hey, I can't seem to get this to work, is serv a missing library?