2016-07-28 00:48:51 +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
|
2016-10-27 06:52:01 +08:00
|
|
|
url: https://ryanteck.uk/hats/1-traffichat-0635648607122.html
|
|
|
|
buy: https://ryanteck.uk/hats/1-traffichat-0635648607122.html
|
2016-07-28 00:48:51 +08:00
|
|
|
image: 'traffic-hat.png'
|
|
|
|
pincount: 40
|
|
|
|
eeprom: yes
|
2016-10-22 23:26:45 +08:00
|
|
|
power:
|
|
|
|
'1':
|
|
|
|
'2':
|
|
|
|
ground:
|
|
|
|
'6':
|
|
|
|
'9':
|
|
|
|
'14':
|
|
|
|
'20':
|
|
|
|
'25':
|
|
|
|
'30':
|
|
|
|
'34':
|
|
|
|
'39':
|
2016-07-28 00:48:51 +08:00
|
|
|
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
|
2016-10-22 23:26:45 +08:00
|
|
|
from gpiozero import TrafficHat
|
2016-07-28 00:48:51 +08:00
|
|
|
from time import sleep
|
2016-10-22 23:26:45 +08:00
|
|
|
from signal import pause
|
2016-07-28 00:48:51 +08:00
|
|
|
|
2016-10-22 23:26:45 +08:00
|
|
|
hat = TrafficHat()
|
2016-07-28 00:48:51 +08:00
|
|
|
|
2016-10-22 23:26:45 +08:00
|
|
|
# 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
|
2016-07-28 00:48:51 +08:00
|
|
|
|
2016-10-22 23:26:45 +08:00
|
|
|
# set up events on button press/release
|
|
|
|
hat.button.when_pressed = hat.lights.blink
|
|
|
|
hat.button.when_released = hat.lights.off
|
2016-07-28 00:48:51 +08:00
|
|
|
|
2016-10-22 23:26:45 +08:00
|
|
|
pause()
|
2016-07-28 00:48:51 +08:00
|
|
|
```
|