Advertisement
Python253

pico_blink

Mar 1st, 2024 (edited)
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # Filename: pico_blink.py
  3. # Author: Jeoi Reqi
  4. # Blinks the LED on a Raspberry Pi Pico Microcontroller running Adafruit Circuit Python & Digitalio
  5.  
  6. import board
  7. import time
  8. from digitalio import DigitalInOut, Direction, Pull
  9.  
  10. # Set up the onboard LED for output.
  11. led = DigitalInOut(board.LED)
  12. led.direction = Direction.OUTPUT
  13.  
  14. # Gather data on the voltage and brightness level of the LED.
  15. def get_voltage_brightness(led_value):
  16.     voltage = 3.3 * led_value
  17.     brightness = 100 * led_value
  18.     return voltage, brightness
  19.  
  20. # Main loop to switch the LED on or off based on the data gathered.
  21. for i in range(3):
  22.     led.value = True  # Turn on the LED
  23.     voltage, brightness = get_voltage_brightness(led.value)
  24.     print("LED is on. Voltage: {}V, Brightness: {}%".format(voltage, brightness))
  25.     time.sleep(1)
  26.     led.value = False  # Turn off the LED
  27.     voltage, brightness = get_voltage_brightness(led.value)
  28.     print("LED is off. Voltage: {}V, Brightness: {}%".format(voltage, brightness))
  29.     time.sleep(1)
  30.     if i == 2:
  31.         break
  32. print("Done!")
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement