ADM Activity 2.1.4

Conditionals and Loops

Use programming logic to make decisions, repeat actions, and control automated processes.

Lesson Overview

You will use programming logic to make decisions, repeat actions, and control an automated sorting process. This example combines repeated pickup movement, optical sensor input, conditional decisions, and stacked placement locations.

Notes

  • This lesson focuses on using loops and conditionals to control an automated sorting process.
  • The loop repeats the pickup, sensing, and placement process for multiple objects.
  • The optical sensor hue value is used to decide which bin or stack location receives the part.
  • zGreen and zRed track stack height so sorted parts can be placed in layers.
  • Final submitted code must include meaningful comments explaining the loop, sensor decision, and placement logic.
What You Will Submit

What You Submit

  • Engineering notebook entry for Activity 2.1.4
  • Code or pseudocode with meaningful comments
  • Explanation of how the loop controls repeated sorting
  • Explanation of how the conditional statement chooses a placement location
  • Testing notes showing what worked, what failed, and what changed
  • Photo, screenshot, or video evidence of the sorting behavior
  • Short reflection explaining how conditionals and loops improve automation
Code example

2.1.4: Conditionals and Loops

Review the code, copy it when needed, and add comments before submitting your final version.

VEXcode Python Example
Code examples may be incomplete or missing comments. Comments are required for code submissions.
zGreen = 30
zRed = 30
# Begin project code
for i in range (6):
    arm10.move_to(180, 100, 100)

    arm10.set_end_effector_type(Arm.MAGNET)
    arm10.move_to(100, 200, 16)
    arm10.set_end_effector_magnet(True)
    arm10.move_to(100, 200, 75)
    arm10.move_to(45, 175, 50)

    optical_5.set_light(LedStateType.ON)
    optical_5.set_light_power(50, PERCENT)
    wait(1, SECONDS)

    if optical_5.hue() > 50:
        arm10.move_to(175, 0, 100)
        arm10.move_to(175, 0, zGreen)
        arm10.set_end_effector_magnet(False)
        zGreen = zGreen + 10
    elif optical_5.hue() < 50:

        arm10.move_to(175, 150, 100)
        arm10.move_to(175, 150, zRed)
        arm10.set_end_effector_magnet(False)
        zRed = zRed + 10