Skip to content

Commit

Permalink
add wait test scripts and button puress scripts(io.py) in twenty
Browse files Browse the repository at this point in the history
  • Loading branch information
sato-makoto committed May 21, 2014
1 parent 2a78b34 commit e67c09b
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 0 deletions.
Binary file added twenty/__pycache__/twenty_on_off.cpython-32.pyc
Binary file not shown.
66 changes: 66 additions & 0 deletions twenty/io.py
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()
34 changes: 34 additions & 0 deletions twenty/wait.py
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()
34 changes: 34 additions & 0 deletions twenty/wait3.py
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()

0 comments on commit e67c09b

Please sign in to comment.