Page 157 - KEC Khaitan C5 Flipbook
P. 157

Forever Block:

 HANDS-ON PROJECT    Drag the forever block from the basic category.
                   Attach the show number stepCount block to continuously display the count.
 PROJECT NAME: Step Counter Gadget with Micro:Bit  Step 2: Testing the Step Counter

 Objective:
                 Verify Motion Detection:
   Design and build a step counter using Microsoft MakeCode for Micro:bit.
                   Shake the Micro:bit gently to simulate walking.
   Program the Micro:bit  to  detect  motion,  count  steps,  and show the total  on its  LED
 screen.           Ensure the step count increments correctly on the LED screen.
                 Debugging:
   Learn how to use sensors, variables, and loops through hands-on coding.
                   If the counter doesn’t update, check the sensitivity of the accelerometer.
 Step-by-Step Instructions
                   Ensure the on shake block is properly configured.
 Step 1: Setting Up the Micro:bit Program
                   Try different shaking intensities to ensure accurate detection.
 Open MakeCode Editor:    Test the reset and display functions to confirm all buttons work correctly.

   Go to MakeCode for Micro:bit.  Step 3: Enhancing the Step Counter

   Start a new project and name it “Step Counter.”
                 Additional Features:
 Design the Code:  Add a Reset Button to Clear the Step Count:


   Use blocks to:     Button A Reset:
   o  Detect motion using the Micro:bit’s built-in accelerometer.    o  Drag the on button A pressed block.

   o  Count steps using a variable.    o  Attach the set stepCount to 0 block.

   o  Display the step count on the LED screen.  Button B to Display Count Temporarily:
                   Drag the on button B pressed block.
 Basic Blocks to Include:
                   Attach the show number stepCount block to display the count temporarily.
   On Start Block: Initializes the step count to zero.
                 Improve Display:
   On Shake Block: Increases the step count when the Micro:bit is shaken.
                   Add animations or icons to make the counter more engaging:
   Forever Block: Continuously displays the step count.
                   o  Use the basic.showIcon() block to display a smiley face after every increment.
 Example Code:   Milestone Check:

 On Start:         Flash a congratulatory message when a milestone is reached (e.g., 10 steps):

   Create a variable stepCount and set it to 0.    o  Drag the if block from the logic category.

   Drag the on start block and attach the set stepCount to 0 block.    o  Add a comparison stepCount % 10 == 0 to check for milestones.
 On Shake:         o  Attach a basic.showString("Great Job!") block to display a message.

   Drag the on shake block from the input category.  Example: If the step count reaches 10, display 'Great Job!' on the screen.

   Attach the change stepCount by 1 block to increment the counter.    Try adding more milestones (20, 50, etc.) for long-term use.



                                                                                              Maker with Micro:bit  155
   152   153   154   155   156   157   158   159   160   161   162