This commit is contained in:
Peli de Halleux
2018-02-23 20:38:53 -08:00
17 changed files with 357 additions and 9 deletions

View File

@ -111,3 +111,25 @@
* [pause for light](/reference/sensors/color-sensor/pause-for-light)
* [color](/reference/sensors/color-sensor/color)
* [light](/reference/sensors/color-sensor/ambient-light)
* [Music](/reference/music)
* [play sound effect](/reference/music/play-sound-effect)
* [play sound effect until done](/reference/music/play-sound-effect-until-done)
* [play tone](/reference/music/play-tone)
* [ring tone](/reference/music/ring-tone)
* [stop all sounds](/reference/music/stop-all-sounds)
* [rest](/reference/music/rest)
* [change tempo by](/reference/music/change-tempo-by)
* [set tempo](/reference/music/set-tempo)
* [note frequency](/reference/music/note-frequency)
* [beat](/reference/music/beat)
* [set volume](/reference/music/set-volume)
* [Control](/reference/control)
* [Timer](/reference/control/timer)
* [seconds](/reference/control/timer/seconds)
* [millis](/reference/control/timer/millis)
* [reset](/reference/control/timer/reset)
* [pause until](/reference/control/timer/pause-until)
* [Console](/reference/console)
* [log](/reference/console/log)
* [log value](/reference/console/log-value)
* [send to screen](/reference/console/send-to-screen)

View File

@ -1,9 +1,16 @@
# Reference
```namespaces
brick.showMood(moods.sleeping);
sensors.color(null);
motors.stopAll();
brick.showMood(moods.sleeping);
```
## Advanced
```namespaces
console.log("");
control.runInParallel(function(){});
```
## See Also
@ -11,5 +18,5 @@ motors.stopAll();
[brick](/reference/brick),
[sensors](/reference/sensors),
[motors](/reference/motors),
[touch sensor](/reference/sensors/touch-sensor),
[color sensor](/reference/sensors/color-sensor)
[control](/reference/control),
[console](/reference/console)

15
docs/reference/console.md Normal file
View File

@ -0,0 +1,15 @@
# Console
Output text and data values to the console.
```cards
console.log("");
console.logValue("x", 0);
console.sendToScreen();
```
## See also
[log](/reference/console/log),
[log value](/reference/console/log-value),
[send to screen](/reference/console/send-to-screen)

View File

@ -0,0 +1,26 @@
# send To Screen
Direct the console output to go to the @boardname@ screen.
```sig
console.sendToScreen();
```
A "console" is a place for a user to see special messages from a device. It could be something connected to a serial port, a display that shows text, or even a text file. A console is typically used as a place to send information that is added to a message _log_ (a record of messages that are sent from a device). Your program can send log messages using the [console](/reference/console) functions. The MakeCode editor has a console view that lets you see the console output when your program runs in the simulator.
On the @boardname@, the screen can serve as a console too and you can make your console output go there. Before using the console log functions, set the screen as the console output location.
## Example
Direct the console output to go to the screen. Show 20 values on the screen. Use the up and down buttons to scroll through the values.
```blocks
console.sendToScreen()
for (let index = 0; index <= 20; index++) {
console.logValue("index", index)
}
```
## See also
[log](reference/console/log), [log value](/reference/console/log-value)

33
docs/reference/control.md Normal file
View File

@ -0,0 +1,33 @@
# Control
Program controls and events.
```cards
control.millis();
control.runInParallel(() => {
});
control.reset();
control.waitMicros(4);
control.deviceSerialNumber();
```
## Timer
```cards
control.timer1.reset()
control.timer1.pauseUntil(5)
control.timer1.millis()
control.timer1.seconds()
```
## Advanced #advanced
```cards
control.raiseEvent(0, 0);
control.onEvent(0, 0, () => {
});
control.assert(false, 0);
control.panic(0);
```

View File

@ -0,0 +1,8 @@
# Timer
```cards
control.timer1.reset()
control.timer1.pauseUntil(5)
control.timer1.millis()
control.timer1.seconds()
```

