mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-12-08 20:39:01 +00:00
Update docs
This commit is contained in:
@@ -271,21 +271,21 @@ from time import sleep
|
|||||||
|
|
||||||
led = RGBLED(red=9, green=10, blue=11)
|
led = RGBLED(red=9, green=10, blue=11)
|
||||||
|
|
||||||
led.red = 255 # full red
|
led.red = 1 # full red
|
||||||
led.red = 128 # half red
|
led.red = 0.5 # half red
|
||||||
|
|
||||||
led.rgb = (0, 255, 0) # full green
|
led.rgb = (0, 1, 0) # full green
|
||||||
|
|
||||||
led.rgb = (255, 0, 255) # magenta
|
led.rgb = (1, 0, 1) # magenta
|
||||||
led.rgb = (255, 255, 0) # yellow
|
led.rgb = (1, 1, 0) # yellow
|
||||||
led.rgb = (0, 255, 100) # cyan
|
led.rgb = (0, 1, 1) # cyan
|
||||||
led.rgb = (255, 255, 255) # white
|
led.rgb = (1, 1, 1) # white
|
||||||
|
|
||||||
led.rgb = (0, 0, 0) # off
|
led.rgb = (0, 0, 0) # off
|
||||||
|
|
||||||
# slowly increase intensity of blue
|
# slowly increase intensity of blue
|
||||||
for n in range(256):
|
for n in range(100):
|
||||||
led.blue += 1
|
led.blue += 0.01
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -439,7 +439,7 @@ pir.when_no_motion = robot.stop
|
|||||||
|
|
||||||
## Potentiometer
|
## Potentiometer
|
||||||
|
|
||||||
Continually print the value of a potentiometer (values between 0 and 1023):
|
Continually print the value of a potentiometer (values between 0 and 1):
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from gpiozero import MCP3008
|
from gpiozero import MCP3008
|
||||||
@@ -457,16 +457,13 @@ values to make up the colour of the LED:
|
|||||||
```python
|
```python
|
||||||
from gpiozero import RGBLED, MCP3008
|
from gpiozero import RGBLED, MCP3008
|
||||||
|
|
||||||
def read_pot(channel):
|
|
||||||
with MCP3008(channel=channel) as pot:
|
|
||||||
return 255 * pot.read() / 1023
|
|
||||||
|
|
||||||
led = RGBLED(red=2, green=3, blue=4)
|
led = RGBLED(red=2, green=3, blue=4)
|
||||||
|
red_pot = MCP3008(channel=0)
|
||||||
|
green_pot = MCP3008(channel=1)
|
||||||
|
blue_pot = MCP3008(channel=2)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
red = read_pot(0)
|
led.red = red_pot.value
|
||||||
green = read_pot(1)
|
led.green = green_pot.value
|
||||||
blue = read_pot(2)
|
led.blue = blue_pot.value
|
||||||
led.rgb = (red, green, blue)
|
|
||||||
print(red, green, blue)
|
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user