color sensor examples (#894)
* tank zigzag * reflected light measure * adding links * added reflected light calibration * updated summary
This commit is contained in:
		@@ -19,11 +19,14 @@
 | 
			
		||||
    * [What Animal Am I?](/tutorials/what-animal-am-i)
 | 
			
		||||
    * [Music Brick](/tutorials/music-brick)
 | 
			
		||||
    * [Run Motors](/tutorials/run-motors)
 | 
			
		||||
    * [Tank ZigZag](/tutorials/tank-zigzag)
 | 
			
		||||
    * [Touch to Run](/tutorials/touch-to-run)
 | 
			
		||||
    * [Touch Sensor Values](/tutorials/touch-sensor-values)
 | 
			
		||||
    * [What Color?](/tutorials/what-color)
 | 
			
		||||
    * [Line Following](/tutorials/line-following)
 | 
			
		||||
    * [Red Light, Green Light](/tutorials/redlight-greenlight)
 | 
			
		||||
    * [Reflected Light Measure](/tutorials/reflected-light-measure)
 | 
			
		||||
    * [Reflected Light Calibration](/tutorials/reflected-light-calibration)
 | 
			
		||||
    * [Object Near?](/tutorials/object-near)
 | 
			
		||||
    * [Security Alert](/tutorials/security-alert)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								docs/static/tutorials/reflected-light-calibration.png
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								docs/static/tutorials/reflected-light-calibration.png
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 7.0 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								docs/static/tutorials/reflected-light-measure.png
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								docs/static/tutorials/reflected-light-measure.png
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 12 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								docs/static/tutorials/tank-zigzag.png
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								docs/static/tutorials/tank-zigzag.png
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 19 KiB  | 
@@ -21,6 +21,18 @@
 | 
			
		||||
  "cardType": "tutorial",
 | 
			
		||||
  "url":"/tutorials/redlight-greenlight",
 | 
			
		||||
  "imageUrl":"/static/tutorials/redlight-greenlight.png"
 | 
			
		||||
}, {
 | 
			
		||||
  "name": "Reflected Light Measure",
 | 
			
		||||
  "description": "Teach the sensor what light or dark is.",
 | 
			
		||||
  "cardType": "example",
 | 
			
		||||
  "url":"/tutorials/reflected-light-measure",
 | 
			
		||||
  "imageUrl":"/static/tutorials/reflected-light-measure.png"
 | 
			
		||||
}, {
 | 
			
		||||
  "name": "Reflected Light Calibration",
 | 
			
		||||
  "description": "Use the auto-calibration feature to setup the dark and bright values.",
 | 
			
		||||
  "cardType": "example",
 | 
			
		||||
  "url":"/tutorials/reflected-light-calibration",
 | 
			
		||||
  "imageUrl":"/static/tutorials/reflected-light-calibration.png"
 | 
			
		||||
}]
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,12 @@
 | 
			
		||||
  "cardType": "tutorial",
 | 
			
		||||
  "url":"/tutorials/run-motors",
 | 
			
		||||
  "imageUrl":"/static/tutorials/run-motors.png"
 | 
			
		||||
}, {
 | 
			
		||||
  "name": "Tank ZigZag",
 | 
			
		||||
  "description": "Use the tank block to keep motors in sync.",
 | 
			
		||||
  "cardType": "example",
 | 
			
		||||
  "url":"/tutorials/tank-zigzag",
 | 
			
		||||
  "imageUrl":"/static/tutorials/tank-zigzag.png"
 | 
			
		||||
}]
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										24
									
								
								docs/tutorials/reflected-light-calibration.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								docs/tutorials/reflected-light-calibration.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
# Reflected light calibration
 | 
			
		||||
 | 
			
		||||
The ``calibrateLight`` blocks allows you to calibrate the reflected light of the color sensor in one block. Start the block and move the sensor over the dark and bright surface; then stop moving it.
 | 
			
		||||
 | 
			
		||||
