-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add wait test scripts and button puress scripts(io.py) in twenty
- Loading branch information
1 parent
2a78b34
commit e67c09b
Showing
4 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
# led one to another | ||
# first parameter is led on time | ||
# second parameter is times of led cycle | ||
# when second parameter is less than 0; | ||
# circle reversed | ||
# when press red button | ||
# led circle quicker | ||
# when press green button | ||
# led circle slower | ||
|
||
from sys import argv | ||
import time | ||
import RPi.GPIO as GPIO | ||
from twenty_on_off import led_on | ||
from twenty_on_off import led_off | ||
from twenty_on_off import light_num | ||
GPIO.setmode(GPIO.BCM) | ||
GPIO.setwarnings(False) | ||
|
||
all_led = len(light_num) | ||
try: | ||
# ltime = float(argv[1]) | ||
repeat_time = int(argv[1]) | ||
except: | ||
ltime = 0.05 | ||
repeat_time = 5 | ||
|
||
if repeat_time < 0: | ||
cont = -1 | ||
repeat_time = abs(repeat_time) | ||
else: | ||
cont = 1 | ||
|
||
def input_check(port): | ||
button = GPIO.input(port) | ||
return (button) | ||
|
||
input_ports = [28, 30, 31] | ||
GPIO.setup(input_ports[0], GPIO.IN) | ||
GPIO.setup(input_ports[1], GPIO.OUT) | ||
GPIO.setup(input_ports[2], GPIO.IN) | ||
GPIO.output(input_ports[1], GPIO.HIGH) | ||
inputwait = 50000 | ||
|
||
for i in range(repeat_time): | ||
for led in range(all_led)[::cont]: | ||
led_begin = time.time() | ||
led_on(led) | ||
for t in range(inputwait): | ||
for port in input_ports[::2]: | ||
check = input_check(port) | ||
if check == False: | ||
if port == input_ports[0]: | ||
inputwait /= 2 | ||
elif port == input_ports[2]: | ||
inputwait *= 2 | ||
while check == False: | ||
check = input_check(port) | ||
led_off(led) | ||
led_end = time.time() | ||
print "led lights", round(led_end - led_begin, 2), "seconds." | ||
|
||
GPIO.cleanup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
# count python loop time | ||
# led on , count start, loop, count end, led off | ||
|
||
from sys import argv | ||
import time | ||
import RPi.GPIO as GPIO | ||
from twenty_on_off import led_on | ||
from twenty_on_off import led_off | ||
GPIO.setmode(GPIO.BCM) | ||
GPIO.setwarnings(False) | ||
|
||
try: | ||
repeat_time = int(argv[1]) | ||
except: | ||
print "No time to wait" | ||
exit(1) | ||
|
||
myport = 5 | ||
start = time.time() | ||
led_on(myport) | ||
for i in range(repeat_time): | ||
pass | ||
|
||
end = time.time() | ||
print round(end - start, 2) | ||
led_off(myport) | ||
led_on(myport + 1) | ||
time.sleep(3) | ||
led_off(myport + 1) | ||
|
||
GPIO.cleanup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
# count python loop time | ||
# led on , count start, loop, count end, led off | ||
|
||
from sys import argv | ||
import time | ||
import RPi.GPIO as GPIO | ||
from twenty_on_off import led_on | ||
from twenty_on_off import led_off | ||
GPIO.setmode(GPIO.BCM) | ||
GPIO.setwarnings(False) | ||
|
||
try: | ||
repeat_time = int(argv[1]) | ||
except: | ||
print ("No time to wait") | ||
exit(1) | ||
|
||
myport = 5 | ||
start = time.time() | ||
led_on(myport) | ||
for i in range(repeat_time): | ||
pass | ||
|
||
end = time.time() | ||
print (round(end - start, 2)) | ||
led_off(myport) | ||
led_on(myport + 1) | ||
time.sleep(3) | ||
led_off(myport + 1) | ||
|
||
GPIO.cleanup() |