Your challenge for this part: write a program that will change CoDrone Mini’s LED colors as the drone turns! You can pick whatever colors you like, but we used:
- Red for 0-90 degrees
- Yellow for 90-180 degrees
- Green for -180 to -90 degrees
- Blue for -90 to 0 degrees
First, import the necessary libraries, create the drone object, and pair the drone. Next, add a sleep command for 1 second and reset the drone’s sensors.
Add a for loop that repeats 100 times and will get the drone’s yaw with the
get_angle() function and then store it to a variable called
Next, write an if statement that will turn the CoDrone Mini’s LED red if the angle is greater than 0 and less than 90. Be careful with this one! Negative numbers are being used in this program so you do need to include greater than 0 in this conditional.
Do the same for the other three angle settings, but use else if statements instead. Finally, include an else statement that will turn the drone’s LED white.
Include a sleep command for .05 seconds and then write a print command that will display as “Done!”
Note: this program doesn’t include any takeoff, landing, or flight commands! As a challenge, add those in yourself.
drone = CoDrone_mini.CoDrone()
for i in range(100):
angle = drone.get_angle().YAW
if angle > 0 and angle < 90:
drone.LED_color(255,0,0,100) # red
elif angle > 90 and angle < 180:
drone.LED_color(255,255,0,100) # yellow
elif angle > -180 and angle < -90:
drone.LED_color(0,255,0,100) # green
elif angle > -90 and angle < 0:
drone.LED_color(0,0,255,100) # blue
drone.LED_color(255,255,255,100) # white