|
1 | 1 | import gc |
2 | 2 |
|
3 | | -import machine |
4 | 3 | import micropython |
5 | | -import utime as time |
6 | 4 |
|
7 | 5 | micropython.alloc_emergency_exception_buf(128) |
8 | 6 |
|
9 | | -for no in range(3, 0, -1): |
10 | | - print('%i main.py wait...' % no) |
11 | | - time.sleep(1) |
| 7 | +# init own stuff: |
12 | 8 |
|
13 | 9 | from watchdog import watchdog # noqa isort:skip |
14 | 10 | from wifi import wifi # noqa isort:skip |
15 | 11 | from ntp import ntp_sync # noqa isort:skip |
16 | | -from leds import power_led # noqa isort:skip |
| 12 | +from leds import power_led, relay # noqa isort:skip |
| 13 | +import button_handler # noqa isort:skip |
17 | 14 |
|
18 | 15 | print('watchdog:', watchdog) |
19 | 16 | print('wifi:', wifi) |
20 | 17 | print('ntp_sync:', ntp_sync) |
21 | 18 | print('power_led:', power_led) |
| 19 | +print('relay:', relay) |
22 | 20 |
|
23 | | - |
24 | | -def get_debounced_value(pin): |
25 | | - """get debounced value from pin by waiting for 20 msec for stable value""" |
26 | | - cur_value = pin.value() |
27 | | - stable = 0 |
28 | | - while stable < 20: |
29 | | - if pin.value() == cur_value: |
30 | | - stable = stable + 1 |
31 | | - else: |
32 | | - stable = 0 |
33 | | - cur_value = pin.value() |
34 | | - time.sleep_ms(1) |
35 | | - return cur_value |
36 | | - |
37 | | - |
38 | | -def button_pressed(pin): |
39 | | - print('button pressed...') |
40 | | - cur_button_value = get_debounced_value(pin) |
41 | | - if cur_button_value == 1: |
42 | | - if relay_pin.value() == 1: |
43 | | - print('turn off by button.') |
44 | | - relay_pin.value(0) |
45 | | - else: |
46 | | - print('turn on by button.') |
47 | | - relay_pin.value(1) |
48 | | - |
49 | | - garbage_collection() |
50 | | - |
51 | | - |
52 | | -button_pin = machine.Pin(0, machine.Pin.IN) |
53 | | -button_pin.irq(button_pressed) |
54 | | - |
| 21 | +print('main.py wait with power led flash...') |
| 22 | +power_led.flash(sleep=0.1, count=20) |
55 | 23 |
|
56 | 24 | print('gc.collect()') |
57 | 25 | gc.collect() |
58 | 26 |
|
59 | 27 |
|
| 28 | +# Start the Webserver: |
60 | 29 | from webswitch import main # noqa isort:skip |
61 | 30 | main() |
0 commit comments