session04 - nsbejrFire/microbitRobot GitHub Wiki
Programming Session 04
This session focuses on conditional expressions. Conditional expressions are expressions that evaluate to True
or False
and allow programs to make decisions. Conditional expressions can be combined with if
, if
/else
, or if
/elif
/else
to control which parts of a program are executed.
Program Code
All the programming exercises can be found here:
- First we reviewed the motor control code
- We looked at the motor control code using functions from last week
- Then we modified that code to include functions
spinLeft()
andspinRight()
in this example
- We tried out combining conditional expressions with control flow
- This example uses
if
/else
to check for button A presses - Then we use
if
/elif
/else
to check for pressing of button A or button B in this example - This example runs just the same as the previous example, but has some more explicit conditional expression checks
- By using some even fancier conditional expression checks, this example can check if both buttons are pressed at the same time
- This example uses
- We used the accelerometer to make some simple "games"
- We wrote a simple dice program in this example
- We replaced the digital numbers from the above example with graphical dice images in this example
- This example makes our Micro:Bit into a Magic 8 Ball
- Finally we learned how to use Infrared Reflectance Sensors to make our robot follow lines in this example
Challenges for Next Week
- The line following program works, but the robot moves slowly. Modify the code to see how fast you can make your robot follow the circular path.
- hint: make your own modified version of
turnLeft()
andturnRight()
to turn more gradually
- hint: make your own modified version of
- Make your robot follow the circular path backwards
- hint: you'll need to redo the decision logic in the while loop
You can upload a video for your fastest robot line following run and/or your best robot backwards line following. Uploading video will make you eligible to win a special end of season prize!
- Your username is: First_name.Last_name
- FlipGrid link for Team 1
- FlipGrid link for Team 2
- FlipGrid link for Team 3
- FlipGrid link for Team 4
- FlipGrid link for Team 5