```blocks
 | 
			
		||||
sensors.color3.onLightDetected(LightIntensityMode.Reflected, Light.Dark, function () {
 | 
			
		||||
    brick.showString("dark", 2)
 | 
			
		||||
})
 | 
			
		||||
sensors.color3.onLightDetected(LightIntensityMode.Reflected, Light.Bright, function () {
 | 
			
		||||
    brick.showString("bright", 2)
 | 
			
		||||
})
 | 
			
		||||
console.sendToScreen()
 | 
			
		||||
console.log("move color sensor")
 | 
			
		||||
console.log("over DARK and BRIGHT color")
 | 
			
		||||
console.log("and stop moving when done")
 | 
			
		||||
console.log("press ENTER when ready")
 | 
			
		||||
brick.buttonEnter.pauseUntil(ButtonEvent.Pressed)
 | 
			
		||||
sensors.color3.calibrateLight(LightIntensityMode.Reflected)
 | 
			
		||||
brick.showValue("dark", sensors.color3.threshold(Light.Dark), 4)
 | 
			
		||||
brick.showValue("bright", sensors.color3.threshold(Light.Bright), 5)
 | 
			
		||||
forever(function () {
 | 
			
		||||
    brick.showValue("reflected light", sensors.color3.light(LightIntensityMode.Reflected), 1)
 | 
			
		||||
})
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										29
									
								
								docs/tutorials/reflected-light-measure.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								docs/tutorials/reflected-light-measure.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
# Reflected light measure
 | 
			
		||||
 | 
			
		||||
This example uses a color sensor to measure the reflected light on the dark and light surface
 | 
			
		||||
and set the light/dark thresholds.
 | 
			
		||||
 | 
			
		||||
```blocks
 | 
			
		||||
sensors.color3.onLightDetected(LightIntensityMode.Reflected, Light.Dark, function () {
 | 
			
		||||
    brick.showString("dark", 2)
 | 
			
		||||
})
 | 
			
		||||
sensors.color3.onLightDetected(LightIntensityMode.Reflected, Light.Bright, function () {
 | 
			
		||||
    brick.showString("bright", 2)
 | 
			
		||||
})
 | 
			
		||||
console.sendToScreen()
 | 
			
		||||
console.log("move color sensor")
 | 
			
		||||
console.log("over DARK color")
 | 
			
		||||
console.log("press ENTER when ready")
 | 
			
		||||
brick.buttonEnter.pauseUntil(ButtonEvent.Pressed)
 | 
			
		||||
sensors.color3.setThreshold(Light.Dark, sensors.color3.light(LightIntensityMode.Reflected) + 5)
 | 
			
		||||
console.logValue("dark", sensors.color3.threshold(Light.Dark))
 | 
			
		||||
console.log("move color sensor")
 | 
			
		||||
console.log("over BRIGHT color")
 | 
			
		||||
console.log("press ENTER when ready")
 | 
			
		||||
brick.buttonEnter.pauseUntil(ButtonEvent.Pressed)
 | 
			
		||||
sensors.color3.setThreshold(Light.Bright, sensors.color3.light(LightIntensityMode.Reflected) - 5)
 | 
			
		||||
console.logValue("bright", sensors.color3.threshold(Light.Bright))
 | 
			
		||||
forever(function () {
 | 
			
		||||
    brick.showValue("reflected light", sensors.color3.light(LightIntensityMode.Reflected), 1)
 | 
			
		||||
})
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										17
									
								
								docs/tutorials/tank-zigzag.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								docs/tutorials/tank-zigzag.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
# Tank ZigZag
 | 
			
		||||
 | 
			
		||||
This example shows how to use the [tank](/reference/motors/tank) block to keep the speed of 2 large motors synchronized. In this example, a [EV3 Driving Base](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-rem-driving-base-79bebfc16bd491186ea9c9069842155e.pdf)
 | 
			
		||||
) will move on a zig zag pattern.
 | 
			
		||||
 | 
			
		||||
```blocks
 | 
			
		||||
/**
 | 
			
		||||
 * Use the tank block to keep large motors synched. 
 | 
			
		||||
 Use this code with a EV3 driving base.
 | 
			
		||||
 */
 | 
			
		||||
forever(function () {
 | 
			
		||||
    brick.showImage(images.eyesMiddleRight)
 | 
			
		||||
    motors.largeBC.tank(50, 10, 2, MoveUnit.Rotations)
 | 
			
		||||
    brick.showImage(images.eyesMiddleLeft)
 | 
			
		||||
    motors.largeBC.tank(10, 50, 2, MoveUnit.Rotations)
 | 
			
		||||
})
 | 
			
		||||
```
 | 
			
		||||
		Reference in New Issue
	
	Block a user