Skip to content

Activité

Audible cookie tin alarm

Intermédiaire | MakeCode | Capteur de luminosité, Son, Écran LED | Itération, Sélection

Qu'est-ce que c'est ?

Use the micro:bit’s light sensor to make an audible alarm to protect your cookies. Students will learn about selection in this fun project.

Audible cookie tin alarm

Comment ça marche

  • Le programme transforme l’écran LED du micro:bit en capteur de lumière.
  • Placez le micro:bit dans votre boîte à biscuits. Lorsque la boîte est ouverte, le capteur de lumière détecte un changement de niveau de luminosité et déclenche l'alarme.
  • The program uses an infinite loop or forever block to keep checking the light levels. Les boucles sont également appelées itérations.
  • Selection or an if then else block is used with comparison logic so that if the light level is above a certain amount, an angry face appears on the display and an audible alarm plays.
  • Appuyez sur le bouton de réinitialisation situé à l'arrière de votre micro:bit pour réinitialiser l'alarme.

Ce dont vous aurez besoin

  • un micro:bit
  • L'éditeur MakeCode
  • coupleur de piles
  • Haut-parleur et clips crocodile en option si vous utilisez un micro:bit V1

Codez votre projet

Voici les blocs dont vous avez besoin pour faire le projet - il faut maintenant les mettre ensemble.

Instructions étape par étape

  1. Ouvrez le projet pour trouver les blocs dont vous avez besoin en utilisant les boutons ci-dessus.
  2. Find the if then else block and put it inside the forever block.
  3. Find the 0 > 30 comparison block and put it onto the word ‘true’ in the if then else block.
  4. Find the light level block and put it onto the zero in the 0 > 30 comparison block.
  5. Locate the show icon (angry) block and put it in the if then else block underneath ‘if light level > 30’.
  6. Find the play melody dadadum block and put it directly underneath the show icon block.
  7. Now, whenever the light level is more than 30, your micro:bit will show an angry icon and play an alarm. But you must also tell your micro:bit what to do if the light level is not more than 30.
  8. Under ‘else’ in the if then else block, add the final clear screen block.
  9. Téléchargez le programme sur votre micro:bit, branchez un pack de piles et essayez-le!

Personnalisez-le

  • Make the alarm more or less sensitive… by adjusting the number in the comparison block. Numbers larger than 30 will require more light to trigger the alarm. Numbers smaller than 30 will require less light to trigger the alarm.
  • Change the icon… using the options in the show icon block. Which icon is most likely to scare cookie thieves away?
  • Change the melody… by using the options in the play melody block. There are 10 melodies to choose from.

Exemple de projet réalisé

Take a peek at some completed code

Projets associés

This project is part of a collection of inclusive projects with sounds and images.