用户工具

站点工具


micropython:开发板:pyesp32:demo

pyESP32 demo

LED

#  pyESP32 LED demo
 
from machine import Pin
from time import sleep_ms
 
LED=Pin(12, Pin.OUT)
while 1:
    LED(not LED())
    sleep_ms(200)

呼吸灯

# pyESP32 Breathing lamp demo
 
from machine import Pin, Timer, PWM
 
LED = PWM(Pin(12), freq=1000)
 
n = 0
 
def breathing(t):
    global n
    LED.duty(abs(1023- n*32))
    n = (n + 1) % 64
 
T0 = Timer(1)
T0.init(period=20, mode=Timer.PERIODIC, callback=breathing)

默认程序

main.py
from machine import Pin, Timer, PWM
from time import sleep_ms
import os, machine, gc
 
print('\n')
print('-----------')
print('| pyESP32 |')
print('-----------')
print('')
 
print('RAM size:', gc.mem_free()+gc.mem_alloc(), '\n')
 
SD_SW = Pin(5, Pin.IN)
if SD_SW():
    print('SD not present')
else:
    try:
        print('SD present')
        os.mount(machine.SDCard(), '/sd')
        print('mount SD success.')
        r = os.statvfs('/sd')
        print('SD capacity: {} B / {} M'.format(r[0] * r[2], r[0] * r[2]/1024/1024))
        print('free space:  {} B / {} M'.format(r[0] * r[3], r[0] * r[3]/1024/1024))        
    except:
        print('mount SD error!')
 
print('\nstart breathing light!\n\n')
 
LED = PWM(Pin(12), freq=1000)
 
n = 0
 
def breathing(t):
    global n
    LED.duty(abs(1023- n*32))
    n = (n + 1) % 64
 
T0 = Timer(1)
T0.init(period=50, mode=Timer.PERIODIC, callback=breathing)


purge    随机主题   
micropython/开发板/pyesp32/demo.txt · 最后更改: 2021/02/28 23:13 (外部编辑) · 查看次数: 405