pxt-calliope/olddocs/js/simulator.md

45 lines
3.2 KiB
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# Run Code in your Browser
2016-04-02 01:22:47 +02:00
Run scripts in a web browser.
2016-03-26 00:47:20 +01:00
2016-04-13 17:27:45 +02:00
While you're writing and testing your scripts, you'll mostly be running scripts in your browser by clicking the `run` button. Both the [Microsoft Block editor](/blocks/editor) and the [Touch Develop editor](/js/editor) have a `run` button above the coding area.
2016-03-26 00:47:20 +01:00
*Note*: in the Touch Develop editor, the button actually is named `run main`, reflecting the fact that execution of a Touch Develop script always beings in the `main` function
When you click `run main` in the Touch Develop editor, your code executes and the results are simulated on-screen, using an image of the @boardname@ device, like this:
2016-03-26 00:47:20 +01:00
In the picture above, [plot image](/reference/led/plot-image) create a heart image that appears on the @boardname@ simulator.
2016-03-26 00:47:20 +01:00
The @boardname@ simulator let's you...
2016-03-26 00:47:20 +01:00
* write and test code, even if you don't have a @boardname@ device
* test your code throughly before downloading and running your script on the @boardname@
2016-03-26 00:47:20 +01:00
### What does the simulator support?
The @boardname@ simulator supports the Touch Develop [functions](/js/contents) and Microsoft [blocks](/blocks/contents), including those related to the LED screen, input buttons, the compass, accelerometer, and the digital I/O pins.
2016-03-26 00:47:20 +01:00
* **LED screen**: the [LED screen](/device/screen) that appears on-screen shows you what you'll see on the @boardname@ device
2016-04-13 17:27:45 +02:00
* **input buttons**: when running code with [button is pressed](/reference/input/button-is-pressed) or [on button pressed](/reference/input/on-button-pressed) functions, click the on-screen A or B button
* **compass**: when running code that includes [compass heading](/reference/input/compass-heading), click and drag the on-screen compass needle to change the heading
2016-11-02 01:44:37 +01:00
* **accelerometer**: move your mouse over the on-screen @boardname@ device to simulate [acceleration](/reference/input/acceleration). The x and y axis values are shown on-screen.
2016-04-13 17:27:45 +02:00
* **digital pins**: you can click the on-screen digital pins (0 , 1, or 2) to turn them on or off (see [digital write pin](/reference/pins/digital-write-pin) and [digital read pin](/reference/pins/digital-read-pin) for more info).
2016-03-26 00:47:20 +01:00
**Can't see the red LEDs on the simulator?**
If you click on the white THEME button in the top right corner of the simulator, it will switch to an accessible version of the simulator, where the LEDs are displayed in blue on a white background.
### All done?
2016-11-02 01:44:37 +01:00
Once you're done writing and testing your code on the simulator, compile and run your script on your @boardname@ device. To find out how to do this, see [run scripts on the @boardname@](/device/usb).
2016-03-26 00:47:20 +01:00
2016-11-02 01:44:37 +01:00
### Simulator vs @boardname@
2016-03-26 00:47:20 +01:00
Running your scripts in a web browser is a *simulation* of how your code will run on the @boardname@ device. When you run your script on your @boardname@ device, the results may differ slightly. For example, the timing may be subtly different when your script runs on the @boardname@ device (you may need to adjust your [pause](/reference/basic/pause) functions). For this reason, be sure to test your scripts on the @boardname@ device.
2016-03-26 00:47:20 +01:00
### See also
2016-11-02 01:44:37 +01:00
[run scripts on the @boardname@](/device/usb), [Microsoft Block editor](/blocks/editor), [Touch Develop editor](/js/editor)
2016-03-26 00:47:20 +01:00