Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # Filename: pico_blink.py
- # Author: Jeoi Reqi
- # Blinks the LED on a Raspberry Pi Pico Microcontroller running Adafruit Circuit Python & Digitalio
- import board
- import time
- from digitalio import DigitalInOut, Direction, Pull
- # Set up the onboard LED for output.
- led = DigitalInOut(board.LED)
- led.direction = Direction.OUTPUT
- # Gather data on the voltage and brightness level of the LED.
- def get_voltage_brightness(led_value):
- voltage = 3.3 * led_value
- brightness = 100 * led_value
- return voltage, brightness
- # Main loop to switch the LED on or off based on the data gathered.
- for i in range(3):
- led.value = True # Turn on the LED
- voltage, brightness = get_voltage_brightness(led.value)
- print("LED is on. Voltage: {}V, Brightness: {}%".format(voltage, brightness))
- time.sleep(1)
- led.value = False # Turn off the LED
- voltage, brightness = get_voltage_brightness(led.value)
- print("LED is off. Voltage: {}V, Brightness: {}%".format(voltage, brightness))
- time.sleep(1)
- if i == 2:
- break
- print("Done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement