Example overrides for 'control' api docs (#352)
* Add 'playSound' api docs * Example overrides for 'control' api docs
This commit is contained in:
		
				
					committed by
					
						
						Peli de Halleux
					
				
			
			
				
	
			
			
			
						parent
						
							fcba14aae1
						
					
				
				
					commit
					eb45a76928
				
			
							
								
								
									
										12
									
								
								docs/reference/control/assert.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								docs/reference/control/assert.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
			
		||||
# @extends
 | 
			
		||||
 | 
			
		||||
## Example #example
 | 
			
		||||
 | 
			
		||||
Stop the program if the gyro dectects an angle greater than 45 degrees.
 | 
			
		||||
 | 
			
		||||
```blocks
 | 
			
		||||
forever(function () {
 | 
			
		||||
    control.assert(sensors.gyro2.angle() > 45, 15)
 | 
			
		||||
    pause(300)
 | 
			
		||||
})
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										9
									
								
								docs/reference/control/device-serial-number.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								docs/reference/control/device-serial-number.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
# @extends
 | 
			
		||||
 | 
			
		||||
## Example #example
 | 
			
		||||
 | 
			
		||||
Log the device serial number to the console.
 | 
			
		||||
 | 
			
		||||
```blocks
 | 
			
		||||
console.logValue("serialnumber", control.deviceSerialNumber());
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										25
									
								
								docs/reference/control/on-event.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								docs/reference/control/on-event.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
# @extends
 | 
			
		||||
 | 
			
		||||
# Example #example
 | 
			
		||||
 | 
			
		||||
Register two events coming from source `22`. Make the brick status light up  when
 | 
			
		||||
the events of `0` and `1` are _raised_.
 | 
			
		||||
 | 
			
		||||
```blocks
 | 
			
		||||
const statusLighter = 22;
 | 
			
		||||
 | 
			
		||||
control.runInParallel(() => {
 | 
			
		||||
    for (let i = 0; i < 2; i++) {
 | 
			
		||||
        pause(1000);
 | 
			
		||||
        control.raiseEvent(statusLighter, i);
 | 
			
		||||
    }
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
control.onEvent(statusLighter, 0, () => {
 | 
			
		||||
    brick.setStatusLight(StatusLight.OrangePulse)
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
control.onEvent(statusLighter, 1, () => {
 | 
			
		||||
    brick.setStatusLight(StatusLight.GreenPulse)
 | 
			
		||||
})
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										13
									
								
								docs/reference/control/panic.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								docs/reference/control/panic.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
			
		||||
# @extends
 | 
			
		||||
 | 
			
		||||
## Example #example
 | 
			
		||||
 | 
			
		||||
Send a 'code red' error that you created to the error display if the brick crashes into a wall.
 | 
			
		||||
 | 
			
		||||
```blocks
 | 
			
		||||
let codeRed = 1
 | 
			
		||||
let codeBlue = 2
 | 
			
		||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
 | 
			
		||||
    control.panic(codeRed)	
 | 
			
		||||
})
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										25
									
								
								docs/reference/control/raise-event.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								docs/reference/control/raise-event.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
# @extends
 | 
			
		||||
 | 
			
		||||
# Example #example
 | 
			
		||||
 | 
			
		||||
Register two events coming from source `22`. Make the brick status light up  when
 | 
			
		||||
the events of `0` and `1` are _raised_.
 | 
			
		||||
 | 
			
		||||
