이 블로그 검색

2021년 10월 2일 토요일

라즈베리파이피코 마이크로파이썬언어로 thonny에서 25번핀 breath blink 예제소스

#BUILTIN LED 숨쉬기예제 

#thonny에서...으로저장 raspberry pico선택

#thonny에서 main.py로 저장해야 바로 실행됨 업로드 같은 계념

import time

from machine import Pin,PWM


pwm_pins = [25] # set PWM pins

pwms = [PWM(Pin(pwm_pins[0]))] # pwm array

[pwm.freq(1000) for pwm in pwms] # set pwm freqs


step_val = 64 # step value for 16-bit breathing

range_0 = [ii for ii in range(0,2**16,step_val)] # brightening

range_1 = [ii for ii in range(2**16,-step_val,-step_val)] # dimming


while True: # loop indefinitely

    # looping through red, blue, green breathing

    for pwm in pwms: 

           for ii in range_0+range_1:

               pwm.duty_u16(ii) # set duty cycle out of 16-bits

               time.sleep(0.001) # sleep 1ms between pwm change

    # white pixel breathing (all three LEDs)

    for ii in range_0+range_1:

        for pwm in pwms:

            pwm.duty_u16(ii) # set duty cycle

        time.sleep(0.001) # wait 1ms


댓글 없음:

댓글 쓰기