pinout.vvzero.com/src/zh/translate/traffic-hat.md

76 lines
1.3 KiB
Markdown
Raw Permalink Normal View History

2022-01-05 23:15:31 +08:00
<!--
---
name: Traffic HAT
class: board
type: multi
formfactor: HAT
manufacturer: Ryanteck
description: A quick and easy way to learn the basics of GPIO on a budget
github: https://github.com/PiSupply/Ryanteck/tree/master/RTK%20Traffic%20HAT
buy: https://uk.pi-supply.com/products/traffic-hat-for-raspberry-pi
image: 'traffic-hat.png'
pincount: 40
eeprom: yes
power:
'1':
'2':
ground:
'6':
'9':
'14':
'20':
'25':
'30':
'34':
'39':
pin:
'15':
name: LED1 / Green
direction: output
active: high
'16':
name: LED2 / Amber
direction: output
active: high
'18':
name: LED3 / Red
direction: output
active: high
'22':
name: Button
direction: input
active: high
'29':
name: Buzzer
direction: output
active: high
-->
# Traffic HAT
A quick and easy way to learn the basics of GPIO on a budget. All in a nice HAT.
```python
from gpiozero import TrafficHat
from time import sleep
from signal import pause
hat = TrafficHat()
# control components individually
hat.lights.green.on()
sleep(1)
hat.lights.amber.on()
sleep(1)
hat.lights.red.on()
sleep(1)
hat.buzzer.on()
sleep(1)
hat.off() # turn everything off
# set up events on button press/release
hat.button.when_pressed = hat.lights.blink
hat.button.when_released = hat.lights.off
pause()
```