LED chaser Dengan Raspberry Pi Pico

Persiapan Bahan #

– Raspberry Pi Pico / Pico W
– 8x LED
– Breadboard
– 8x Resisor 220Ohm
– Kabel Jumper Male to Male
– Kabel Micro USD
– Aplikasi Thonny IDE

Wiring LED dan Resistor Raspberry Pi Pico #

Sample Code – LED Chaser : main.py #

#Import the library files
from  machine import Pin
import time

#Pattern one
def patternOne(times):
    for a in range (0,times):
        for i in range(0,8):
            Pin(i,Pin.OUT).value(1)
            time.sleep(0.1)
            Pin(i,Pin.OUT).value(0)          

#Pattern two
def patternTwo(times):
    for a in range(0,times):
        for i in range(0,7):
            Pin(i,Pin.OUT).value(1)
            time.sleep(0.1)
            Pin(i,Pin.OUT).value(0)
            
        for x in range(7,0,-1):
            Pin(x,Pin.OUT).value(1)
            time.sleep(0.1)
            Pin(x,Pin.OUT).value(0)

#Pattern three
def patternThree(times):
    for a in range(0,times):
        for i in range(0,7):
            Pin(i,Pin.OUT).value(0)
            time.sleep(0.1)
            Pin(i,Pin.OUT).value(1)
            
        for x in range(7,0,-1):
            Pin(x,Pin.OUT).value(0)
            time.sleep(0.1)
            Pin(x,Pin.OUT).value(1)

#Pattern four
def patternFour(times):
    for a in range(0,times):
        for i in range(0,8):
            Pin(i,Pin.OUT).value(1)
            time.sleep(0.1)       
            
        for x in range(7,0,-1):
            Pin(x,Pin.OUT).value(0)
            time.sleep(0.1)       

#Pattern five
def patternFive(times):
    for a in range(0,times):
        for i in range(0,7):
            Pin(i,Pin.OUT).value(0)
            time.sleep(0.1)       
            
        for x in range(8,-1,-1):
            Pin(x,Pin.OUT).value(1)
            time.sleep(0.1)

#Pattern six
def patternSix(times):
    for a in range(0,times):
        for i in range(0,7):
            Pin(i,Pin.OUT).value(1)
            Pin(i+1,Pin.OUT).value(1)
            time.sleep(0.1)
            Pin(i,Pin.OUT).value(0)
            Pin(i+1,Pin.OUT).value(0)
            
        for x in range(7,0,-1):
            Pin(x,Pin.OUT).value(1)
            Pin(x-1,Pin.OUT).value(1)
            time.sleep(0.1)
            Pin(x,Pin.OUT).value(0)
            Pin(x-1,Pin.OUT).value(0)

#Call the functions
while True:           
    patternOne(3)
    patternTwo(3)
    patternThree(3)
    patternFour(3)
    patternFive(3)
    patternSix(3)

Powered by BetterDocs

Leave a Reply

Your email address will not be published. Required fields are marked *

Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare
What are you looking for in Partdo?
× How can I help you?