-
Notifications
You must be signed in to change notification settings - Fork 3
/
sm_dust.py
118 lines (102 loc) · 1.83 KB
/
sm_dust.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import time as t
import RPi.GPIO as rp
import smtplib as s
rp.setmode(rp.BOARD)
rp.setwarnings(False)
l=[11,13,21,31,33,35,37]
def distance():
rp.output(21,1)
t.sleep(0.001)
rp.output(21,0)
while(rp.input(19)==0):
pass
st=t.time()
while(rp.input(19)==1):
pass
stopt=t.time()
tt=stopt-st
d=34300*tt/2
return d
rp.setup(19,rp.IN)
for i in l:
rp.setup(i,rp.OUT)
def checked(c):
if((c&0x01)==0):
rp.output(11,0)
else:
rp.output(11,1)
if((c&0x02)==0):
rp.output(13,0)
else:
rp.output(13,1)
if((c&0x10)==0):
rp.output(31,0)
else:
rp.output(31,1)
if((c&0x20)==0):
rp.output(33,0)
else:
rp.output(33,1)
if((c&0x40)==0):
rp.output(35,0)
else:
rp.output(35,1)
if((c&0x80)==0):
rp.output(37,0)
else:
rp.output(37,1)
def cmd(c):
d=c&0xF0
d=d+0x02
checked(d)
t.sleep(0.001)
d=d-0x02
checked(d)
d=(c<<4)&0xf0
d=d+0x02
checked(d)
t.sleep(0.001)
d=d-0x02
checked(d)
def data(c):
d=c&0xF0
d=d+0x03
checked(d)
t.sleep(0.001)
d=d-0x02
checked(d)
d=(c<<4)&0xf0
d=d+0x03
checked(d)
t.sleep(0.001)
d=d-0x02
checked(d)
def init():
cmd(0x02)
cmd(0x28)
cmd(0x06)
cmd(0x0C)
def clear():
cmd(0x01)
t.sleep(0.001)
init()
def string(s):
l=len(s)
for i in range(0,l):
data(ord(s[i]))
cmd(0x80)
while(1):
clear()
dis=distance()
if(dis<20):
print("keep going")
string('Dustbin is full')
cmd(0xc0)
string("mail sent")
t.sleep(2)
else:
print("empty now")
string("*Smart Dustbin*")
cmd(0xc0)
string("**it's empty now**")
t.sleep(2)