Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A Virtual Pet #4631

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 107 additions & 25 deletions docs/device/simulator.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,107 @@
# Simulator

The JavaScript simulator allows you to test and execute most BBC micro:bit programs in the browser.
It allows you to emulate sensor data or user interactions.

```sim
input.onButtonPressed(Button.A, () => {
basic.showString("A");
});
input.onButtonPressed(Button.B, () => {
basic.showString("B");
});
input.onPinPressed(TouchPin.P0, () => {
basic.showString("0");
});
input.onPinPressed(TouchPin.P1, () => {
basic.showString("1");
});
input.onPinPressed(TouchPin.P2, () => {
basic.showString("2");
});
input.temperature()
input.compassHeading()
input.lightLevel()
```
input.onPinPressed(TouchPin.P0, function () {
Pin0 = ["Activated"]
Pin1 = ["Deactivated"]
Pin2 = ["Deactivated"]
})
input.onButtonPressed(Button.A, function () {
Mood = ["Happy"]
basic.showLeds(`
. # . # .
. # . # .
. . # . .
# . . . #
# # # # #
`)
basic.pause(50000)
Mood = ["Sad"]
basic.showLeds(`
. # . # .
. # . # .
. . # . .
# # # # #
# . . . #
`)
})
input.onPinPressed(TouchPin.P2, function () {
Pin1 = ["Deactivated"]
Pin0 = ["Deactivated"]
Pin2 = ["Activated"]
})
input.onButtonPressed(Button.B, function () {
Mood = ["Really Happy"]
basic.showLeds(`
. . . . .
# # . # #
. . # . .
# . . . #
# # # # #
`)
basic.pause(5000)
Mood = ["Happy"]
basic.showLeds(`
. # . # .
. # . # .
. . # . .
# . . . #
# # # # #
`)
basic.pause(50000)
Mood = ["Sad"]
basic.showLeds(`
. # . # .
. # . # .
. . # . .
# # # # #
# . . . #
`)
})
input.onPinPressed(TouchPin.P1, function () {
Pin1 = ["Activated"]
Pin0 = ["Deactivated"]
Pin2 = ["Deactivated"]
})
let Mood: string[] = []
let Pin2: string[] = []
let Pin1: string[] = []
let Pin0: string[] = []
let Status = ["Preparing..."]
basic.showString("LOADING ASSETS...")
servos.P2.stop()
Pin0 = ["Activated"]
Pin1 = ["Deactivated"]
Pin2 = ["Deactivated"]
Mood = ["None"]
pins.digitalWritePin(DigitalPin.P0, 1)
Status = ["Setting up..."]
basic.showString("STARTING PROGRAM...")
basic.pause(randint(1000, 5000))
pins.digitalWritePin(DigitalPin.P0, 0)
pins.digitalWritePin(DigitalPin.P1, 1)
Pin0 = ["Deactivated"]
Pin1 = ["Activated"]
Pin2 = ["Deactivated"]
Status = ["Loading..."]
basic.showString("INITIATING...")
Mood = ["Happy"]
Status = ["Running..."]
basic.showLeds(`
. # . # .
. # . # .
. . # . .
# . . . #
# # # # #
`)
basic.forever(function () {
servos.P2.run(100)
})
loops.everyInterval(20000, function () {
basic.pause(50000)
Mood = ["Sad"]
basic.showLeds(`
. # . # .
. # . # .
. . # . .
# # # # #
# . . . #
`)
})