| Total Complexity | 5 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import logging |
||
| 2 | from curio import sleep |
||
| 3 | from bricknil import attach, start |
||
| 4 | from bricknil.hub import PoweredUpHub |
||
| 5 | from bricknil.sensor import Light |
||
| 6 | |||
| 7 | |||
| 8 | @attach(Light, name='light') |
||
| 9 | class Train(PoweredUpHub): |
||
| 10 | |||
| 11 | async def run(self): |
||
| 12 | self.message_info("Running") |
||
| 13 | self.keep_running = True |
||
| 14 | brightness = 0 |
||
| 15 | delta = 10 |
||
| 16 | |||
| 17 | while self.keep_running: |
||
| 18 | # change the brightness up and down between -100 and 100 |
||
| 19 | brightness += delta |
||
| 20 | if brightness >= 100: |
||
| 21 | delta = -10 |
||
| 22 | elif brightness <= -100: |
||
| 23 | delta = 10 |
||
| 24 | self.message_info("Brightness: {}".format(brightness)) |
||
| 25 | await self.light.set_brightness(brightness) |
||
| 26 | await sleep(1) |
||
| 27 | |||
| 28 | |||
| 29 | async def system(): |
||
| 30 | Train('My Train') |
||
| 31 | |||
| 32 | if __name__ == '__main__': |
||
| 33 | logging.basicConfig(level=logging.INFO) |
||
| 34 | start(system) |
||
| 35 |