Product User’s Manual -
HAT-MAKER
8. PYTHON DEMO CODE
User can try this python demo code to control the LEDs and buzzer using push button on
Maker pHAT. Click on Menu - Programming - Python 3 (IDLE). Then click File - New File.
Write (or copy and paste) the following python code (
gist
).
MakerpHATDemo.py - /home/pi/Documents/MakerpHATDemo.py (3.5.3)
File Edit Format Run Options Window Help
from
gpiozero
import
LED, Button, Buzzer
from
time
import
sleep
import
os
LED1 = LED(17)
LED2 = LED(18)
LED3 = LED(27)
LED4 = LED(22)
LED5 = LED(25)
LED6 = LED(12)
LED7 = LED(13)
LED8 = LED(19)
SW1 = Button(21)
SW2 = Button(16)
SW3 = Button(20)
BUZZER = Buzzer(26)
NONE = 0
DECREASE = 1
INCREASE = 2
ALL_OFF = 9
ALL_ON = 10
def
beep
(times, sec):
for
x
in
range
(times):
BUZZER.on()
sleep(sec)
BUZZER.off()
sleep(sec)
def
led
(ledNumber):
if
ledNumber == 1:
LED1.on()
else
:
LED1.off()
if
ledNumber == 2:
LED2.on()
else
:
LED2.off()
if
ledNumber == 3:
LED3.on()
else
:
LED3.off()
Created by
Cytron Technologies Sdn Bhd
– All Rights Reserved
Back to