pxt-calliope/docs/lessons/prank-wifi/activity.md

142 lines
3.0 KiB
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# prank wifi challenges
2016-06-02 06:19:16 +02:00
create a fake wifi app to trick your friends.
2016-03-26 00:47:20 +01:00
## Before we get started
2016-03-31 02:15:42 +02:00
Complete the following exercise. Your code should look like this:
2016-03-26 00:47:20 +01:00
2016-03-31 02:15:42 +02:00
```blocks
2016-03-26 00:47:20 +01:00
basic.showString("Check Wifi", 150)
basic.forever(() => {
2016-04-01 01:39:32 +02:00
let xAccel = Math.abs(input.acceleration(Dimension.X))
let yAccel = Math.abs(input.acceleration(Dimension.Y))
let zAccel = Math.abs(input.acceleration(Dimension.Z))
2016-03-26 00:47:20 +01:00
let sum = xAccel + yAccel + zAccel
if (sum < 1400) {
2016-04-01 01:39:32 +02:00
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. # # . .
# # # . .
`)
2016-03-26 00:47:20 +01:00
} else if (sum >= 1400 && sum < 1680) {
2016-04-01 01:39:32 +02:00
basic.showLeds(`
. . . . .
. . . # .
. . # # .
. # # # .
# # # # .
`)
} else if (sum >= 1680) {
basic.showLeds(`
. . . . .
. . . . .
. . . . .
. . . . .
# . . . .
`)
2016-03-26 00:47:20 +01:00
}
})
2016-04-01 01:39:32 +02:00
2016-03-26 00:47:20 +01:00
```
## Challenge 1
2016-03-26 00:47:20 +01:00
What if wanted to show the maximum connectivity of wifi instead of just 1, 3, or 4 bars?
Let's start by changing the first **IF** statement to `if sum <1200`.
2016-03-31 02:15:42 +02:00
Edit this line: if sum is greater than 1400 then just click on the `1400` and backspace until you can add your own number of `1200`.
2016-03-26 00:47:20 +01:00
2016-03-31 02:15:42 +02:00
```blocks
2016-03-26 00:47:20 +01:00
basic.showString("Check Wifi", 150)
basic.forever(() => {
2016-04-01 01:39:32 +02:00
let xAccel1 = Math.abs(input.acceleration(Dimension.X))
2016-04-01 01:54:51 +02:00
let yAccel1 = Math.abs(input.acceleration(Dimension.Y))
let zAccel1 = Math.abs(input.acceleration(Dimension.Z))
2016-03-26 00:47:20 +01:00
let sum1 = xAccel1 + yAccel1 + zAccel1
if (sum1 < 1200) {
2016-04-01 01:54:51 +02:00
basic.showLeds(`
2016-03-26 00:47:20 +01:00
. . . . .
. . . . .
. . # . .
. # # . .
# # # . .
`)
} else if (sum1 >= 1400 && sum1 < 1680) {
2016-04-01 01:54:51 +02:00
basic.showLeds(`
2016-03-26 00:47:20 +01:00
. . . . .
. . . # .
. . # # .
. # # # .
# # # # .
`)
}
else if (sum1 >= 1680) {
2016-04-01 01:54:51 +02:00
basic.showLeds(`
2016-03-26 00:47:20 +01:00
. . . . .
. . . . .
. . . . .
. . . . .
# . . . .
`)
}
})
```
## Challenge 2
2016-03-26 00:47:20 +01:00
Let's add an **IF** at the bottom of your code that checks to see if `sum >= to 1200` **and** if `sum <1400`
2016-03-31 02:15:42 +02:00
```blocks
2016-03-26 00:47:20 +01:00
basic.showString("Check Wifi", 150)
basic.forever(() => {
2016-04-01 01:52:44 +02:00
let xAccel2 = Math.abs(input.acceleration(Dimension.X))
let yAccel2 = Math.abs(input.acceleration(Dimension.Y))
let zAccel2 = Math.abs(input.acceleration(Dimension.Z))
2016-03-26 00:47:20 +01:00
let sum2 = xAccel2 + yAccel2 + zAccel2
if (sum2 < 1200) {
2016-04-01 01:54:51 +02:00
basic.showLeds(`
2016-03-26 00:47:20 +01:00
. . . . .
. . . . .
. . # . .
. # # . .
# # # . .
`)
} else if (sum2 >= 1400 && sum2 < 1680) {
2016-04-01 01:52:44 +02:00
basic.showLeds(`
2016-03-26 00:47:20 +01:00
. . . . .
. . . # .
. . # # .
. # # # .
# # # # .
`)
}
else if (sum2 >= 1680) {
2016-04-01 01:52:44 +02:00
basic.showLeds(`
2016-03-26 00:47:20 +01:00
. . . . .
. . . . .
. . . . .
. . . . .
# . . . .
`)
}
if (sum2 >= 1200 && sum2 < 1400) {
2016-04-01 01:52:44 +02:00
basic.showLeds(`
2016-03-26 00:47:20 +01:00
. . . . #
. . . # #
. . # # #
. # # # #
# # # # #
2016-04-01 02:25:22 +02:00
`)
2016-03-26 00:47:20 +01:00
}
})
```
## Challenge 3
2016-03-26 00:47:20 +01:00
2016-04-01 01:52:44 +02:00
Now it's your turn! Be creative and change the Wifi meter images to your own wifi image you're sure will prank your friends by editing the lines that call `showLeds()`.
2016-03-26 00:47:20 +01:00