View File

@ -0,0 +1,25 @@
# millis
Get the amount of time counted by the timer in milliseconds.
The timer count begins from `0` when you program starts or is [reset](/reference/control/timer/reset).
## Returns
* a [number](/types/number) that is the amount of time elapsed, in milliseconds, since the timer was started or reset.
## Example
Find out how many milliseconds go by between presses of the `down` button on the brick.
```blocks
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
brick.showValue("DownButtonTime", control.timer1.millis(), 1)
control.timer1.reset()
})
```
## See also
[seconds](/reference/control/timer/seconds), [reset](/reference/control/timer/reset)

View File

@ -0,0 +1,32 @@
# pauseUntil
Pause until the timer counts up to a number of milliseconds.
```sig
control.timer1.pauseUntil(0)
```
When code in a block comes to a **pauseUntil**, it will wait until the timer count reaches the number of milliseconds you say. Code in blocks like **forever** and **runInParallel** will keep running while the current code is paused.
The time number you give is the number of milliseconds past the running timer count. If the timer is currently at `25000` milliseconds and you want to pause for `10` seconds, then use a pause time of `35000`. If you want your pause time number to match the actual wait time, then [reset](/reference/control/timer/reset) the timer first.
## Parameters
* **ms**: the [number](/types/number) of milliseconds that you want the timer to count up to. For seconds, convert to milliseconds: 100 milliseconds = 1/10 second and 1000 milliseconds = 1 second.
## Example
Pause between messages on the screen by `5` seconds.
```blocks
brick.clearScreen()
brick.showString("Testing my pause...", 1)
let startTime = control.timer1.millis()
brick.showValue("StartTime", startTime, 3)
control.timer1.pauseUntil(startTime + 5000)
brick.showValue("EndTime", control.timer1.millis() - startTime, 4)
```
## See also
[millis](/reference/control/timer/millis), [reset](/reference/control/timer/reset)

View File

@ -0,0 +1,49 @@
# reset
Reset the elapsed time of the timer back to `0`.
```sig
control.timer1.reset()
```
A timer starts counting from `0` when your program starts. It's time value always gets larger as your program runs. Maybe you want to meausure how long some task takes to finish or you want to do some action only for a little while. A timer can keep track of the time it takes to do it.
Resetting the timer sets the time value to `0` so the next time you check the time it's exactly the amount of time that has _elapsed_. Otherwise, you need to remember a start time value and then subtract it from the current time.
## Examples
### Press time
Find out how much time goes by between presses of the `enter` button on the brick.
```blocks
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
brick.showValue("PressTime", control.timer1.seconds(), 1)
control.timer1.reset()
})
```
### Difference timer
Use a difference timer and compare it to a timer that resets. Use the ``left`` button to start timing and the ``right`` button to stop.
```blocks
let startTime = 0
let timing = false
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
brick.clearScreen()
brick.showString("Starting timers...", 1)
startTime = control.timer1.seconds()
control.timer2.reset()
timing = true
})
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
if (timing) {
brick.clearScreen()
brick.showString("Timer results...", 1)
brick.showValue("timer 1", control.timer1.seconds() - startTime, 3)
brick.showValue("timer 2", control.timer2.seconds(), 4)
timing = false;
}
})
```

View File

@ -0,0 +1,25 @@
# seconds
Get the amount of time counted by the timer in seconds.
The timer count begins from `0` when you program starts or is [reset](/reference/control/timer/reset). The number of seconds returned also includes milliseconds if there is a fractional part of a second too.
## Returns
* a [number](/types/number) that is the amount of time elapsed, in seconds, since the timer was started or reset.
## Example
Find out how many seconds go by between presses of the `down` button on the brick.
```blocks
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
brick.showValue("DownButtonTime", control.timer1.seconds(), 1)
control.timer1.reset()
})
```
## See also
[millis](/reference/control/timer/millis), [reset](/reference/control/timer/reset)