Skip to content

Commit

Permalink
Añado control por polling de 3 cronómeotros (#1)
Browse files Browse the repository at this point in the history
Script añadido con sus correspondientes correcciones (flake8).
  • Loading branch information
ivanhercaz committed Jun 1, 2019
1 parent 523b4c3 commit e391d53
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions ejemplos/polling_cronometros.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import time
import machine


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 = [machine.Pin(14, machine.Pin.OUT),
machine.Pin(12, machine.Pin.OUT),
machine.Pin(13, machine.Pin.OUT)]

contador_ms = [CuentaMs(1000), CuentaMs(2333), CuentaMs(1698)]

while True:
time.sleep(0.1)
for i, e in enumerate(contador_ms):
if e.comprueba():
pin[i].value(not pin[i].value())
print(" " * i, i, "ha pasado su tiempo")

0 comments on commit e391d53

Please sign in to comment.