Skip to content

Instantly share code, notes, and snippets.

@yasugahira0810
Created December 7, 2018 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yasugahira0810/9cd8382df74089b6a9170f31651aa25d to your computer and use it in GitHub Desktop.
Save yasugahira0810/9cd8382df74089b6a9170f31651aa25d to your computer and use it in GitHub Desktop.
const Obniz = require("obniz");
const express = require('@runkit/runkit/express-endpoint/1.0.0');
const app = express(exports);
const yourObnizId = "OBNIZ_ID" // write your obniz id
app.get('/', async (req,res) =>{
let obniz = new Obniz(yourObnizId);
let connected = await obniz.connectWait({timeout:10});
if(connected){
var servo = obniz.wired("ServoMotor", {signal:0,vcc:3, gnd:2});
servo.angle(100.0);
await obniz.wait(1000);
servo.angle(80.0);
setTimeout(function(){
obniz.close();
},1000);
res.json({status: "success"});
}else{
res.json({status: "error", reason : "Cannnot connect to obniz"});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment