-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain
47 lines (39 loc) · 1007 Bytes
/
main
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
#!/bin/bash
#
# Displaying the current time using AQM0802
# Check and rewrite I2C address
readonly DEVICE="0x3e"
#######################################
# Convert string to hexcode
# Globals:
# None
# Arguments:
# string
# Returns:
# hexcode
#######################################
function convert_hexcode() {
local string="$1"
local hexcode=""
if [[ ${#string} -ne 0 ]]; then
for index in $(seq 0 $((${#string} - 1))); do
hexcode="${hexcode} 0x$(printf "%x" \'${string:${index}:1})"
done
fi
echo ${hexcode}
}
# aqm0802 initialization
i2cset -y 1 ${DEVICE} 0 0x38 0x39 0x14 0x70 0x56 0x6c i
sleep 0.2
i2cset -y 1 ${DEVICE} 0 0x38 0x0c 0x01 i
sleep 0.2
while true; do
now=$(LANG=en_US.UTF-8 date '+%m/%d%a%H:%M:%S')
# display 1st line
display1="$(convert_hexcode ${now:0:8})"
i2cset -y 1 ${DEVICE} 0x40 ${display1} i
i2cset -y 1 ${DEVICE} 0 0xc0 b
# display 2nd line
display2="$(convert_hexcode ${now:8:8})"
i2cset -y 1 ${DEVICE} 0x40 ${display2} i
done