Skip to content

Commit 915a604

Browse files
committed
add demo with logging
1 parent a797521 commit 915a604

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

blink1_demo/demo_logging.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
demo_logging -- simple demo of blink1 library with logging
5+
6+
run with:
7+
DEBUGLBLINK1=1 python3 ./blink1_demo/demo_logging.py
8+
9+
"""
10+
from blink1.blink1 import Blink1
11+
12+
import time,sys
13+
14+
import logging
15+
16+
logging.basicConfig()
17+
#logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)
18+
#logging.basicConfig(filename="test.log", format='%(filename)s: %(message)s', filemode='w')
19+
log = logging.getLogger(__name__)
20+
log.setLevel(logging.DEBUG)
21+
log.info("hello info")
22+
log.debug("hello debug")
23+
log.warning("hello warning")
24+
log.error("hello error")
25+
26+
try:
27+
blink1 = Blink1()
28+
except:
29+
log.error("no blink1 found")
30+
sys.exit()
31+
32+
log.info("blink(1) found")
33+
34+
log.info(" serial number: " + blink1.get_serial_number())
35+
log.info(" firmware version: " + blink1.get_version())
36+
37+
log.info("fading to #ffffff")
38+
blink1.fade_to_rgb(1000, 255, 255, 255)
39+
40+
log.info("waiting 2.5 seconds, unplug to check error raising...");
41+
time.sleep(2.5)
42+
43+
log.info("fading to #000000")
44+
blink1.fade_to_color(1000, 'black')
45+
46+
log.info("closing connection to blink(1)")
47+
blink1.close()
48+
49+
log.info("done")

0 commit comments

Comments
 (0)