Edits for step counter (#1219)
This commit is contained in:
parent
d0a40d1ae1
commit
e6593c1476
@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
![A @boardname@ attached on a foot](/static/mb/projects/step-counter.png)
|
![A @boardname@ attached on a foot](/static/mb/projects/step-counter.png)
|
||||||
|
|
||||||
This project turns the @boardname@ into a simple step-counter.
|
This project turns the @boardname@ into a simple step counter. A step counter is also known as a pedometer. Each **shake** event increments a **counter** variable. The step count is displayed on the LEDs.
|
||||||
Each **shake** event increment a **counter** variable.
|
|
||||||
|
|
||||||
## ~ hint
|
## ~ hint
|
||||||
|
|
||||||
@ -13,7 +12,7 @@ If you built a watch in the [make](/projects/watch/make) portion of the of the [
|
|||||||
|
|
||||||
## A counter
|
## A counter
|
||||||
|
|
||||||
To build a counter, we will need a variable to store the number of steps.
|
To build a counter, we'll need a variable to store the number of steps.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
let step = 0
|
let step = 0
|
||||||
@ -22,7 +21,7 @@ step = 0
|
|||||||
|
|
||||||
## Detecting a step
|
## Detecting a step
|
||||||
|
|
||||||
Assuming you attach the @boardname@ to your foot, it will get shaken up when do a step. We can use the ``||input:on shake||`` event to detect a step (it should work most of the time). Let's add the code to increment ``step`` by 1 when @boardname@ is shaken.
|
Assuming you attach the @boardname@ to your foot or ankle, it will get shaken when you take a step. We can use the ``||input:on shake||`` event to detect a step (it should notice a step most of the time). Let's add the code to increment ``step`` by `1` when the @boardname@ is shaken.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
let step = 0
|
let step = 0
|
||||||
@ -34,8 +33,7 @@ step = 0
|
|||||||
|
|
||||||
## How many steps so far?
|
## How many steps so far?
|
||||||
|
|
||||||
We want to see the number of steps at all time. In a ``||basic:forever||`` loop,
|
We want to always see how many steps were counted. In a ``||basic:forever||`` loop, we add a ``||basic:show number||`` block to display the value of ``step``.
|
||||||
we add a ``||basic:show number||`` block to display the value of ``step``.
|
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
let step = 0
|
let step = 0
|
||||||
@ -50,9 +48,7 @@ step = 0
|
|||||||
|
|
||||||
## Display lag
|
## Display lag
|
||||||
|
|
||||||
Did you notice there is a lag in the display of steps?
|
Did you notice there is a lag, or delay, in the display of steps? This is because the ``step`` value can change **while** the @boardname@ is displaying a number. To remove the lag, add ``||led:stop animation||`` after changing the value of ``step``.
|
||||||
This is because the ``step`` value can change **while** the @boardname@ is displaying a number.
|
|
||||||
To remove the lag, add ``||led:stop animation||`` after changing the value of ``step``.
|
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
let step = 0
|
let step = 0
|
||||||
|
@ -27,9 +27,9 @@ This is the _rough_ outline of the code:
|
|||||||
|
|
||||||
>When a user presses **A**, we start by determining which state we're in.
|
>When a user presses **A**, we start by determining which state we're in.
|
||||||
|
|
||||||
>If the watch is stopped, (``start time`` is 0 and this means we're in **state 1**), we start the counter and store the current time. The watch now goes from **state 1** to **state 2**.
|
>If the watch is stopped, (``start_time`` is `0` and this means we're in **state 1**), we start the counter and store the current time. The watch now goes from **state 1** to **state 2**.
|
||||||
|
|
||||||
>If the watch is running (``start time`` is not 0 and this means we're in **state 2**), we calculate the time duration and reset ``start time`` to 0. The watch goes back from **state 2** to **state 1**.
|
>If the watch is running (``start_time`` is not `0` and this means we're in **state 2**), we calculate the time duration and reset ``start_time`` to `0`. The watch goes back from **state 2** to **state 1**.
|
||||||
|
|
||||||
The ``||input:running time||`` block returns the number of **milli**-seconds elapsed since the @boardname@ was turned on. To compute the duration in seconds, we use the following formula:
|
The ``||input:running time||`` block returns the number of **milli**-seconds elapsed since the @boardname@ was turned on. To compute the duration in seconds, we use the following formula:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user