The CoDrone EDU controller is equipped with an LED screen to display information about the drone. Using python we can customize the LED screen and draw anything that we want! First, we need to understand how the LED screen works in order to draw an image. The screen uses X-Y coordinates to determine what pixels will be drawn. However, the X-Y coordinates are a little different than what you may be used to. The origin of the screen is in the top left corner. As you move in the downward Y direction the Y value increases. The X value also increases as you move to the right. Let’s do a quick example to see this in action.
Whenever we want to draw a new image we need to make sure to call drone.controller_clear_screen()
. If you forget to do this then your new image will be drawn over either the Link State screen or your old image. Let’s find the border of our screen.
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.controller_clear_screen()
drone.controller_draw_line(0, 0, 126, 0)
drone.controller_draw_line(0, 0, 0, 63)
The controller_draw_line()
function takes a point (x1, y1) and draws a line to the point (x2, y2). In this example we are drawing a line from the origin to make a border around the edge of the screen. From this example we can see that the LED screen is 126 x 63 pixels! Can you finish the rest of the border on your own? See if you can draw a giant square around the edges of the screen!
Solution:
from codrone_edu.drone import *
drone = Drone()
drone.pair()
drone.controller_clear_screen()
drone.controller_draw_line(0, 0, 126, 0)
drone.controller_draw_line(0, 0, 0, 63)
drone.controller_draw_line(126, 0, 126, 63)
drone.controller_draw_line(0, 63, 126, 63)