1
0
This repository has been archived on 2024-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
ProgramChooser/example/randomblink.py
2024-03-10 16:31:09 +01:00

49 lines
1.6 KiB
Python

"""
An example "program" which can be used with the ProgramChooser library, see also main.py
Copyright (C) 2024 Benjamin Burkhardt <bluefox@privacynerd.de>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
"""
# Feature: blink pico's onboard led (GPIO25) randomly
"""
from machine import Pin
from time import sleep
import random
def run():
# Initialisierung von GPIO25 als Ausgang
led_onboard = Pin(25, Pin.OUT)
pause_counter = 0
counter = 0
# repeat for some time (as it's randomly you don't really now)
# approx ~30s
while counter < 30:
# turn LED on
led_onboard.on()
# wait a short time (80ms)
sleep(0.08)
# turn LED off
led_onboard.off()
# wait a shorter time (20ms)
sleep(0.02)
pause_counter += 1
# make a pause (1s) randomly
if pause_counter > random.randint(6,20):
sleep(1)
print(counter)
counter += 1
if __name__ == "__main__":
run()