Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save takahashilabo/f1de55e37ee88083cd3e50f9a39b8ff8 to your computer and use it in GitHub Desktop.
Save takahashilabo/f1de55e37ee88083cd3e50f9a39b8ff8 to your computer and use it in GitHub Desktop.
Box Step by Sphero Mini using Spherov2.js
//see https://www.youtube.com/watch?v=SjjnBMIci2s
//spherov2.js at https://github.com/igbopie/spherov2.js
const { Scanner, Utils } = require('spherov2.js');
const makeItBlink = async () => {
const spheros = await Scanner.findAllSpheroMini();
if (!spheros || spheros.length == 0) return console.log('sphero mini not available!');
let c=0;
while (true) {
let ary = [];
for (let s of spheros) {
ary.push(setColor(s, c));
}
await Promise.all(ary);
c = ++c % 4;
}
};
makeItBlink();
async function setColor(s,i) {
const speed = 100;
switch(i) {
case 0:
await s.setMainLedColor(255, 0, 0);
await p(s, speed, 270);
break;
case 1:
await s.setMainLedColor(0, 255, 0);
await p(s, speed, 0);
break;
case 2:
await s.setMainLedColor(0, 0, 255);
await p(s, speed, 90);
break;
case 3:
await s.setMainLedColor(255, 0, 255);
await p(s, speed, 180);
break;
}
}
const p = async (sphero, speed, angle) => {
const PATROL_TIME = 2181;
await sphero.rollTime(speed, angle, PATROL_TIME, []);
// console.log(angle);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment