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
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:
- You should make a code that once the battery is really low (less than 20%) the CoDrone will stop flying and safely land.