mirror of
				https://github.com/KevinMidboe/python-gpiozero.git
				synced 2025-10-29 17:50:37 +00:00 
			
		
		
		
	Update sourcevalues docs as suggested in lurch's review
This commit is contained in:
		| @@ -1,7 +1,9 @@ | ||||
| from gpiozero import LED, Button | ||||
| from time import sleep | ||||
|  | ||||
| led = LED(17) | ||||
| button = Button(2) | ||||
|  | ||||
| while True: | ||||
|     led.value = button.value | ||||
|     sleep(0.01) | ||||
|   | ||||
| @@ -4,6 +4,7 @@ from signal import pause | ||||
|  | ||||
| led = LED(4) | ||||
| btn = Button(17) | ||||
|  | ||||
| led.source = negated(btn.values) | ||||
|  | ||||
| pause() | ||||
|   | ||||
| @@ -4,5 +4,6 @@ from signal import pause | ||||
|  | ||||
| led = PWMLED(4) | ||||
| led.source = random_values() | ||||
| led.source_delay = 0.1 | ||||
|  | ||||
| pause() | ||||
|   | ||||
							
								
								
									
										13
									
								
								docs/examples/source_value_processing.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								docs/examples/source_value_processing.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| from gpiozero import Button, LED | ||||
| from signal import pause | ||||
|  | ||||
| def opposite(values): | ||||
|     for value in values: | ||||
|         yield not value | ||||
|  | ||||
| led = LED(4) | ||||
| btn = Button(17) | ||||
|  | ||||
| led.source = opposite(btn.values) | ||||
|  | ||||
| pause() | ||||
| @@ -35,14 +35,8 @@ provided, setting the device's value to each element at a rate specified in the | ||||
| .. image:: images/source_values.* | ||||
|  | ||||
| The most common use case for this is to set the source of an output device to | ||||
| the values of an input device, like the example above. It is also possible to | ||||
| set the source of an output device to the values of another output device (so | ||||
| they match): | ||||
|  | ||||
| .. literalinclude:: examples/led_button.py | ||||
|  | ||||
| A more interesting example would be a potentiometer controlling the brightness | ||||
| of an LED: | ||||
| the values of an input device, like the example above. A more interesting | ||||
| example would be a potentiometer controlling the brightness of an LED: | ||||
|  | ||||
| .. literalinclude:: examples/pwmled_pot.py | ||||
|  | ||||
| @@ -58,7 +52,7 @@ The device's values can also be processed before they are passed to the | ||||
|  | ||||
| For example: | ||||
|  | ||||
| .. literalinclude:: examples/custom_generator.py | ||||
| .. literalinclude:: examples/source_value_processing.py | ||||
|  | ||||
| Alternatively, a custom generator can be used to provide values from an | ||||
| artificial source: | ||||
| @@ -81,11 +75,11 @@ Composite devices | ||||
| ----------------- | ||||
|  | ||||
| Most devices have a ``value`` range between 0 and 1. Some have a range between | ||||
| -1 and 1 (e.g. ``Robot``). The ``value`` of a composite device is a namedtuple | ||||
| of such values. For example:: | ||||
| -1 and 1 (e.g. ``Motor``). The ``value`` of a composite device is a namedtuple | ||||
| of such values. For example, the ``Robot`` class:: | ||||
|  | ||||
|     >>> from gpiozero import Robot | ||||
|     >>> robot = Robot(left=(14, 15), right=(17, 18) | ||||
|     >>> robot = Robot(left=(14, 15), right=(17, 18)) | ||||
|     >>> robot.value | ||||
|     RobotValue(left_motor=0.0, right_motor=0.0) | ||||
|     >>> tuple(robot.value) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user