40 lines
1.0 KiB
Python
40 lines
1.0 KiB
Python
#import StepperL298M
|
|
import time
|
|
import Hardware as HW
|
|
import uasyncio as asyncio
|
|
|
|
class Clock:
|
|
def __init__(self):
|
|
self.started_async = False
|
|
self._async_running = False
|
|
|
|
def start(self):
|
|
if not self.started_async:
|
|
self.started_async = True
|
|
loop = asyncio.get_event_loop()
|
|
loop.create_task(self._update_async())
|
|
|
|
def stop(self):
|
|
self._async_running = False
|
|
self.started_async = False
|
|
|
|
async def _update_async(self):
|
|
self._async_running = True
|
|
while(self._async_running):
|
|
self.update()
|
|
await asyncio.sleep(1)
|
|
|
|
def update(self):
|
|
hour = time.localtime()[3]
|
|
minute = time.localtime()[4]
|
|
HW.motorHour.rotateTo(1-((hour%12)/12+minute/(12*60)))
|
|
HW.motorMinu.rotateTo(1-minute/60)
|
|
|
|
def disablePower(self):
|
|
HW.motorHour.disablePower()
|
|
HW.motorMinu.disablePower()
|
|
#HW.stepperhour.disablePower()
|
|
|
|
def isRunning(self):
|
|
return self._async_running
|