Created
October 1, 2020 18:19
-
-
Save daisycamber/5b4881e801d1b71c20d78d05eeb62d2d to your computer and use it in GitHub Desktop.
Sphero random movement with collision detection
This file contains 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
async function onCollision() { | |
stopRoll(); | |
setMainLed({ r: 255, g: 0, b: 0 }); | |
await setHeading(getRandomInt(0,359)); | |
await delay(0.5); | |
setMainLed({ r: 255, g: 22, b: 255 }); | |
setSpeed(100); | |
} | |
registerEvent(EventType.onCollision, onCollision); | |
async function startProgram() { | |
setMainLed({ | |
r: getRandomInt(0,255), | |
g: getRandomInt(0,255), | |
b: getRandomInt(0,255) | |
}); | |
//setHeading(getRandomInt(0,359)); | |
maxRoll = 20; | |
while(true){ | |
setStabilization(true); | |
setSpeed(30); | |
await delay(3); | |
or = getOrientation(); | |
while(or.pitch < maxRoll && or.yaw < maxRoll && or.roll < maxRoll ){ | |
await delay(0.1); | |
or = getOrientation(); | |
} | |
setSpeed(0); | |
setStabilization(true); | |
setHeading(getRandomInt(0,359)); | |
await delay(1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment