Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
time-machine
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hugo Hörnquist
time-machine
Commits
cc8d5c65
Commit
cc8d5c65
authored
7 years ago
by
Hugo Hörnquist
Browse files
Options
Downloads
Patches
Plain Diff
Screen, with more
parent
1793d21a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
machine.py
+87
-42
87 additions, 42 deletions
machine.py
with
87 additions
and
42 deletions
machine.py
+
87
−
42
View file @
cc8d5c65
...
...
@@ -4,6 +4,8 @@ import RPi.GPIO as g
import
time
import
threading
import
Adafruit_CharLCD
as
LCD
# For lazer array
# if no bottle present then all are high
# if bottle at least one low
...
...
@@ -14,25 +16,50 @@ import threading
g
.
setmode
(
g
.
BCM
)
pins
=
[
17
]
btn_pin
=
22
pins
=
[
17
,
27
,
22
,
10
,
9
,
11
,
5
,
6
,
13
,
19
]
btn_pin
=
4
test
=
False
lcd_rs
=
12
lcd_en
=
7
lcd_d4
=
8
lcd_d5
=
25
lcd_d6
=
24
lcd_d7
=
23
lcd_backlight
=
2
# Define LCD column and row size for 16x2 LCD.
lcd_columns
=
16
lcd_rows
=
2
lcd
=
LCD
.
Adafruit_CharLCD
(
lcd_rs
,
lcd_en
,
lcd_d4
,
lcd_d5
,
lcd_d6
,
lcd_d7
,
lcd_columns
,
lcd_rows
,
lcd_backlight
)
last_time
=
0
risewait
=
threading
.
Event
()
fallwait
=
threading
.
Event
()
def
callback
(
pin
):
state
=
g
.
input
(
pin
)
if
state
==
g
.
LOW
:
print
"
falling edge
"
fallwait
.
set
()
else
:
print
"
rising edge
"
risewait
.
set
()
g
.
setup
(
btn_pin
,
g
.
IN
,
pull_up_down
=
g
.
PUD_DOWN
)
g
.
setup
(
3
,
g
.
IN
,
pull_up_down
=
g
.
PUD_DOWN
)
for
pin
in
pins
:
g
.
setup
(
pin
,
g
.
IN
,
pull_up_down
=
g
.
PUD_DOWN
)
g
.
add_event_detect
(
pin
,
g
.
BOTH
,
callback
=
callback
)
risewait
=
threading
.
Event
()
fallwait
=
threading
.
Event
()
def
bottle_check
(
pins
):
if
test
:
return
any
([
g
.
input
(
pin
)
for
pin
in
pins
])
else
:
return
not
all
([
g
.
input
(
pin
)
for
pin
in
pins
])
class
States
:
...
...
@@ -65,30 +92,46 @@ def wait_fall():
# should these be the other way around?
def
wait_for_bottle_place
():
#return wait_rise()
return
wait_fall
()
return
wait_rise
()
if
test
else
wait_fall
()
def
wait_for_bottle_remove
():
#return wait_fall()
return
wait_rise
()
return
wait_fall
()
if
test
else
wait_rise
()
def
lcd_info
(
msg
):
lcd
.
clear
()
lcd
.
home
()
lcd
.
set_cursor
(
0
,
0
)
lcd
.
message
(
"
Tid: {0} s
"
.
format
(
last_time
))
lcd
.
set_cursor
(
0
,
1
)
lcd
.
message
(
msg
)
def
wait_btn
():
return
g
.
wait_for_edge
(
btn_pin
,
g
.
RISING
,
bouncetime
=
500
)
#g.wait_for_edge(btn_pin, g.RISING)
if
__name__
==
"
__main__
"
:
while
True
:
if
state
==
States
.
no_hafv
:
print
print
"
Inget Hafv
"
lcd_info
(
"
Vilar
"
)
wait_for_bottle_place
()
state
=
States
.
hafv_ready
elif
state
==
States
.
hafv_ready
:
print
"
Hafv redo
"
out
=
g
.
wait_for_edge
(
btn_pin
,
g
.
RISING
)
lcd_info
(
"
Starta med knapp
"
)
wait_btn
()
state
=
States
.
hafv_active
start_time
=
time_ms
()
elif
state
==
States
.
hafv_active
:
print
"
currently Hafving
"
lcd_info
(
"
Klockar
"
)
if
not
bottle_check
(
pins
):
print
"
Early start
"
lcd_info
(
"
Tjuvstart!
"
)
wait_btn
()
state
=
States
.
no_hafv
continue
print
"
Raise the bottle
"
...
...
@@ -102,5 +145,7 @@ while True:
t
=
(
end_time
-
start_time
)
/
1000.0
print
"
Hafvtid: {0} s
"
.
format
(
t
)
last_time
=
t
lcd_info
(
"
Avvakta
"
)
state
=
States
.
no_hafv
time
.
sleep
(
1
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment