-
Notifications
You must be signed in to change notification settings - Fork 0
/
J5TennisBall.min.js
2 lines (2 loc) · 1.32 KB
/
J5TennisBall.min.js
1
2
var j5=require("johnny-five"),board,button;board=new j5.Board;board.on("ready",function(){function u(){redLight=new j5.Led(3);yellowLight=new j5.Led(2);greenLight=new j5.Led(4)}var r=new j5.Ping({pin:8,freq:250}),t,i,n;button=new j5.Button({pin:7,holdtime:500,invert:!0});t=20;button.on("hold",function(){n=t;console.log("offset = "+n)});i=2;n=5;r.on("change",function(){t=this.inches;this.inches<i+n?(console.log("flashing red"),redLight.strobe(200),yellowLight.off(),greenLight.off()):this.inches>i+n&&this.inches<6+n?(console.log("red"),redLight.off().stop(),redLight.on(),yellowLight.off(),greenLight.off()):this.inches>6+n&&this.inches<10+n?(console.log("red and yellow"),redLight.off().stop(),redLight.on(),yellowLight.on(),greenLight.off()):this.inches>10+n&&this.inches<20+n?(console.log("yellow"),redLight.off(),yellowLight.on(),greenLight.off()):this.inches>20+n&&this.inches<35+n?(console.log("green and yellow"),greenLight.on(),yellowLight.on(),redLight.off()):this.inches>55+n&&(console.log("green"),redLight.off(),yellowLight.off(),greenLight.on())});u();this.repl.inject({redLight:redLight});console.log("You can interact with the RGB LED via the variable 'led' e.g. led.on();\n Hit control-D to exit.\n >> ");console.log('try "on", "off", "toggle", "strobe", "stop" (stops strobing)')});
//# sourceMappingURL=J5TennisBall.min.js.map