diff --git a/docs/device/simulator.md b/docs/device/simulator.md index f1f99a0df36..55d62927ad5 100644 --- a/docs/device/simulator.md +++ b/docs/device/simulator.md @@ -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(` + . # . # . + . # . # . + . . # . . + # # # # # + # . . . # + `) +})