本文整理汇总了Python中machine.Pin.toggle方法的典型用法代码示例。如果您正苦于以下问题:Python Pin.toggle方法的具体用法?Python Pin.toggle怎么用?Python Pin.toggle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类machine.Pin
的用法示例。
在下文中一共展示了Pin.toggle方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Trigger_Monitor
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import toggle [as 别名]
class Trigger_Monitor(object):
'''
Is there a way to change the callback?
'''
def __init__(self):
# OUTPUT/INPUT
self.pins = ['GP16', 'GP13']
self.outputPin = Pin(self.pins[0], mode=Pin.OUT, value=1)
self.inputPin = Pin(self.pins[1], mode=Pin.IN, pull=Pin.PULL_UP)
self.triggerCount = 0
self._triggerType_ = Pin.IRQ_RISING
self.inputIRQ = self.inputPin.irq(trigger=self._triggerType_, handler=self.pinHandler)
self.irqState = True
def toggleInput(self, time_ms = 5):
self.outputPin.toggle()
time.sleep_ms(time_ms)
def pinHandler(self, pin_o):
# global self.pin_irq_count_trigger
# global self.pin_irq_count_total
# self._triggerType_
# if self._triggerType_ & self.inputIRQ.flags():
# self.pin_irq_count_trigger += 1
self.triggerCount += 1
def getTriggerCount(self):
print("Trigger Count: ", self.triggerCount)
def resetTriggerCount(self):
self.triggerCount = 0
def disableIRQ(self):
self.irqState = machine.disable_irq() # Start of critical section
def reEnableIRQ(self):
machine.enable_irq(True)
self.irqState=True
示例2: main
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import toggle [as 别名]
def main():
# set internal clock
rtc = settime(timezone_offset=TIMEZONE_OFFSET)
year, month, day, hour, minute, second, *_ = rtc.now()
trigger = Pin('GP5', mode=Pin.OUT)
trigger.value(0)
# initial trigger timer
timer = Timer(3, mode=Timer.PERIODIC, width=32)
timer_channel = timer.channel(Timer.A | Timer.B, period=30000000)
timer_channel.irq(handler=lambda t: trigger.toggle(), trigger=Timer.TIMEOUT)
try:
while True:
leds = clock2matrix(hour=hour, minute=minute).columns
# led matrix multiplexing
current_trigger = trigger.value()
while trigger.value() == current_trigger:
for col in leds:
latch.value(0)
# write current time
spi.write(col)
# update LEDs
latch.value(1)
sleep_ms(1)
latch.value(0)
spi.write(OFF)
latch.value(1)
sleep_us(50)
latch.value(0)
spi.write(OFF)
latch.value(1)
year, month, day, hour, minute, second, *_ = rtc.now()
# update rtc at 04:00
if hour == 4 and minute == 0:
rtc = settime(timezone_offset=TIMEZONE_OFFSET)
except Exception as e:
matrix_off()
while True:
print(e)
sleep_ms(2000)
示例3: print
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import toggle [as 别名]
os.dupterm(uart)
print ('UART initialised')
#uart.irq(trigger=UART.RX_ANY, wake=machine.IDLE)
from machine import Pin
from machine import Timer
led_out = Pin('GP16', mode=Pin.OUT)
tim = Timer(1, mode=Timer.PERIODIC)
tim_a = tim.channel(Timer.A, freq=5)
# The slowest frequency the timer can run at is 5Hz
# so we divide the frequency down to toggle the LED
# BUT the callback function doesn't appear to have been developed
# Worth trying again as it is now included in the documentation
tim_a.irq(handler=lambda t:led_out.toggle(), trigger=Timer.TIMEOUT) # Toggle LED on Timer interrupt
#btn_in = Pin('GP17', mode=Pin.IN, pull=Pin.PULL_UP)
# Connect to my WiFi
import machine
from network import WLAN
wlan = WLAN() # get current object, without changing the mode
# Settings for TP-LINK home network
KEY = ''
IP = '192.168.1.253' # WiPy Fixed IP address
GATEWAY = '192.168.1.1' # IP address of gateway
DNS = '192.168.1.1' # IP address of DNS
NETMASK = '255.255.255.0' # Netmask for this subnet
示例4: Pin
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import toggle [as 别名]
# test pin init and printing
pin = Pin(pin_map[0])
pin.init(mode=Pin.IN)
print(pin)
pin.init(Pin.IN, Pin.PULL_DOWN)
print(pin)
pin.init(mode=Pin.OUT, pull=Pin.PULL_UP, drive=pin.LOW_POWER)
print(pin)
pin.init(mode=Pin.OUT, pull=Pin.PULL_UP, drive=pin.HIGH_POWER)
print(pin)
# test value in OUT mode
pin = Pin(pin_map[0], mode=Pin.OUT)
pin.value(0)
pin.toggle() # test toggle
print(pin())
pin.toggle() # test toggle again
print(pin())
# test different value settings
pin(1)
print(pin.value())
pin(0)
print(pin.value())
pin.value(1)
print(pin())
pin.value(0)
print(pin())
# test all getters and setters
pin = Pin(pin_map[0], mode=Pin.OUT)
示例5: HeartBeat
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import toggle [as 别名]
from machine import Timer, Pin, HeartBeat
#disable heartbeat
#per - https://micropython.org/resources/docs/en/latest/wipy/library/machine.html
HeartBeat().disable()
#turn LED on
# (says v1.6, led works/HB is incorrect?) https://micropython.org/resources/docs/en/latest/wipy/wipy/tutorial/repl.html#linux
led = Pin('GP25', mode=Pin.OUT)
led(1)
#simple function to blink lamp
blink = lambda f:led.toggle()
#Much of 1.4.6 doc is just bad/does not match actual v1.4.6 WiPy firmware
#https://github.com/micropython/micropython/blob/v1.4.6/docs/pyboard/tutorial/timer.rst
#initialize a timer
tim = Timer(4) #1-14 exist; 3 is for internal use; avoid 5+6 (used for servo control or ADC/DAC)
tim.init(mode=Timer.PERIODIC)
#configure a timer 'channel'
tim_a = tim.channel( tim.A, freq=5) #less than 5per sec did not work
#add something useful to the running channel
tim_a.irq(handler=blink) #blinks strangely rapidly
#disable the timer 'channel'
tim_a = None #still blinking
#tim.deinit() #stopped, terminal froze.
tim.channel( tim.A, freq=5) #stopped blinking
示例6: Pin
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import toggle [as 别名]
# main.py -- put your code here!
from machine import Pin
import time
led = Pin("GP16", Pin.OUT)
led.toggle()
def log(msg):
print(msg)
def btnPressed(pin):
led.toggle()
time.sleep_us(100)
btn = Pin("GP17", Pin.IN, Pin.PULL_UP)
btn.irq(trigger=Pin.IRQ_FALLING, handler=btnPressed)
def home():
global wifi
if wifi.mode() != WLAN.STA:
wifi.mode(WLAN.STA)
wifi.connect(config.HOME_SSID, auth=(WLAN.WPA, config.HOME_PASSWORD))
def tc():
global t, p
import theta
t = theta.Theta()
p = t.connect()
if not p:
示例7: Pin
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import toggle [as 别名]
pin1 = Pin(pins[1], mode=Pin.IN, pull=Pin.PULL_UP)
def pin_handler (pin_o):
global pin_irq_count_trigger
global pin_irq_count_total
global _trigger
if _trigger & pin1_irq.flags():
pin_irq_count_trigger += 1
pin_irq_count_total += 1
pin_irq_count_trigger = 0
pin_irq_count_total = 0
_trigger = Pin.IRQ_FALLING
pin1_irq = pin1.irq(trigger=_trigger, handler=pin_handler)
for i in range (0, 10):
pin0.toggle()
time.sleep_ms(5)
print(pin_irq_count_trigger == 5)
print(pin_irq_count_total == 5)
pin_irq_count_trigger = 0
pin_irq_count_total = 0
_trigger = Pin.IRQ_RISING
pin1_irq = pin1.irq(trigger=_trigger, handler=pin_handler)
for i in range (0, 200):
pin0.toggle()
time.sleep_ms(5)
print(pin_irq_count_trigger == 100)
print(pin_irq_count_total == 100)
pin1_irq.disable()