Snap Lesson 11: Battery Checker
In this lesson we will learn about how to receive the battery level from the CoDrone

Request Battery Percent

 

 

  • Requests the CoDrone to send back the battery level as a percentage
  • Gives the percentage as a value from 0 to 100
We will use this block to know what the battery percentage is of the CoDrone. Then using that information we will set teh CoDrone’s LEDs to different colors to let us know what percentage the battery is at. To do this we will first need to save the battery percentage to a variable so that we can check it later. We will put this into a forever loop so that as long as the CoDrone is running we will know the current battery level.

 

Then we will add in several if statements to check to see what level the battery is at. I will divide it into 4 levels, 100 to 75, 75 to 50, 50 to 25, and 25 to 0 each level will have its own LED color. First we will just build the structure of the if statements.

 

The first category of 100 to 75 would only be when Battery is greater than 75. Then since it would only get to the next if statement (Battery greater than 50) when the first one is not true (Battery greater than 75 is not true) the only time that the code in the second if statement would run is when Battery is between 75 and 50. This works for the next if statement too. Then since the only time it would get to the last else is when Battery is less than 25, which is the last category. Now we can add in the LEDs. I will use green, yellow, flickering yellow, and then flickering red for the colors.

Activity: Low Battery Landing

The challenge is to have the CoDrone safely land when the battery is too low.

Challenge Rules:

  1. You should make a code that once the battery is really low (less than 20%) the CoDrone will stop flying and safely land.