import time
time.sleep(0.1) # Wait for USB to become ready
print("Hello, Pi Pico!")
from machine import PWM, Pin
import utime
# servo = PWM(Pin(0))
# servo.freq(50)
# min_duty = 3277
# max_duty = 6553
# while True:
# servo.duty_u16(min_duty)
# utime.sleep(1)
# servo.duty_u16(max_duty)
# utime.sleep(1)
from machine import Pin
import utime
# from machine import Pin
# import utime
# # Define each segment by name
# A = Pin(0, Pin.OUT)
# B = Pin(1, Pin.OUT)
# C = Pin(2, Pin.OUT)
# D = Pin(3, Pin.OUT)
# E = Pin(4, Pin.OUT)
# F = Pin(5, Pin.OUT)
# G = Pin(6, Pin.OUT)
# # Group them in the same segment order used in digit definitions
# segments = [A, B, C, D, E, F, G]
# COM = Pin(7, Pin.OUT)
# COM.value(0) # Enable the digit (set LOW for common cathode)
# # Segment patterns for digits 0–9 (A to G)
# # 1 = ON, 0 = OFF
# digits = [
# [1,1,1,1,1,1,0], # 0
# [0,1,1,0,0,0,0], # 1
# [1,1,0,1,1,0,1], # 2
# [1,1,1,1,0,0,1], # 3
# [0,1,1,0,0,1,1], # 4
# [1,0,1,1,0,1,1], # 5
# [1,0,1,1,1,1,1], # 6
# [1,1,1,0,0,0,0], # 7
# [1,1,1,1,1,1,1], # 8
# [1,1,1,0,0,1,1] # 9
# ]
# # Display digits 0–9 with 1 second delay
# while True:
# for num in range(10):
# pattern = digits[num]
# for seg, val in zip(segments, pattern):
# seg.value(val)
# print(f"Showing: {num}")
# utime.sleep(1)
# from machine import Pin
# import utime
# # Define each segment by name (A–G)
# A = Pin(0, Pin.OUT)
# B = Pin(1, Pin.OUT)
# C = Pin(2, Pin.OUT)
# D = Pin(3, Pin.OUT)
# E = Pin(4, Pin.OUT)
# F = Pin(5, Pin.OUT)
# G = Pin(6, Pin.OUT)
# # Define COM pins for the two digits
# COM1 = Pin(7, Pin.OUT)
# COM2 = Pin(8, Pin.OUT)
# # Segment list for easy loop
# segments = [A, B, C, D, E, F, G]
# # Segment patterns for digits 0–9 (A to G)
# digits = [
# [1,1,1,1,1,1,0], # 0
# [0,1,1,0,0,0,0], # 1
# [1,1,0,1,1,0,1], # 2
# [1,1,1,1,0,0,1], # 3
# [0,1,1,0,0,1,1], # 4
# [1,0,1,1,0,1,1], # 5
# [1,0,1,1,1,1,1], # 6
# [1,1,1,0,0,0,0], # 7
# [1,1,1,1,1,1,1], # 8
# [1,1,1,0,0,1,1] # 9
# ]
# # Function to display a digit on the 7-segment display
# def display_digit(digit, com_pin):
# pattern = digits[digit]
# # Set the appropriate COM pin to LOW to activate the digit
# if com_pin == COM1:
# COM1.value(0) # Turn COM1 on (LOW)
# COM2.value(1) # Turn COM2 off (HIGH)
# elif com_pin == COM2:
# COM1.value(1) # Turn COM1 off (HIGH)
# COM2.value(0) # Turn COM2 on (LOW)
# # Light up the segments for the current digit
# for i in range(7):
# segments[i].value(pattern[i])
# # Main loop to display digits 0–9 on a 2-digit 7-segment display
# while True:
# for digit in range(10):
# # Display the digit on the first digit (COM1)
# display_digit(digit, COM1)
# utime.sleep(0.5) # Wait for half a second
# # Display the digit on the second digit (COM2)
# display_digit(digit, COM2)
# utime.sleep(0.5) # Wait for half a second
from machine import Pin, PWM, I2C
import utime
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
# Initialize I2C for the LCD (GPIO4 = SDA, GPIO5 = SCL)
i2c = I2C(0, scl=Pin(9), sda=Pin(8), freq=400000)
lcd_addr = i2c.scan()[0] # Get the LCD I2C address
lcd = I2cLcd(i2c, lcd_addr, 2, 16) # 2 rows, 16 columns
# Initialize servos for the 4 rafters
servo1 = PWM(Pin(15))
servo2 = PWM(Pin(16))
servo3 = PWM(Pin(17))
servo4 = PWM(Pin(18))
for servo in [servo1, servo2, servo3, servo4]:
servo.freq(50)
servo.duty_u16(1638) # Start all rafters closed (0 degrees)
# Functions to open a servo (simulate rafter removal)
def open_rafter(servo):
servo.duty_u16(8192) # Move to ~90 degrees
# Rocket launch countdown logic
def rocket_launch():
lcd.clear()
lcd.putstr("Preparing...\nRocket Ready")
utime.sleep(2)
for count in range(9, -1, -1):
lcd.clear()
lcd.putstr("Countdown:\n" + str(count))
utime.sleep(1)
# Open a rafter every 2 seconds
if count == 8:
open_rafter(servo1)
elif count == 6:
open_rafter(servo2)
elif count == 4:
open_rafter(servo3)
elif count == 2:
open_rafter(servo4)
lcd.clear()
lcd.putstr(" TAKE OFF! 🚀")
print("Rocket Launched!")
# Start the simulation
rocket_launch()