Using JavaScript, there are many possible ways to program a Sphero.
The following code will make the sphero roll in direction 0° at 100 speed for 2 seconds:
async function startProgram() {
await roll(0, 100, 2);
}
The following program will make the Sphero set its backlight LED to full brightness, fade from blue to pink over 4 seconds and then make it strobe green three times until it permanently remains green until the program ends.
async function startProgram() {
setBackLed(255);
await fade({ r: 6,
g: 13, b: 255 },
{ r: 255, g: 0,
b: 187 }, 4);
await strobe({ r: 4, g: 255,
b: 14}, 2, 3);
}
The following program will spin the Sphero at 1080° for 2 seconds, then set its raw motor at -255 for left, 255 for right for 3 seconds:
async function startProgram() {
await spin(1080, 2);
await rawMotor(-255, 255, 3);
}
This program will make the Sphero play a random sound:
async function startProgram() {
await Sound.play(true);
}
This program will make the Sphero roll at 0° at 70 speed for 2 seconds, then on collision, it will make the Sphero turn pink.
async function startProgram() {
await roll(0, 70, 2);
}
async function onCollision() {
setMainLed({ r: 255,
g: 41, b: 29 });
}
registerEvent(EventType.onCollision,
onCollision);
This program will make the Sphero fade from green to purple over 1 second with a delay of 0.025 on a loop of 5 times.
async function startProgram() {
for (var _i0 = 0; _i0
< 5; ++_i0) {
await fade({ r: 43,
g: 255, b: 13 },
{ r: 172, g: 1,
b: 255 }, 1);
await fade({ r: 172,
g: 1, b: 255 },
{ r: 43, g: 255,
b: 13 }, 1);
await delay(0.025);
}
}