43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
import StepperL298M
|
|
import time
|
|
import uasyncio as asyncio
|
|
|
|
class StepperClock:
|
|
def __init__(self,stepperHour,stepperMin):
|
|
self._stepperMinute = stepperMin
|
|
self._stepperHour = stepperHour
|
|
self.started_async = False
|
|
self._async_running = False
|
|
|
|
def start(self):
|
|
if not self.started_async:
|
|
self.started_async = True
|
|
self._stepperMinute.start()
|
|
self._stepperHour.start()
|
|
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]
|
|
self._stepperHour.rotateTo(1-((hour%12)/12+minute/(12*60)))
|
|
self._stepperMinute.rotateTo(1-minute/60)
|
|
|
|
def disablePower(self):
|
|
self._stepperHour.disablePower()
|
|
self._stepperMinute.disablePower()
|
|
#self._stepperHour.disablePower()
|
|
|
|
def isRunning(self):
|
|
return self._async_running
|