```blocks
 | 
			
		||||
const statusLighter = 22;
 | 
			
		||||
 | 
			
		||||
control.runInParallel(() => {
 | 
			
		||||
    for (let i = 0; i < 2; i++) {
 | 
			
		||||
        pause(1000);
 | 
			
		||||
        control.raiseEvent(statusLighter, i);
 | 
			
		||||
    }
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
control.onEvent(statusLighter, 0, () => {
 | 
			
		||||
    brick.setStatusLight(StatusLight.OrangePulse)
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
control.onEvent(statusLighter, 1, () => {
 | 
			
		||||
    brick.setStatusLight(StatusLight.GreenPulse)
 | 
			
		||||
})
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										61
									
								
								docs/reference/control/run-in-parallel.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								docs/reference/control/run-in-parallel.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,61 @@
 | 
			
		||||
# @extends
 | 
			
		||||
 | 
			
		||||
## Separate tasks #tasks
 | 
			
		||||
 | 
			
		||||
As an example, you could have a small task that checks the battery level and gives a warning when it drops below 15 percent. This is placed inside a ``||control:run in parallel||`` block:
 | 
			
		||||
 | 
			
		||||
```block
 | 
			
		||||
let powerCheck = false;
 | 
			
		||||
 | 
			
		||||
control.runInParallel(() => {
 | 
			
		||||
    while (!powerCheck) {
 | 
			
		||||
        if (brick.batteryLevel() <= 15) {
 | 
			
		||||
            brick.setStatusLight(StatusLight.RedFlash)
 | 
			
		||||
            powerCheck = true;
 | 
			
		||||
        } else {
 | 
			
		||||
            pause(5000);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
})
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
The code the main program just drives the brick in a constant pattern until the battery check in the parallel task says that the battery level is too low.
 | 
			
		||||
 | 
			
		||||
```block
 | 
			
		||||
let powerCheck = false;
 | 
			
		||||
while (!powerCheck) {
 | 
			
		||||
    motors.largeBC.tank(50, 50, 5, MoveUnit.Seconds)
 | 
			
		||||
    motors.largeBC.steer(5, 50, 6, MoveUnit.Rotations)
 | 
			
		||||
}
 | 
			
		||||
motors.stopAll()
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## #example
 | 
			
		||||
 | 
			
		||||
Tank the brick in a pattern until the battery warning variable is set. Have a separate task check the battery level and set a warning variable when the level is below `5` percent.
 | 
			
		||||
 | 
			
		||||
```blocks
 | 
			
		||||
let powerCheck = false;
 | 
			
		||||
 | 
			
		||||
control.runInParallel(() => {
 | 
			
		||||
    while (!powerCheck) {
 | 
			
		||||
        if (brick.batteryLevel() < 5) {
 | 
			
		||||
            powerCheck = true;
 | 
			
		||||
        } else {
 | 
			
		||||
            pause(5000);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
while (!powerCheck) {
 | 
			
		||||
    motors.largeBC.tank(20, 20, 5, MoveUnit.Seconds)
 | 
			
		||||
    motors.largeBC.steer(15, 20, 6, MoveUnit.Rotations)
 | 
			
		||||
    motors.largeBC.tank(40, 40, 5, MoveUnit.Seconds)
 | 
			
		||||
    motors.largeBC.steer(-10, 20, 3, MoveUnit.Rotations)
 | 
			
		||||
}
 | 
			
		||||
motors.stopAll()
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## See also #seealso
 | 
			
		||||
 | 
			
		||||
[forever](/reference/loops/forever)
 | 
			
		||||
							
								
								
									
										17
									
								
								docs/reference/control/wait-micros.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								docs/reference/control/wait-micros.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
# @extends
 | 
			
		||||
 | 
			
		||||
## Example #example
 | 
			
		||||
 | 
			
		||||
Use the a wait and the timer to generate a crazy number.
 | 
			
		||||
 | 
			
		||||
```blocks
 | 
			
		||||
let crazy = 0
 | 
			
		||||
for (let i = 0; i < 100; i++) {
 | 
			
		||||
    control.waitMicros(100)
 | 
			
		||||
    crazy = control.millis()
 | 
			
		||||
    crazy += control.deviceSerialNumber()
 | 
			
		||||
    if (crazy != 0) {
 | 
			
		||||
        crazy = crazy / 1000000
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
		Reference in New Issue
	
	Block a user