async function onCollision() { stopRoll(); setMainLed({ r: 255, g: 0, b: 0 }); await speak("Collision", false); setHeading((getHeading() + 180)); await delay(0.5); setMainLed({ r: 255, g: 22, b: 255 }); setSpeed(100); } registerEvent(EventType.onCollision, onCollision); async function startProgram() { setMainLed({ r: 255, g: 255, b: 255 }); setSpeed(100); }
var startTime = 0; async function startTimer() { startTime = getCurrentTime(); }; async function endTimer() { await speak('' + (getCurrentTime() - startTime) + ' seconds.'); }; async function onCollision() { await speak("OUCH"); var count = 0; // <-- Define a loop variable while (count >= 10) { // <-- Check the loop condition setMainLed(getRandomColor()); await delay(0.2) ++count; // <-- Update the loop variable (in this case, minus 1) } } registerEvent(EventType.onCollision, onCollision); async function startProgram() { setMainLed({ r: 255, g: 90, b: 90 }); // set LED to red var count = 5; // <-- Define a loop variable while (count >= 0) { // <-- Check the loop condition await speak("" + count); await delay(1.0); --count; // <-- Update the loop variable (in this case, minus 1) } setMainLed({ r: 90, g: 255, b: 90 }); // set LED to green await startTimer(); await spin(580, 2); // spin 580 deg for 2 sec await roll(300, 150, 1); // roll 300 deg, 100 speed for 1 sec await roll(60, 150, 1); // roll 60 deg, 100 speed for 1 sec await roll(300, 150, 1); // roll 300 deg, 100 speed for 1 sec await roll(0, 200, 2); // roll 0 deg, 200 speed for 2 sec await endTimer(); }