Beispiel #1
0
from machine import PIN
from machine import LED
total_pin = 35
pin_title = 'P'
pin_num = 0
failNum = 0
led = LED(1)
led.on()
led.off()
irq_count = 0


def count(t):
    global irq_count
    if irq_count < 5:
        irq_count = irq_count + 1
    else:
        irq_count = 0


while pin_num < total_pin:
    if pin_num == 17 or pin_num == 18:
        pin_num += 1
        continue
    gpio_set = pin_title + str(pin_num)
    p_test = PIN(gpio_set)  #创建I/O
    p_test.mode(PIN.OUT)  #设置引脚模式为输出
    p_test.drive(PIN.LOW_POWER)  #设置引脚驱动强度
    p_test.value(1)  #设置引脚的值
    print(p_test)
    cmp_str = "Pin('" + gpio_set + "', mode=Pin.OUT, pull=Pin.INACTIVE, drive=Pin.LOW_POWER, alt=0)"
Beispiel #2
0
from machine import LED
total_pin = 4					
pin_num=1

while pin_num < (total_pin+1): 
 led_test=LED(int(pin_num))		#LED1~4循序亮灭
 print(led_test)
 led_test.on()
 for j in range(0,5000,1):
  continue
 led_test.off()
 for j in range(0,5000,1):
  continue
 led_test.toggle()
 for j in range(0,5000,1):
  continue
 led_test.toggle()
 for j in range(0,5000,1):
  continue
 pin_num=pin_num+1
Beispiel #3
0
    if ch == '/r':
        break
    
count =0
while True:
    ch = sys.stdin.read(2)
    if ch == 'Q0':
        break
    if ch == 'R0':
        ledr.toggle()
    if ch == 'G0':
        ledg.toggle()
    if ch == 'Y0':
        ledy.toggle()
    if ch == 'r0':
        ledr.on()
    if ch == 'g0':
        ledg.on()
    if ch == 'y0':
        ledy.on()
    if ch == 'r1':
        ledr.off()
    if ch == 'g1':
        ledg.off()
    if ch == 'y1':
        ledy.off()      
    print ('key=',ch)
    utime.sleep_ms(100)
        
micropython.kbd_intr(3)
Beispiel #4
0
'''
Touch Key
SIG --> P17
VCC --> 3.3V
GND --->GND 

when Touch the LED(Y) will off P17 is High)
release touch LED(Y) will on ( P17 is Low)
'''
from machine import Pin, LED
import utime
ledy = LED('ledy')
ledg = LED('ledg')
p17 = Pin(Pin.board.P17, Pin.IN)

ledg.off()
while True:

    print(p17.value())
    if p17.value() == 0:
        ledy.on()
    else:
        ledy.off()

    utime.sleep_ms(500)
Beispiel #5
0
from machine import KEY
from machine import PIN
from machine import LED
led = LED(LED.LED1)  #创建红灯LED1
led.on()  #红灯开启


def toggle(t):  #中断回调函数
    led.toggle()  #LED状态改变


k = KEY(KEY.KEYA)  #创建按键A
k.value()  #读取按键值
k.irq(trigger=PIN.IRQ_BOTH, handler=toggle)  #按键上升缘或下降缘产生中断
Beispiel #6
0
from machine import LED, delay

ledR = LED('ledr')
ledY = LED('ledy')
ledG = LED('ledg')

ledR.off()
ledY.off()
ledG.off()
delay(1000)
ledR.on()
ledY.on()
ledG.on()

while True:
    ledG.toggle()
    delay(1000)