Last active
March 4, 2021 12:11
-
-
Save phirefly/b1c9b249e94639b24261e04e9ce1fde8 to your computer and use it in GitHub Desktop.
Lego Robotics: Color Sorter Snippets
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
// Startup | |
brick.showMood(moods.awake); | |
brick.showString("Hello world", 1); | |
music.playSoundEffect(sounds.communicationHello); | |
music.playSoundEffectUntilDone; | |
motors.largeD.run(-50, 3, MoveUnit.Seconds); | |
sensors.touch1.onEvent(ButtonEvent.Pressed, function () { | |
brick.showImage(images.eyesWinking); | |
}) | |
// Event examples | |
sensors.touch1.onEvent(ButtonEvent.Released, function () { | |
brick.showImage(images.eyesBlackEye); | |
motors.largeD.run(20, 5, MoveUnit.Degrees); | |
motors.stopAll(); | |
}) | |
sensors.color3.onColorDetected(ColorSensorColor.Blue, function () { | |
music.playSoundEffectUntilDone(sounds.colorsBlue); | |
}) | |
sensors.color3.onColorDetected(ColorSensorColor.Yellow, function () { | |
music.playSoundEffectUntilDone(sounds.colorsYellow); | |
}) | |
sensors.color1.onColorDetected(ColorSensorColor.Green, function () { | |
music.playSoundEffectUntilDone(sounds.colorsGreen); | |
}) | |
//Write the one for Red using code completion | |
// TBD | |
// Re-use this to dump the brick. See if you can figure out how to do this in code using the visual | |
function dumpBrick() { | |
music.playSoundEffect(sounds.mechanicalBlip1); | |
motors.mediumA.run(20, 180, MoveUnit.Degrees); | |
pause(1000) | |
motors.mediumA.run(-20, 180, MoveUnit.Degrees); | |
motors.mediumA.stop(); | |
} | |
// Variables | |
// var initialMood = moods.awake | |
// Additional functions we can write: | |
// Move the beginning to reset(); | |
// set the ActiveColor to most recently scanned color | |
// goToMarkerAndDump(); | |
// Dump the color if the center button is pressed | |
// storeColorList(); | |
dumpBrick(); | |
// REFERENCE LINKS: | |
// https://education.lego.com/en-us/lessons/ev3-cim/make-a-sorting-machine#coding-tips | |
// https://makecode.mindstorms.com/reference/motors/motor/run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment