BBC micro:bit – Automated Car Park Display

car-park-signOur aim is to use the BBC micro:bit to create an automated Car Park Display to inform drivers of the number of empty spaces left in a car park.

Our system should:

  • Be initialised with the number of available spaces in the car park set to 20 and the car park will be empty when the program is started.
  • When the car park is empty the micro:bit should display a scrolling message saying “Car park is empty”
  • car-park-empty

  • To enter the car park, the driver has to press the A button of the micro:bit. The display should then changes to calculate and display the number of empty spaces left: e.g. Scrolling text : “15 spaces left”.
  • car-park-15-spaces-left

  • When a car leaves the car park, they will press the B button of the micro:bit. The display should then changes to refresh the number of empty spaces left.
  • If the car park is full, the micro:bit should display the scrolling text: “No entry – Car park is full”. Drivers should not be able to enter the car park. Instead, should the A button be pressed the display should say “No entry – Car park is full”.
  • car-park-no-entry

Use the microbit.org website to get started!

Solution

We will complete this project in 4 blocks of code.

First let’s initialise two variables:

  • maxCapacity to store the total number of spaces of the car park. (e.g. 20)
  • emptySpaces to store the total number of empty spaces of the car park. To start with we will assume the car par is empty so we can set emptySpaces to the same value as maxCapacity.

Then we will decrement the number of empty spaces by 1, everytime the A button is being pressed. (A car enters the car park), making sure that we only let cars in if the number of empty spaces is greater than 0. (There is at least on empty space).

Using a similar approach, we will increment the number of empty spaces by 1 everytime the B button is pressed (A car leaves the car park)

Finally, depending on the number of empty spaces in the car park, we will display the relevant message as scrolling text to inform users of the number of empty spaces in the car park.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 4.3 / 5. Vote count: 39

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: