# Blinking LED
# from time import sleep
# from machine import Pin
# led = Pin(0, Pin.OUT)
# while True:
# led.toggle()
# sleep(1)
# print("Toggled")
# led.on()
# sleep(0.5)
# led.off()
# sleep(0.5)
# {
# "version": 1,
# "author": "Liam Brennan",
# "editor": "wokwi",
# "parts": [
# {
# "type": "wokwi-pi-pico",
# "id": "pico",
# "top": 0,
# "left": 0,
# "attrs": { "env": "micropython-20241129-v1.24.1" }
# },
# {
# "type": "wokwi-led",
# "id": "led1",
# "top": -3.6,
# "left": -140.2,
# "attrs": { "color": "red" }
# }
# ],
# "connections": [ [ "led1:A", "pico:GP0", "green", [ "v0" ] ], [ "led1:C", "pico:GND.1", "green", [ "v0" ] ] ],
# "dependencies": {}
# }
# NeoPixel (Change Pixel Colour 1-By-1)
# from time import sleep
# import neopixel
# from machine import Pin
# pixels = neopixel.NeoPixel(Pin(0), 16)
# colours = [(255, 0, 0), (0, 255, 0), (0, 0, 255)]
# pixel_index = 0
# colour_index = 0
# while True:
# pixels[pixel_index] = colours[colour_index]
# pixels.write()
# if pixel_index == len(pixels) - 1:
# colour_index = (colour_index + 1) % len(colours)
# pixel_index = (pixel_index + 1) % len(pixels)
# sleep(0.1)
# print("Toggled")
# {
# "version": 1,
# "author": "Liam Brennan",
# "editor": "wokwi",
# "parts": [
# {
# "type": "wokwi-pi-pico",
# "id": "pico",
# "top": 0,
# "left": 0,
# "attrs": { "env": "micropython-20241129-v1.24.1" }
# },
# {
# "type": "wokwi-led-ring",
# "id": "ring1",
# "top": -37.76,
# "left": -210.01,
# "attrs": { "pixels": "16" }
# }
# ],
# "connections": [
# [ "ring1:DIN", "pico:GP0", "green", [ "v0" ] ],
# [ "ring1:VCC", "pico:3V3", "red", [ "v0" ] ],
# [ "ring1:GND", "pico:GND.1", "black", [ "v0" ] ]
# ],
# "dependencies": {}
# }
# 2 NeoPixels (Change Pixel Colour 1-By-1 When NeoPixels Are Chained Together)
# from time import sleep
# from machine import Pin
# import neopixel
# colours_1 = [(255, 0, 0), (0, 255, 0), (0, 0, 255)]
# colours_2 = [(255, 255, 0), (0, 255, 255), (255, 0, 255)]
# pixels = neopixel.NeoPixel(Pin(0), 32)
# colour_index_1 = 0
# colour_index_2 = 1
# pixel_index = 0
# while True:
# pixels[pixel_index] = colours_1[colour_index_1]
# pixels[pixel_index+16] = colours_2[colour_index_2]
# pixels.write()
# if pixel_index == len(pixels) - 16 - 1:
# colour_index_1 = (colour_index_1 + 1) % len(colours_1)
# if pixel_index == len(pixels) - 16 - 1:
# colour_index_2 = (colour_index_2 + 1) % len(colours_2)
# pixel_index = (pixel_index + 1) % 16
# sleep(0.1)
# print("Toggled")
# {
# "version": 1,
# "author": "Liam Brennan",
# "editor": "wokwi",
# "parts": [
# {
# "type": "wokwi-pi-pico",
# "id": "pico",
# "top": 0,
# "left": 0,
# "attrs": { "env": "micropython-20241129-v1.24.1" }
# },
# {
# "type": "wokwi-led-ring",
# "id": "ring1",
# "top": -37.76,
# "left": -248.41,
# "attrs": { "pixels": "16" }
# },
# {
# "type": "wokwi-led-ring",
# "id": "ring2",
# "top": 135.04,
# "left": -248.41,
# "attrs": { "pixels": "16" }
# }
# ],
# "connections": [
# [ "ring1:GND", "pico:GND.1", "black", [ "v0" ] ],
# [ "ring1:VCC", "pico:3V3", "red", [ "v0" ] ],
# [ "ring1:DIN", "pico:GP0", "green", [ "v0" ] ],
# [ "ring2:GND", "pico:GND.1", "black", [ "v0" ] ],
# [ "ring2:VCC", "pico:3V3", "red", [ "v0" ] ],
# [ "ring1:DOUT", "ring2:DIN", "green", [ "v0" ] ]
# ],
# "dependencies": {}
# }
# NeoPixel (Change All Pixel Colours At Once)
# from time import sleep
# from machine import Pin
# import neopixel
# pixels = neopixel.NeoPixel(Pin(0), 48)
# colours = [(255, 0, 0), (0, 255, 0), (0, 0, 255)]
# colour_index = 0
# pixel_index = 0
# while True:
# for i in range(len(pixels)):
# pixels[i] = colours[colour_index]
# pixels.write()
# colour_index = (colour_index + 1) % len(colours)
# sleep(0.1)
# print("Toggled")
# {
# "version": 1,
# "author": "Liam Brennan",
# "editor": "wokwi",
# "parts": [
# {
# "type": "wokwi-pi-pico",
# "id": "pico",
# "top": 0,
# "left": 0,
# "attrs": { "env": "micropython-20241129-v1.24.1" }
# },
# {
# "type": "wokwi-led-ring",
# "id": "ring1",
# "top": -37.76,
# "left": -200.41,
# "attrs": { "pixels": "16" }
# }
# ],
# "connections": [
# [ "ring1:GND", "pico:GND.1", "black", [ "v0" ] ],
# [ "ring1:VCC", "pico:3V3", "red", [ "v0" ] ],
# [ "ring1:DIN", "pico:GP0", "green", [ "v0" ] ]
# ],
# "dependencies": {}
# }
# Buzzer (Basic)
# from picozero import Speaker
# from time import sleep
# speaker = Speaker(0)
# tone = 100
# while True:
# speaker.play(tone, duration=0.1, volume=0.1)
# sleep(1)
# # speaker.on()
# # sleep(1)
# # speaker.off()
# # sleep(1)
# {
# "version": 1,
# "author": "Liam Brennan",
# "editor": "wokwi",
# "parts": [
# {
# "type": "wokwi-pi-pico",
# "id": "pico",
# "top": 0,
# "left": 0,
# "attrs": { "env": "micropython-20241129-v1.24.1" }
# },
# {
# "type": "wokwi-buzzer",
# "id": "bz1",
# "top": 2.4,
# "left": -171,
# "attrs": { "volume": "0.1" }
# }
# ],
# "connections": [ [ "bz1:2", "pico:GP0", "red", [ "v0" ] ], [ "bz1:1", "pico:GND.1", "black", [ "v0" ] ] ],
# "dependencies": {}
# }
# Buzzer (Melody On Repeat)
# from picozero import Speaker
# from time import sleep
# speaker = Speaker(0)
# melody = [
# {"freq": 262, "duration": 0.3}, {"freq": 330, "duration": 0.3}, {"freq": 392, "duration": 0.3}, {"freq": 440, "duration": 0.4}, {"freq": 392, "duration": 0.3}, {"freq": 330, "duration": 0.3}, {"freq": 262, "duration": 0.3}, {"freq": 294, "duration": 0.3}, {"freq": 349, "duration": 0.3}, {"freq": 440, "duration": 0.3},
# {"freq": 392, "duration": 0.5}, {"freq": 523, "duration": 0.4}, {"freq": 494, "duration": 0.3}, {"freq": 440, "duration": 0.3}, {"freq": 392, "duration": 0.3}, {"freq": 349, "duration": 0.3}, {"freq": 330, "duration": 0.3}, {"freq": 294, "duration": 0.3}, {"freq": 262, "duration": 0.6},
# ]
# tone_index = 0
# while True:
# speaker.play(melody[tone_index]["freq"], duration=melody[tone_index]["duration"])
# tone_index = (tone_index + 1) % len(melody)
# {
# "version": 1,
# "author": "Liam Brennan",
# "editor": "wokwi",
# "parts": [
# {
# "type": "wokwi-pi-pico",
# "id": "pico",
# "top": 0,
# "left": 0,
# "attrs": { "env": "micropython-20241129-v1.24.1" }
# },
# {
# "type": "wokwi-buzzer",
# "id": "bz1",
# "top": -103.2,
# "left": -199.8,
# "attrs": { "volume": "0.1" }
# }
# ],
# "connections": [ [ "bz1:2", "pico:GP0", "red", [ "v0" ] ], [ "bz1:1", "pico:GND.1", "black", [ "v0" ] ] ],
# "dependencies": {}
# }
# PWM (Melody On Repeat w/ Reverse And Decreasing Duration)
# from time import sleep
# from machine import PWM, Pin
# pwm = PWM(Pin(0))
# melody = [
# {"freq": 262, "duration": 0.3}, {"freq": 330, "duration": 0.3}, {"freq": 392, "duration": 0.3}, {"freq": 440, "duration": 0.4}, {"freq": 392, "duration": 0.3}, {"freq": 330, "duration": 0.3}, {"freq": 262, "duration": 0.3}, {"freq": 294, "duration": 0.3}, {"freq": 349, "duration": 0.3}, {"freq": 440, "duration": 0.3},
# {"freq": 392, "duration": 0.5}, {"freq": 523, "duration": 0.4}, {"freq": 494, "duration": 0.3}, {"freq": 440, "duration": 0.3}, {"freq": 392, "duration": 0.3}, {"freq": 349, "duration": 0.3}, {"freq": 330, "duration": 0.3}, {"freq": 294, "duration": 0.3}, {"freq": 262, "duration": 0.6},
# ]
# tone_index = 0
# duration = 1
# while True:
# pwm.freq(melody[tone_index]["freq"])
# pwm.duty_u16(1000)
# sleep(melody[tone_index]["duration"]*duration)
# pwm.duty_u16(0)
# if tone_index == len(melody) - 1:
# melody.reverse()
# duration = duration / 1.5
# tone_index = (tone_index + 1) % len(melody)
# {
# "version": 1,
# "author": "Liam Brennan",
# "editor": "wokwi",
# "parts": [
# {
# "type": "wokwi-pi-pico",
# "id": "pico",
# "top": 0,
# "left": 0,
# "attrs": { "env": "micropython-20241129-v1.24.1" }
# },
# {
# "type": "wokwi-buzzer",
# "id": "bz1",
# "top": -103.2,
# "left": -199.8,
# "attrs": { "volume": "0.1" }
# }
# ],
# "connections": [ [ "bz1:2", "pico:GP0", "red", [ "v0" ] ], [ "bz1:1", "pico:GND.1", "black", [ "v0" ] ] ],
# "dependencies": {}
# }
# 7 Segment Display
# from machine import Pin
# from time import sleep
# pins = [
# Pin(0, Pin.OUT), # A
# Pin(1, Pin.OUT), # B
# Pin(2, Pin.OUT), # C
# Pin(3, Pin.OUT), # D
# Pin(4, Pin.OUT), # E
# Pin(5, Pin.OUT), # F
# Pin(6, Pin.OUT), # G
# Pin(7, Pin.OUT), # DP
# ]
# # dp, g, f, e, d, c, b, a
# digits = [
# [0, 0, 0, 0, 0, 0, 1, 1], # 0
# [1, 0, 0, 1, 1, 1, 1, 1], # 1
# [0, 0, 1, 0, 0, 1, 0, 1], # 2
# [0, 0, 0, 0, 1, 1, 0, 1], # 3
# [1, 0, 0, 1, 1, 0, 0, 1], # 4
# [0, 1, 0, 0, 1, 0, 0, 1], # 5
# [0, 1, 0, 0, 0, 0, 0, 1], # 6
# [0, 0, 0, 1, 1, 1, 1, 1], # 7
# [0, 0, 0, 0, 0, 0, 0, 1], # 8
# [0, 0, 0, 1, 1, 0, 0, 1], # 9
# [0, 0, 0, 1, 0, 0, 0, 1], # A
# [1, 1, 0, 0, 0, 0, 0, 1], # b
# [0, 1, 1, 0, 0, 0, 1, 1], # C
# [1, 0, 0, 0, 0, 1, 0, 1], # d
# [0, 1, 1, 0, 0, 0, 0, 1], # E
# [0, 1, 1, 1, 0, 0, 0, 1], # F
# ]
# while True:
# for i in range(len(digits)):
# for j in range(len(pins)):
# pins[j].value(digits[i][j])
# sleep(0.5)
# digits.reverse()
# while True:
# for i in range(len(digits)):
# for j in range(len(pins)):
# pins[j].value(digits[i][j])
# sleep(0.5)
# {
# "version": 1,
# "author": "Liam Brennan",
# "editor": "wokwi",
# "parts": [
# {
# "type": "wokwi-pi-pico",
# "id": "pico",
# "top": -3.15,
# "left": -34.8,
# "attrs": { "env": "micropython-20241129-v1.24.1" }
# },
# { "type": "wokwi-7segment", "id": "sevseg1", "top": 52.98, "left": -167.72, "attrs": {} }
# ],
# "connections": [
# [ "sevseg1:A", "pico:GP0", "#8f4814", [ "v0" ] ],
# [ "sevseg1:B", "pico:GP1", "violet", [ "v0" ] ],
# [ "sevseg1:C", "pico:GP2", "orange", [ "v0" ] ],
# [ "sevseg1:D", "pico:GP3", "gold", [ "v0" ] ],
# [ "sevseg1:E", "pico:GP4", "cyan", [ "v0" ] ],
# [ "sevseg1:F", "pico:GP5", "purple", [ "v0" ] ],
# [ "sevseg1:G", "pico:GP6", "blue", [ "v0" ] ],
# [ "sevseg1:DP", "pico:GP7", "green", [ "v0" ] ],
# [ "sevseg1:COM.1", "pico:3V3", "red", [ "h0" ] ]
# ],
# "dependencies": {}
# }
# 7 Segment Display w/ Switch
# from time import sleep
# from machine import Pin
# pins = [
# Pin(0, Pin.OUT), # A
# Pin(1, Pin.OUT), # B
# Pin(2, Pin.OUT), # C
# Pin(3, Pin.OUT), # D
# Pin(4, Pin.OUT), # E
# Pin(5, Pin.OUT), # F
# Pin(6, Pin.OUT), # G
# Pin(7, Pin.OUT), # DP
# ]
# # dp, g, f, e, d, c, b, a
# digits = [
# [0, 0, 0, 0, 0, 0, 1, 1], # 0
# [1, 0, 0, 1, 1, 1, 1, 1], # 1
# [0, 0, 1, 0, 0, 1, 0, 1], # 2
# [0, 0, 0, 0, 1, 1, 0, 1], # 3
# [1, 0, 0, 1, 1, 0, 0, 1], # 4
# [0, 1, 0, 0, 1, 0, 0, 1], # 5
# [0, 1, 0, 0, 0, 0, 0, 1], # 6
# [0, 0, 0, 1, 1, 1, 1, 1], # 7
# [0, 0, 0, 0, 0, 0, 0, 1], # 8
# [0, 0, 0, 1, 1, 0, 0, 1], # 9
# [0, 0, 0, 1, 0, 0, 0, 1], # A
# [1, 1, 0, 0, 0, 0, 0, 1], # b
# [0, 1, 1, 0, 0, 0, 1, 1], # C
# [1, 0, 0, 0, 0, 1, 0, 1], # d
# [0, 1, 1, 0, 0, 0, 0, 1], # E
# [0, 1, 1, 1, 0, 0, 0, 1], # F
# ]
# switch = Pin(27, Pin.IN)
# while True:
# if switch.value() == 1:
# for i in range(len(digits)):
# if switch.value() == 0:
# break
# for j in range(len(pins)):
# pins[j].value(digits[i][j])
# sleep(0.5)
# elif switch.value() == 0:
# for i in range(len(digits) - 1, -1, -1):
# if switch.value() == 1:
# break
# for j in range(len(pins)):
# pins[j].value(digits[i][j])
# sleep(0.5)
# {
# "version": 1,
# "author": "Liam Brennan",
# "editor": "wokwi",
# "parts": [
# {
# "type": "wokwi-pi-pico",
# "id": "pico",
# "top": -3.15,
# "left": -34.8,
# "attrs": { "env": "micropython-20241129-v1.24.1" }
# },
# { "type": "wokwi-7segment", "id": "sevseg1", "top": 52.98, "left": -167.72, "attrs": {} },
# { "type": "wokwi-slide-switch", "id": "sw1", "top": -14.8, "left": 118.3, "attrs": {} }
# ],
# "connections": [
# [ "sevseg1:A", "pico:GP0", "#8f4814", [ "v0" ] ],
# [ "sevseg1:B", "pico:GP1", "violet", [ "v0" ] ],
# [ "sevseg1:C", "pico:GP2", "orange", [ "v0" ] ],
# [ "sevseg1:D", "pico:GP3", "gold", [ "v0" ] ],
# [ "sevseg1:E", "pico:GP4", "cyan", [ "v0" ] ],
# [ "sevseg1:F", "pico:GP5", "purple", [ "v0" ] ],
# [ "sevseg1:G", "pico:GP6", "blue", [ "v0" ] ],
# [ "sevseg1:DP", "pico:GP7", "green", [ "v0" ] ],
# [ "sevseg1:COM.1", "pico:3V3", "red", [ "h0" ] ],
# [ "sw1:1", "pico:3V3", "black", [ "v0" ] ],
# [ "sw1:3", "pico:GND.8", "red", [ "v0" ] ],
# [ "sw1:2", "pico:GP27", "green", [ "v0" ] ]
# ],
# "dependencies": {}
# }
# 2 7 Segment Displays /w Switch
# from machine import Pin
# from time import sleep
# pins_1 = [
# Pin(0, Pin.OUT), # A
# Pin(1, Pin.OUT), # B
# Pin(2, Pin.OUT), # C
# Pin(3, Pin.OUT), # D
# Pin(4, Pin.OUT), # E
# Pin(5, Pin.OUT), # F
# Pin(6, Pin.OUT), # G
# Pin(7, Pin.OUT), # DP
# ]
# pins_2 = [
# Pin(16, Pin.OUT), # A
# Pin(17, Pin.OUT), # B
# Pin(18, Pin.OUT), # C
# Pin(19, Pin.OUT), # D
# Pin(20, Pin.OUT), # E
# Pin(21, Pin.OUT), # F
# Pin(22, Pin.OUT), # G
# Pin(26, Pin.OUT), # DP
# ]
# # dp, g, f, e, d, c, b, a
# digits = [
# [0, 0, 0, 0, 0, 0, 1, 1], # 0
# [1, 0, 0, 1, 1, 1, 1, 1], # 1
# [0, 0, 1, 0, 0, 1, 0, 1], # 2
# [0, 0, 0, 0, 1, 1, 0, 1], # 3
# [1, 0, 0, 1, 1, 0, 0, 1], # 4
# [0, 1, 0, 0, 1, 0, 0, 1], # 5
# [0, 1, 0, 0, 0, 0, 0, 1], # 6
# [0, 0, 0, 1, 1, 1, 1, 1], # 7
# [0, 0, 0, 0, 0, 0, 0, 1], # 8
# [0, 0, 0, 1, 1, 0, 0, 1], # 9
# [0, 0, 0, 1, 0, 0, 0, 1], # A
# [1, 1, 0, 0, 0, 0, 0, 1], # b
# [0, 1, 1, 0, 0, 0, 1, 1], # C
# [1, 0, 0, 0, 0, 1, 0, 1], # d
# [0, 1, 1, 0, 0, 0, 0, 1], # E
# [0, 1, 1, 1, 0, 0, 0, 1], # F
# ]
# switch = Pin(12, Pin.IN)
# while True:
# if switch.value() == 1:
# for i in range(len(digits)):
# if switch.value() == 0:
# break
# for j in range(len(pins_1)):
# pins_1[j].value(digits[i][j])
# pins_2[j].value(digits[len(digits) - 1 - i][j])
# sleep(0.5)
# elif switch.value() == 0:
# for i in range(len(digits) - 1, -1, -1):
# if switch.value() == 1:
# break
# for j in range(len(pins_2)):
# pins_1[j].value(digits[i][j])
# pins_2[j].value(digits[len(digits) - 1 - i][j])
# sleep(0.5)
# {
# "version": 1,
# "author": "Liam Brennan",
# "editor": "wokwi",
# "parts": [
# {
# "type": "wokwi-pi-pico",
# "id": "pico",
# "top": -3.15,
# "left": -34.8,
# "attrs": { "env": "micropython-20241129-v1.24.1" }
# },
# { "type": "wokwi-7segment", "id": "sevseg1", "top": -4.62, "left": -138.92, "attrs": {} },
# { "type": "wokwi-7segment", "id": "sevseg2", "top": -14.22, "left": 101.08, "attrs": {} },
# { "type": "wokwi-slide-switch", "id": "sw1", "top": -62.8, "left": -6.5, "attrs": {} }
# ],
# "connections": [
# [ "sevseg1:A", "pico:GP0", "green", [ "v0" ] ],
# [ "sevseg1:B", "pico:GP1", "green", [ "v0" ] ],
# [ "sevseg1:C", "pico:GP2", "green", [ "v0" ] ],
# [ "sevseg1:D", "pico:GP3", "green", [ "v0" ] ],
# [ "sevseg1:E", "pico:GP4", "green", [ "v0" ] ],
# [ "sevseg1:F", "pico:GP5", "green", [ "v0" ] ],
# [ "sevseg1:G", "pico:GP6", "green", [ "v0" ] ],
# [ "sevseg2:A", "pico:GP16", "green", [ "v0" ] ],
# [ "sevseg2:B", "pico:GP17", "green", [ "v0" ] ],
# [ "sevseg2:C", "pico:GP18", "green", [ "v0" ] ],
# [ "sevseg2:D", "pico:GP19", "green", [ "v0" ] ],
# [ "sevseg2:E", "pico:GP20", "green", [ "v0" ] ],
# [ "sevseg2:F", "pico:GP21", "green", [ "v0" ] ],
# [ "sevseg2:G", "pico:GP22", "green", [ "v0" ] ],
# [ "sevseg2:DP", "pico:GP26", "blue", [ "v0" ] ],
# [ "sevseg2:COM.1", "pico:3V3", "red", [ "h0" ] ],
# [ "sevseg1:COM.1", "pico:3V3", "red", [ "h0" ] ],
# [ "sevseg1:DP", "pico:GP7", "blue", [ "v0" ] ],
# [ "sw1:1", "pico:3V3", "red", [ "v0" ] ],
# [ "sw1:2", "pico:GP12", "green", [ "v0" ] ],
# [ "sw1:3", "pico:GND.8", "black", [ "v0" ] ]
# ],
# "dependencies": {}
# }
from machine import ADC
from time import sleep
gas_sensor = ADC(26)
vref = 3.3
adc = 65535
rate = 1.5
while True:
raw = gas_sensor.read_u16()
voltage = (raw / adc) * vref
cost = voltage * rate
print("\nRaw: ", raw)
print("Voltage: ", voltage)
print("Cost: ", cost)
# sleep(0.5)
# Gas Sensor
# from machine import ADC
# from time import sleep
# # ADC only on pin 26
# gas_sensor = ADC(26)
# voltage_ref = 3.3
# adc_res = 65535
# dollar_rate = 2.5
# while True:
# raw = gas_sensor.read_u16()
# print("\nRaw: ", raw)
# voltage = (raw / adc_res) * voltage_ref
# print("Voltage: ", voltage)
# cost = voltage * dollar_rate
# print("Cost: ", cost)
# sleep(0.5)
# {
# "version": 1,
# "author": "Liam Brennan",
# "editor": "wokwi",
# "parts": [
# {
# "type": "wokwi-pi-pico",
# "id": "pico",
# "top": -3.15,
# "left": -34.8,
# "attrs": { "env": "micropython-20241129-v1.24.1" }
# },
# { "type": "wokwi-gas-sensor", "id": "gas1", "top": -6.9, "left": -204.2, "attrs": {} }
# ],
# "connections": [
# [ "gas1:GND", "pico:GND.1", "black", [ "h0" ] ],
# [ "gas1:VCC", "pico:3V3", "red", [ "h0" ] ],
# [ "gas1:AOUT", "pico:GP26", "green", [ "h0" ] ]
# ],
# "dependencies": {}
# }
# I2C LCD
# from machine import Pin, I2C
# from i2c_lcd import I2cLcd
# from time import sleep
# i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
# lcd = I2cLcd(i2c, 0x27, 2, 16)
# lcd.clear()
# lcd.putstr("Hello")
# lcd.move_to(0, 1)
# lcd.putstr("World")
# sleep(1)
# words = ["dragon", "wizard", "dungeon", "sorcery", "goblin", "phoenix", "enchant", "mythril", "rune", "alchemy"]
# word_index = 0
# while True:
# lcd.clear()
# lcd.putstr(words[word_index])
# word_index = (word_index + 1) % len(words)
# lcd.move_to(0, 1)
# lcd.putstr(words[word_index])
# sleep(1)
# {
# "version": 1,
# "author": "Liam Brennan",
# "editor": "wokwi",
# "parts": [
# {
# "type": "wokwi-pi-pico",
# "id": "pico",
# "top": -3.15,
# "left": -34.8,
# "attrs": { "env": "micropython-20241129-v1.24.1" }
# },
# {
# "type": "wokwi-lcd1602",
# "id": "lcd1",
# "top": 25.6,
# "left": 72.8,
# "attrs": { "pins": "i2c" }
# }
# ],
# "connections": [
# [ "lcd1:GND", "pico:GND.1", "black", [ "h0" ] ],
# [ "lcd1:VCC", "pico:3V3", "red", [ "h0" ] ],
# [ "lcd1:SDA", "pico:GP0", "green", [ "h0" ] ],
# [ "lcd1:SCL", "pico:GP1", "green", [ "h0" ] ]
# ],
# "dependencies": {}
# }
# 4-Digit 7 Segment Display
# from time import sleep
# from machine import Pin
# from rp2 import PIO
# @rp2.asm_pio(out_init=[PIO.OUT_LOW]*8, sideset_init=[PIO.OUT_LOW]*4)
# def sevseg():
# wrap_target()
# label("0")
# pull(noblock) .side(0) # 0
# mov(x, osr) .side(0) # 1
# out(pins, 8) .side(1) # 2
# out(pins, 8) .side(2) # 3
# out(pins, 8) .side(4) # 4
# out(pins, 8) .side(8) # 5
# jmp("0") .side(0) # 6
# wrap()
# sm = rp2.StateMachine(0, sevseg, freq=2000, out_base=Pin(2), sideset_base=Pin(10))
# sm.active(1)
# # dp, g, f, e, d, c, b, a
# digits = [
# 0b11000000, # 0
# 0b11111001, # 1
# 0b10100100, # 2
# 0b10110000, # 3
# 0b10011001, # 4
# 0b10010010, # 5
# 0b10000010, # 6
# 0b11111000, # 7
# 0b10000000, # 8
# 0b10010000, # 9
# ]
# def segmentize(num):
# return (
# digits[num % 10]
# | digits[num // 10 % 10] << 8
# | digits[num // 100 % 10] << 16
# | digits[num // 1000 % 10] << 24
# )
# counter = 0
# while True:
# sm.put(segmentize(counter))
# counter += 1
# sleep(0.1)
# {
# "version": 1,
# "author": "Liam Brennan",
# "editor": "wokwi",
# "parts": [
# {
# "type": "wokwi-pi-pico",
# "id": "pico",
# "top": -3.15,
# "left": -34.8,
# "attrs": { "env": "micropython-20241129-v1.24.1" }
# },
# {
# "type": "wokwi-7segment",
# "id": "sevseg1",
# "top": 53.82,
# "left": -238.88,
# "attrs": { "digits": "4" }
# }
# ],
# "connections": [
# [ "sevseg1:COM", "pico:3V3", "red", [ "v0" ] ],
# [ "sevseg1:A", "pico:GP2", "green", [ "v0" ] ],
# [ "sevseg1:B", "pico:GP3", "green", [ "v0" ] ],
# [ "sevseg1:C", "pico:GP4", "green", [ "v0" ] ],
# [ "sevseg1:D", "pico:GP5", "green", [ "v0" ] ],
# [ "sevseg1:E", "pico:GP6", "green", [ "v0" ] ],
# [ "sevseg1:F", "pico:GP7", "green", [ "v0" ] ],
# [ "sevseg1:G", "pico:GP8", "green", [ "v0" ] ],
# [ "sevseg1:DIG1", "pico:GP10", "blue", [ "v0" ] ],
# [ "sevseg1:DIG2", "pico:GP11", "blue", [ "v0" ] ],
# [ "sevseg1:DIG4", "pico:GP13", "blue", [ "v0" ] ],
# [ "sevseg1:DIG3", "pico:GP12", "blue", [ "v0" ] ],
# [ "sevseg1:DP", "pico:GP9", "violet", [ "v0" ] ]
# ],
# "dependencies": {}
# }
# Ultrasonic Sensor
# from machine import Pin, time_pulse_us
# from time import sleep_us, sleep
# trig = Pin(2, Pin.OUT)
# echo = Pin(3, Pin.IN)
# def calc_distance():
# trig.low()
# sleep_us(4)
# trig.high()
# sleep_us(4)
# trig.low()
# duration = time_pulse_us(echo, 1)
# return duration / 58.82
# while True:
# distance = calc_distance()
# print("Distance: ", distance)
# sleep(0.5)
# {
# "version": 1,
# "author": "Liam Brennan",
# "editor": "wokwi",
# "parts": [
# {
# "type": "wokwi-pi-pico",
# "id": "pico",
# "top": -3.15,
# "left": -34.8,
# "attrs": { "env": "micropython-20241129-v1.24.1" }
# },
# { "type": "wokwi-hc-sr04", "id": "ultrasonic1", "top": 20.7, "left": -253.7, "attrs": {} }
# ],
# "connections": [
# [ "ultrasonic1:GND", "pico:GND.1", "black", [ "v0" ] ],
# [ "ultrasonic1:VCC", "pico:3V3", "red", [ "v0" ] ],
# [ "ultrasonic1:TRIG", "pico:GP2", "green", [ "v0" ] ],
# [ "ultrasonic1:ECHO", "pico:GP3", "green", [ "v0" ] ]
# ],
# "dependencies": {}
# }