reaction time and state of matter (#420)
* STEM0 * stem1 * STEM_soil * soil_2 * update to stem lesson * acceleration update * reaction time * update reaction and states of matter * remove make pages * stem index page * update to stem lessons * stem page update * moving docs to projects * update make * editing * code2 * complete reaction time project * states of matter * finish draft states of matter * finish draft of states of matter * make update for reaction game * update make pics for projects * index page * reaction time landing page * states of matter landing page * make reaction time * make reaction time1 * reaction time make2 * reaction time code * reaction time code2 * forms of matter make3 * states of matter make * delete stem course folder * deleting unecessary images * delete add'l images for lessons
This commit is contained in:
parent
65b2640744
commit
045a2a7694
35
docs/projects/reaction-time.md
Normal file
35
docs/projects/reaction-time.md
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
|
||||||
|
# Reaction Time
|
||||||
|
|
||||||
|
### @description A reaction time experiment made of cardboard
|
||||||
|
|
||||||
|
### ~avatar avatar
|
||||||
|
|
||||||
|
Make a reaction time experiment that responds to your body's conductivity!
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
|
https://youtu.be/DgJ-S0q0EMs
|
||||||
|
|
||||||
|
## Duration
|
||||||
|
|
||||||
|
2 Activities, approx 30-45 min each based on familiarity with the coding concepts
|
||||||
|
|
||||||
|
## Materials
|
||||||
|
|
||||||
|
* Cardboard
|
||||||
|
* Aluminum Foil
|
||||||
|
* Permanent Markers (Red and Black)
|
||||||
|
* 1 @boardname@, battery holder and 2 AAA batteries
|
||||||
|
* 4 Crocodile clips
|
||||||
|
|
||||||
|
## Activities
|
||||||
|
|
||||||
|
* [Make](/projects/reaction-time/make)
|
||||||
|
* [Code](/projects/reaction-time/code)
|
||||||
|
|
||||||
|
### ~button /projects/reaction-time/make
|
||||||
|
|
||||||
|
Let's get started!
|
||||||
|
|
||||||
|
### ~
|
319
docs/projects/reaction-time/code.md
Normal file
319
docs/projects/reaction-time/code.md
Normal file
@ -0,0 +1,319 @@
|
|||||||
|
# Code
|
||||||
|
### @description code to make the Reaction Time interactive
|
||||||
|
|
||||||
|
## Step 1: Measuring reaction time.
|
||||||
|
|
||||||
|
![](/static/mb/courses/stem/reaction_time_complete.jpg)
|
||||||
|
|
||||||
|
This lesson uses the Micro:bit to measure the reaction time of a student by completing a circuit on a board. The student will be measuring his/her reaction time in an undistracted environment and a distracted environment.
|
||||||
|
|
||||||
|
Connect each piece of foil to the appropriate pin on the Micro:bit. Note: For the experiment we will not be utilizing the P2 pin.
|
||||||
|
|
||||||
|
Test the apparatus by putting one hand on the ground pin and one hand on the P0 pin. This will complete the circuit and start the timer on the Micro:bit after a 3 second count down.
|
||||||
|
|
||||||
|
Once the timer starts, wait for the LED screen to light up and then press the Ground foil with one hand and and the P1 with the other. This will connect the circuit and shut off the timer.
|
||||||
|
|
||||||
|
The Micro:bit will then read off the time in milliseconds from when the timer starts and the circuit is completed.
|
||||||
|
|
||||||
|
|
||||||
|
## Step 2: Variables
|
||||||
|
|
||||||
|
In order for Reaction Time to follow the rules for determining the player's reaction speed, we need to add variables that will store data. Then we will assign (set) the value of the variables. We want to name the four (4) variables as follows: “start”, “end”, “false_start”, and “running”. Set the value of the variables, “start” and “end” to 0. Then set the value of the variable “false_start” and “running” to false. Modify your code so that your code looks like this.
|
||||||
|
|
||||||
|
In the code below:
|
||||||
|
- the reaction time experiment will start and end at specific times based on the player's reaction.
|
||||||
|
- the code will keep track of when the experiment is running as well as when the player has a false start in the experiment.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
let start = 0
|
||||||
|
let end = 0
|
||||||
|
let false_start = false
|
||||||
|
let running = false
|
||||||
|
running = false
|
||||||
|
false_start = false
|
||||||
|
end = 0
|
||||||
|
start = 0
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Step 3: On pin pressed
|
||||||
|
|
||||||
|
We want to register an event handler that will execute whenever the user holds the GND pin with one hand, and presses pin 0 or pin with the other hand, thus completing a circuit. When you run a script with this function in a web browser, click pins 0 or 1 in the simulator. The game will start on P0 and the P1 will detect when the player visualizes a single LED on the screen. Modify your code so that your code looks like this.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
let start = 0
|
||||||
|
let end = 0
|
||||||
|
let false_start = false
|
||||||
|
let running = false
|
||||||
|
input.onPinPressed(TouchPin.P0, () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
input.onPinPressed(TouchPin.P1, () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
running = false
|
||||||
|
false_start = false
|
||||||
|
end = 0
|
||||||
|
start = 0
|
||||||
|
|
||||||
|
```
|
||||||
|
## Step 4: Countdown timer
|
||||||
|
|
||||||
|
We want to code the countdown timer that will be displayed on pin pressed 0. We will insert three show number blocks to visually display the countdown: 3 2 1. Then we want to add a Basic block clear screen to clear the numbers from the screen. Modify your code so that your code looks like this:
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
let start = 0
|
||||||
|
let end = 0
|
||||||
|
let false_start = false
|
||||||
|
let running = false
|
||||||
|
input.onPinPressed(TouchPin.P0, () => {
|
||||||
|
basic.showNumber(3)
|
||||||
|
basic.showNumber(2)
|
||||||
|
basic.showNumber(1)
|
||||||
|
basic.clearScreen()
|
||||||
|
})
|
||||||
|
input.onPinPressed(TouchPin.P1, () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
running = false
|
||||||
|
false_start = false
|
||||||
|
end = 0
|
||||||
|
start = 0
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
* click Download to see if the code works as expected.
|
||||||
|
|
||||||
|
## Step 5: Boolean
|
||||||
|
|
||||||
|
We want to set variables, running and set false start to false. This occurs on pin 0 pressed. Those blocks represent the true and false Boolean values. A Boolean has one of two possible values: true; false.
|
||||||
|
|
||||||
|
Modify your code so that your code looks like this:
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
let start = 0
|
||||||
|
let end = 0
|
||||||
|
let false_start = false
|
||||||
|
let running = false
|
||||||
|
input.onPinPressed(TouchPin.P0, () => {
|
||||||
|
basic.showNumber(3)
|
||||||
|
basic.showNumber(2)
|
||||||
|
basic.showNumber(1)
|
||||||
|
basic.clearScreen()
|
||||||
|
running = false
|
||||||
|
false_start = false
|
||||||
|
})
|
||||||
|
input.onPinPressed(TouchPin.P1, () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
running = false
|
||||||
|
false_start = false
|
||||||
|
end = 0
|
||||||
|
start = 0
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Step 6: Begin reaction time randomly
|
||||||
|
|
||||||
|
We want to introduce the reaction time experiment if there is not a false start on pin 0 pressed. Reaction time will randomly plot a LED on the x and y coordinates. Modify your code so that your code looks like this:
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
let start = 0
|
||||||
|
let end = 0
|
||||||
|
let false_start = false
|
||||||
|
let running = false
|
||||||
|
input.onPinPressed(TouchPin.P0, () => {
|
||||||
|
basic.showNumber(3)
|
||||||
|
basic.showNumber(2)
|
||||||
|
basic.showNumber(1)
|
||||||
|
basic.clearScreen()
|
||||||
|
running = false
|
||||||
|
false_start = false
|
||||||
|
basic.pause(1000 + Math.random(2000))
|
||||||
|
})
|
||||||
|
input.onPinPressed(TouchPin.P1, () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
running = false
|
||||||
|
false_start = false
|
||||||
|
end = 0
|
||||||
|
start = 0
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Step 7: Plot LED on X, Y coordinates randomly
|
||||||
|
|
||||||
|
We want to introduce the reaction time experiment if there is not a false start. Reaction time will randomly plot a LED on the x and y coordinates. Modify your code so that your code looks like this:
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
let start = 0
|
||||||
|
let end = 0
|
||||||
|
let false_start = false
|
||||||
|
let running = false
|
||||||
|
input.onPinPressed(TouchPin.P1, () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
input.onPinPressed(TouchPin.P0, () => {
|
||||||
|
basic.showNumber(3)
|
||||||
|
basic.showNumber(2)
|
||||||
|
basic.showNumber(1)
|
||||||
|
basic.clearScreen()
|
||||||
|
running = false
|
||||||
|
false_start = false
|
||||||
|
basic.pause(1000 + Math.random(2000))
|
||||||
|
if (!(false_start)) {
|
||||||
|
start = input.runningTime()
|
||||||
|
running = true
|
||||||
|
led.stopAnimation()
|
||||||
|
basic.clearScreen()
|
||||||
|
led.plot(Math.random(5), Math.random(5))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
running = false
|
||||||
|
false_start = false
|
||||||
|
end = 0
|
||||||
|
start = 0
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Step 8: Display feedback to reaction
|
||||||
|
|
||||||
|
We want to add code to detect when the player presses the Ground foil with one hand and and the P1 with the other. This code will connect the circuit and shut off the timer. We will add code to have the Micro:bit read off the time in milliseconds from when the timer starts and the circuit is completed. This code also detects if there is a correct reaction or false start on pin 1 pressed.
|
||||||
|
|
||||||
|
We want to display one of two images on pin 1 pressed. The first image displays if the player correctly completes the circuit between GND and P1. A correct reaction occurs to complete the circuit on pin 1 pressed after the randomly generated LED appears on the screen. The seconde image displays if the player completes a circuit between GND and P1 on a false start. A false start occurs when the player completes a circuit on pin 1 pressed before the LED randomly appears on the x, y coordinates. Modify your code so that your code looks like this:
|
||||||
|
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
let start = 0
|
||||||
|
let end = 0
|
||||||
|
let false_start = false
|
||||||
|
let running = false
|
||||||
|
input.onPinPressed(TouchPin.P1, () => {
|
||||||
|
if (running) {
|
||||||
|
running = false
|
||||||
|
end = input.runningTime()
|
||||||
|
basic.showLeds(`
|
||||||
|
# # . . .
|
||||||
|
# # . . .
|
||||||
|
# # . . .
|
||||||
|
# # . . .
|
||||||
|
# # . . .
|
||||||
|
`)
|
||||||
|
basic.pause(1000)
|
||||||
|
basic.showNumber(end - start)
|
||||||
|
} else {
|
||||||
|
false_start = true
|
||||||
|
basic.showLeds(`
|
||||||
|
. . . . .
|
||||||
|
# . # . .
|
||||||
|
. # . . .
|
||||||
|
# . # . .
|
||||||
|
. . . . .
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
input.onPinPressed(TouchPin.P0, () => {
|
||||||
|
basic.showNumber(3)
|
||||||
|
basic.showNumber(2)
|
||||||
|
basic.showNumber(1)
|
||||||
|
basic.clearScreen()
|
||||||
|
running = false
|
||||||
|
false_start = false
|
||||||
|
basic.pause(1000 + Math.random(2000))
|
||||||
|
if (!(false_start)) {
|
||||||
|
start = input.runningTime()
|
||||||
|
running = true
|
||||||
|
led.stopAnimation()
|
||||||
|
basic.clearScreen()
|
||||||
|
led.plot(Math.random(5), Math.random(5))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
running = false
|
||||||
|
false_start = false
|
||||||
|
end = 0
|
||||||
|
start = 0
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Extension
|
||||||
|
|
||||||
|
After the students have finished their experiments. Have them play the game with a friend (using the P2 pin) and have competitons to see who is the quickest on the draw.
|
||||||
|
|
||||||
|
You can find the code for this below:
|
||||||
|
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
let start = 0
|
||||||
|
let end = 0
|
||||||
|
let false_start = false
|
||||||
|
let running = false
|
||||||
|
input.onPinPressed(TouchPin.P0, () => {
|
||||||
|
basic.showNumber(3)
|
||||||
|
basic.showNumber(2)
|
||||||
|
basic.showNumber(1)
|
||||||
|
basic.clearScreen()
|
||||||
|
running = false
|
||||||
|
false_start = false
|
||||||
|
basic.pause(1000 + Math.random(2000))
|
||||||
|
if (!(false_start)) {
|
||||||
|
start = input.runningTime()
|
||||||
|
running = true
|
||||||
|
led.stopAnimation()
|
||||||
|
basic.clearScreen()
|
||||||
|
led.plot(Math.random(5), Math.random(5))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
input.onPinPressed(TouchPin.P1, () => {
|
||||||
|
if (running) {
|
||||||
|
running = false
|
||||||
|
end = input.runningTime()
|
||||||
|
basic.showLeds(`
|
||||||
|
# # . . .
|
||||||
|
# # . . .
|
||||||
|
# # . . .
|
||||||
|
# # . . .
|
||||||
|
# # . . .
|
||||||
|
`)
|
||||||
|
basic.pause(1000)
|
||||||
|
basic.showNumber(end - start)
|
||||||
|
} else {
|
||||||
|
false_start = true
|
||||||
|
basic.showLeds(`
|
||||||
|
. . . . .
|
||||||
|
# . # . .
|
||||||
|
. # . . .
|
||||||
|
# . # . .
|
||||||
|
. . . . .
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
input.onPinPressed(TouchPin.P2, () => {
|
||||||
|
if (running) {
|
||||||
|
running = false
|
||||||
|
end = input.runningTime()
|
||||||
|
basic.showLeds(`
|
||||||
|
. . . # #
|
||||||
|
. . . # #
|
||||||
|
. . . # #
|
||||||
|
. . . # #
|
||||||
|
. . . # #
|
||||||
|
`)
|
||||||
|
basic.pause(1000)
|
||||||
|
basic.showNumber(end - start)
|
||||||
|
} else {
|
||||||
|
false_start = true
|
||||||
|
basic.showLeds(`
|
||||||
|
. . . . .
|
||||||
|
. . # . #
|
||||||
|
. . . # .
|
||||||
|
. . # . #
|
||||||
|
. . . . .
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
* click *Download* to see if the code works as expected.
|
15
docs/projects/reaction-time/make.md
Normal file
15
docs/projects/reaction-time/make.md
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# Make
|
||||||
|
### @description Building the reaction time experiment.
|
||||||
|
|
||||||
|
|
||||||
|
![](/static/mb/courses/stem/reaction_time_complete.jpg)
|
||||||
|
|
||||||
|
* Fold the foil squares and place them around the cardboard.
|
||||||
|
* Connect each piece of foil to the appropriate pin on the Micro:bit. Note: For the experiment we will not be utilizing the P2 pin
|
||||||
|
|
||||||
|
That's it!
|
||||||
|
|
||||||
|
### ~button /projects/reaction-time/code
|
||||||
|
Code
|
||||||
|
### ~
|
||||||
|
|
35
docs/projects/states-of-matter.md
Normal file
35
docs/projects/states-of-matter.md
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
|
||||||
|
# States of Matter
|
||||||
|
|
||||||
|
### @description A states of matter experiment made of cardboard
|
||||||
|
|
||||||
|
### ~avatar avatar
|
||||||
|
|
||||||
|
Make a states of matter experiment that responds to your micro:bit wand or micro:bit's movement!
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
|
https://youtu.be/Hdsy93yaQC0
|
||||||
|
|
||||||
|
## Duration
|
||||||
|
|
||||||
|
The activity is approx 30-45 min based on familiarity with the coding concepts
|
||||||
|
|
||||||
|
## Materials
|
||||||
|
|
||||||
|
* Cardboard
|
||||||
|
* Aluminum Foil
|
||||||
|
* Permanent Markers (Red and Black)
|
||||||
|
* 1 @boardname@, battery holder and 2 AAA batteries
|
||||||
|
* 4 Crocodile clips
|
||||||
|
|
||||||
|
## Activities
|
||||||
|
|
||||||
|
* [Make](/projects/states-of-matter/make)
|
||||||
|
* [Code](/projects/states-of-matter/code)
|
||||||
|
|
||||||
|
### ~button /projects/states-of-matter/make
|
||||||
|
|
||||||
|
Let's get started!
|
||||||
|
|
||||||
|
### ~
|
183
docs/projects/states-of-matter/code.md
Normal file
183
docs/projects/states-of-matter/code.md
Normal file
@ -0,0 +1,183 @@
|
|||||||
|
# Code
|
||||||
|
### @description code to detect States of Matter
|
||||||
|
|
||||||
|
## Step 1: Make temperature simulation
|
||||||
|
|
||||||
|
Have you ever tried to represent the states of matter? Let's try to visually represent various states of matter based on atmospheric temperatures!
|
||||||
|
|
||||||
|
### ~button /projects/states-of-matter/make
|
||||||
|
Make
|
||||||
|
### ~
|
||||||
|
|
||||||
|
|
||||||
|
## Step 2: Variables.
|
||||||
|
|
||||||
|
|
||||||
|
In order for States of Matter to follow the rules for determining the atmospheric temperature, we need to add variables that will store data. Then we will assign (set) the value of the variables. We want to name the two (2) variables as follows: “atmos_temperature” and “temperature”. Set the value of the variables to 100. Modify your code so that your code looks like this.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
let temperature = 100
|
||||||
|
let atmos_temperature = 100
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Step 3: Detect a solid.
|
||||||
|
|
||||||
|
We want to detect a solid for the atmospheric temperature. On Pin 2 Pressed, you want to represent an atmospheric temperature of 0 and scroll the message SOLID. We want to set atmos_temperature to 0 and show string as a Solid. Modify your code so that your code looks like this:
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
let temperature = 0
|
||||||
|
let atmos_temperature = 0
|
||||||
|
input.onPinPressed(TouchPin.P2, () => {
|
||||||
|
atmos_temperature = 0
|
||||||
|
basic.showString("SOLID")
|
||||||
|
})
|
||||||
|
atmos_temperature = 100
|
||||||
|
temperature = 100
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Step 4: Detect a liquid.
|
||||||
|
|
||||||
|
We want to detect a liquid for the atmospheric temperature. On Pin 1 Pressed, you want to represent an atmospheric temperature of 80 and scroll the message LIQUID. We want to set atmos_temperature to 80 and show string as a liquid. Modify your code so that your code looks like this:
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
let temperature = 0
|
||||||
|
let atmos_temperature = 0
|
||||||
|
input.onPinPressed(TouchPin.P2, () => {
|
||||||
|
atmos_temperature = 0
|
||||||
|
basic.showString("SOLID")
|
||||||
|
})
|
||||||
|
input.onPinPressed(TouchPin.P1, () => {
|
||||||
|
atmos_temperature = 80
|
||||||
|
basic.showString("LIQUID")
|
||||||
|
})
|
||||||
|
atmos_temperature = 100
|
||||||
|
temperature = 100
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
* click *Download* to see if the code works as expected.
|
||||||
|
|
||||||
|
|
||||||
|
## Step 5: Detect a gas.
|
||||||
|
|
||||||
|
We want to detect a liquid for the atmospheric temperature. On Pin 1 Pressed, you want to represent an atmospheric temperature of 80 and scroll the message LIQUID. We want to set atmos_temperature to 80 and show string as a liquid. Modify your code so that your code looks like this:
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
let atmos_temperature = 0
|
||||||
|
let temperature = 0
|
||||||
|
input.onGesture(Gesture.Shake, () => {
|
||||||
|
temperature += 50
|
||||||
|
basic.showIcon(IconNames.Triangle)
|
||||||
|
})
|
||||||
|
input.onPinPressed(TouchPin.P0, () => {
|
||||||
|
atmos_temperature = 250
|
||||||
|
basic.showString("GAS")
|
||||||
|
})
|
||||||
|
input.onPinPressed(TouchPin.P2, () => {
|
||||||
|
atmos_temperature = 0
|
||||||
|
basic.showString("SOLID")
|
||||||
|
})
|
||||||
|
input.onPinPressed(TouchPin.P1, () => {
|
||||||
|
atmos_temperature = 80
|
||||||
|
basic.showString("LIQUID")
|
||||||
|
})
|
||||||
|
atmos_temperature = 100
|
||||||
|
temperature = 100
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
* click *Download* to see if the code works as expected.
|
||||||
|
|
||||||
|
|
||||||
|
## Step 6: Increase temperature.
|
||||||
|
|
||||||
|
We want to display a change of temperature on shake. When you shake the states of matter experiment, there will be a show icon to represent an increase in temperature. Modify your code so that your code looks like this:
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
let atmos_temperature = 0
|
||||||
|
let temperature = 0
|
||||||
|
input.onGesture(Gesture.Shake, () => {
|
||||||
|
temperature += 50
|
||||||
|
basic.showIcon(IconNames.Triangle)
|
||||||
|
})
|
||||||
|
input.onPinPressed(TouchPin.P0, () => {
|
||||||
|
atmos_temperature = 250
|
||||||
|
basic.showString("GAS")
|
||||||
|
})
|
||||||
|
input.onPinPressed(TouchPin.P2, () => {
|
||||||
|
atmos_temperature = 0
|
||||||
|
basic.showString("SOLID")
|
||||||
|
})
|
||||||
|
input.onPinPressed(TouchPin.P1, () => {
|
||||||
|
atmos_temperature = 80
|
||||||
|
basic.showString("LIQUID")
|
||||||
|
})
|
||||||
|
atmos_temperature = 100
|
||||||
|
temperature = 100
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
* click Download to see if the code works as expected.
|
||||||
|
|
||||||
|
|
||||||
|
## Step 6: Display temperature change.
|
||||||
|
|
||||||
|
We want to conditionally run code depending on whether a Boolean condition is true or false. We want to display certain icons to reflect the temperature being changed on shake. We will create two condition statements. After displaying an icon, the icon will be cleared from the screen with clear screen. Then we will pause program execution for 100 milliseconds. This function is helpful to slow down the program's execution.
|
||||||
|
|
||||||
|
The first condition statement follows this logic:
|
||||||
|
- change the temperature by 20 if the temperature is less than the atmospheric temperature.
|
||||||
|
- change the temperature by -20 if the temperature is not less than the atmos_temperature.
|
||||||
|
|
||||||
|
The second condition follows this logic:
|
||||||
|
- show icon with a symbol of a solid if the temperature is less than 32 degrees.
|
||||||
|
- show icon with a sybmol of a liquid (umbrella) if the temperature is less than 212 degrees.
|
||||||
|
- show icon with a symbol of a gas if the temperature is greater than or equal to 212 degrees.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
let atmos_temperature = 0
|
||||||
|
let temperature = 0
|
||||||
|
input.onGesture(Gesture.Shake, () => {
|
||||||
|
temperature += 50
|
||||||
|
basic.showIcon(IconNames.Triangle)
|
||||||
|
})
|
||||||
|
basic.forever(() => {
|
||||||
|
if (temperature < atmos_temperature) {
|
||||||
|
temperature += 20
|
||||||
|
} else {
|
||||||
|
temperature += -20
|
||||||
|
}
|
||||||
|
if (temperature < 32) {
|
||||||
|
basic.showIcon(IconNames.Square)
|
||||||
|
} else if (temperature < 212) {
|
||||||
|
basic.showIcon(IconNames.Umbrella)
|
||||||
|
} else {
|
||||||
|
basic.showIcon(IconNames.Chessboard)
|
||||||
|
}
|
||||||
|
basic.clearScreen()
|
||||||
|
basic.pause(100)
|
||||||
|
})
|
||||||
|
input.onPinPressed(TouchPin.P0, () => {
|
||||||
|
atmos_temperature = 250
|
||||||
|
basic.showString("GAS")
|
||||||
|
})
|
||||||
|
input.onPinPressed(TouchPin.P2, () => {
|
||||||
|
atmos_temperature = 0
|
||||||
|
basic.showString("SOLID")
|
||||||
|
})
|
||||||
|
input.onPinPressed(TouchPin.P1, () => {
|
||||||
|
atmos_temperature = 80
|
||||||
|
basic.showString("LIQUID")
|
||||||
|
})
|
||||||
|
atmos_temperature = 100
|
||||||
|
temperature = 100
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
* click Download to see if the code works as expected.
|
||||||
|
|
21
docs/projects/states-of-matter/make.md
Normal file
21
docs/projects/states-of-matter/make.md
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# Make
|
||||||
|
### @description Building the states of matter experiment.
|
||||||
|
|
||||||
|
### ~avatar avatar
|
||||||
|
|
||||||
|
Turn a piece of cardboard into a detector of temperature and atmospheric temperature!
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
|
https://youtu.be/Hdsy93yaQC0
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
|
* Fold the foil squares and place them around the cardboard.
|
||||||
|
* Connect each piece of foil to the appropriate pin on the Micro:bit.
|
||||||
|
|
||||||
|
That's it!
|
||||||
|
|
||||||
|
### ~button /projects/states-of-matter/code
|
||||||
|
Code
|
||||||
|
### ~
|
Loading…
Reference in New Issue
Block a user