forked from pythoncanarias/upython
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Añado script de control de tiempo por polling (#1)
Script añadido con sus correspondientes correcciones (flake8).
- Loading branch information
1 parent
6582ae3
commit 523b4c3
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import time | ||
import machine | ||
""" dejamos el espacio de nombres sin "aplanar" | ||
es decir, NO hacemos: | ||
from machine import * """ | ||
|
||
|
||
class CuentaMs(): | ||
def __init__(self, ms): | ||
self.ms = ms | ||
self.reset() | ||
|
||
def reset(self): | ||
self.proximo = time.ticks_ms() + self.ms | ||
|
||
def comprueba(self): | ||
if self.proximo <= time.ticks_ms(): | ||
self.reset() | ||
return True | ||
else: | ||
return False | ||
|
||
|
||
PIN_LED = 16 # puede cambiar en cada placa | ||
led = machine.Pin(PIN_LED, machine.Pin.OUT) | ||
contador_ms = CuentaMs(500) | ||
|
||
while True: | ||
# hacemos el resto de tareas | ||
# ¿las insertamos aquí, o despues del if? | ||
if contador_ms.comprueba(): | ||
led.value(not led.value()) |