-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbutton_test.py
More file actions
executable file
·49 lines (38 loc) · 1.45 KB
/
button_test.py
File metadata and controls
executable file
·49 lines (38 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright 2020-2021 by Murray Altheim. All rights reserved. This file is part
# of the Robot Operating System project, released under the MIT License. Please
# see the LICENSE file included as part of this package.
#
# This tests the Button task, which reads the state of the push button.
#
import os, sys, signal, time
from colorama import init, Fore, Style
init()
from lib.button import Button
from lib.logger import Level
# ..............................................................................
def callback_method(value):
global activated
activated = True
# activated = True if False else False
print('button_test :' + Fore.CYAN + ' INFO : callback method fired; value: {:d}'.format(value) + Style.RESET_ALL)
# call main ....................................................................
def main():
global activated
activated = False
print('button_test :' + Fore.CYAN + ' INFO : starting test...' + Style.RESET_ALL)
_pin = 12
_button = Button(_pin, callback_method, Level.INFO)
try:
while not activated:
print(Fore.BLACK + 'waiting for button press on pin {:d}...'.format(_pin) + Style.RESET_ALL)
time.sleep(1.0)
except KeyboardInterrupt:
print(Fore.RED + "caught Ctrl-C." + Style.RESET_ALL)
finally:
print("closing button...")
_button.close()
if __name__== "__main__":
main()