Created
March 18, 2019 15:38
-
-
Save joelcardinal/db22ac95fdc596982c1a35ce572f84e1 to your computer and use it in GitHub Desktop.
Smartibot Testing
This file contains hidden or 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
var smarti = require("Smartibot"); | |
// why did this work with E1 when plugged into E2 | |
var g = require("Smartibot-display").connect(smarti.E2); | |
var dist = require("Smartibot-distance").connect(smarti.E1); | |
var m1 = false; | |
var eyes = false; | |
// BTN A | |
setWatch(function(e) { | |
// e.state boolean | |
if(m1){ | |
LED.write(false); // blue LED | |
smarti.setMotor(1, 0); // motor, speed | |
m1 = false; | |
}else{ | |
LED.write(true); // blue LED | |
smarti.setMotor(1, -0.5); // motor, speed | |
m1 = true; | |
} | |
}, BTN1, {repeat:true}); | |
// BTN B | |
setWatch(function(e) { | |
if(eyes){ | |
smarti.setLEDs([0,0,0], [0,0,0]); // eyes "off" | |
eyes = false; | |
}else{ | |
smarti.setLEDs([255,0,0], [0,255,0]); // eyes | |
eyes = true; | |
} | |
}, BTN2, {repeat:true}); | |
// screen | |
function sayHi(){ | |
console.log('Hi'); | |
g.clear(); // not working? | |
g.setColor(127); // set brightness - 0..255 | |
// Draw something! | |
//g.drawRect(0,0,15,8); | |
g.drawRect(0,0,0.5,0.5); // single LED | |
g.drawString("Hi",2,2); | |
// Send what we drew to the screen | |
g.flip(); | |
} | |
function sayYo(){ | |
console.log('Yo'); | |
g.clear(); | |
g.setColor(127); // set brightness - 0..255 | |
// Draw something! | |
g.drawRect(0,0,15,8); | |
g.drawString("Yo",2,2); | |
// Send what we drew to the screen | |
g.flip(); | |
} | |
function clearScreen(){ | |
console.log('clear'); | |
g.clear(); | |
g.flip(); | |
} | |
// distance/gesture | |
setInterval(function() { | |
// 100 = 10cm away | |
/* | |
if (dist.getLeft() < 100){ | |
}else{ | |
} | |
if (dist.getRight() < 100){ | |
}else{ | |
} | |
*/ | |
var gesture = dist.getGesture(); | |
if (gesture){ | |
if (gesture === 'up'){ | |
sayHi(); | |
} | |
if (gesture === 'down'){ | |
clearScreen(); | |
//sayYo(); | |
} | |
} | |
// dist.getLeft() alwasy returns 8191 | |
console.log(dist.getLeft()+'|'+dist.getRight()); | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment