import explorerhat
from time import sleep
explorerhat.output.one.on()
sleep(3)
explorerhat.output.one.off()
Additionally the following methods are supported
toggle() | Changes the output to its opposite state |
blink( on_time, off_time ) | Turns the output on for “on_time” and then off for “off_time” |
pulse( fade_in_time, fade_out_time, on_time, off_time ) | Same as blink, but lets you fade between on and off |
fade( from, to, time ) | Fade from 0-100 to 0-100 brightness over a number of seconds specified by “time” |
stop() | Stops any running blink, fade or pulse action |
import explorerhat
print(explorerhat.input.on.read())
import explorerhat
def push(input):
state = input.read()
if state == 1:
print('You pushed me')
else:
print('You released me')
explorerhat.input.one.changed(push)
or alternatively:
import explorerhat
def pushed(input):
print('You pushed me')
def released(input):
print('You released me')
explorerhat.input.one.on_high(pushed)
explorerhat.input.one.on_low(released)
PIR | ExplorerHAT |
VCC | 5V |
OUT | INPUT # |
GND | GND |
import explorerhat
print(explorerhat.input.on.read())
import explorerhat
def moving(input):
state = input.read()
if state == 1:
print('MOVING')
else:
print('NOT MOVING')
explorerhat.input.one.changed(moving)
import explorerhat
print(explorerhat.analog.one.read())
or detect a change, for example in the code below this is looking for a change of only 0.01mV
import explorerhat
def light(channel, event):
print('Light changed')
explorerhat.analog.one.changed(light,0.01)
import explorerhat
from time import sleep
explorerhat.motor.one.forward(100)
sleep(3)
explorerhat.motor.one.backward(100)
sleep(3)