-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_voltage.py
72 lines (55 loc) · 1.75 KB
/
read_voltage.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import smbus
import os
import time
import threading
from servo_voltage.JsonWorker import JsonWorker
# init I2C for RGB indicator
bus = smbus.SMBus(1)
# Set switch to False
#switch = False
def ledOnPower():
# Clear RGB Matrix
mass = [170, 255, 0, 0, 0, 0, 5, 0]
bus.write_i2c_block_data(0x5f, 0, mass)
time.sleep(0.005)
mass = [170, 255, 0, 0, 0, 0, 5, 0]
bus.write_i2c_block_data(0x5E, 0, mass)
time.sleep(0.005)
# On Leds of RGB Matrix
mass = [170, 0xFC, 2, 1, 44, 1, 4, 0]
bus.write_i2c_block_data(0x5F, 0, mass)
time.sleep(0.005)
mass = [170, 0xFC, 2, 1, 44, 1, 4, 0]
bus.write_i2c_block_data(0x5E, 0, mass)
def ledOffPower():
# Clear RGB Matrix
mass = [170, 255, 0, 0, 0, 0, 5, 0]
bus.write_i2c_block_data(0x5f, 0, mass)
time.sleep(0.005)
mass = [170, 255, 0, 0, 0, 0, 5, 0]
bus.write_i2c_block_data(0x5E, 0, mass)
time.sleep(0.005)
def readFromFile():
#global switch
# with open('/home/pi/adam/batterylevel.txt', 'r') as batteryLevelFile:
voltage = JsonWorker.ReadFromJson()['servo_voltage']
if voltage <= 15: # and switch == False:
threading.Timer(1.0, playMessage).start()
#switch = True
ledOnPower()
if voltage > 15: # and switch == True:
#switch = False
threading.Timer(1.0, playMessage).cancel()
ledOffPower()
def playMessage():
os.system('mplayer "/home/pi/Music/prj-bat-low-15.mp3" & ')
# while 1:
# servo_voltage = ServoVoltage().GetVoltage(13)
#
# if servo_voltage in range(0, 100):
# with open('/home/pi/adam/batterylevel.txt', 'w') as batterylevwrite: batterylevwrite.write(str(servo_voltage))
#
# time.sleep(1.0)
# readFromFile()