-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsietes.py
More file actions
103 lines (80 loc) · 2.16 KB
/
sietes.py
File metadata and controls
103 lines (80 loc) · 2.16 KB
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
#!/usr/bin/python
# -*- coding: iso-8859-1 -*-
# Esta es la organización de un 7-segmentos.
#
# 3 0 1 2
# | | | | |
# ---------
# | ---1 |
# | |0 |2|
# | | | |
# | ---3 |
# | |4 | |
# | | 5 |6|
# | ---o7|
# ---------
# | | | | |
# 4 5 G 6 7
#
import sys
import time
try:
import RPi.GPIO as GPIO
except RuntimeError:
print "Error importando RPi.GPIO! Probablemente se deba a falta de permisos!"
sys.exit(1)
def ponerDigito(disp, digito):
cont = 0
while (cont < 8):
GPIO.output(disp[cont], numeros[digito][cont])
cont += 1
def ponerValor(valor, base, disps):
cont = 0
digito = 0
while (valor > 0) and (cont < len(disps)):
digito = valor % base
valor = valor / base
ponerDigito(disps[cont], digito)
cont += 1
numeros = {0: [1, 1, 1, 0, 1, 1, 1, 0]\
,1 : [0, 0, 1, 0, 0, 0, 1, 0]\
,2 : [0, 1, 1, 1, 1, 1, 0, 0]\
,3 : [0, 1, 1, 1, 0, 1, 1, 0]\
,4 : [1, 0, 1, 1, 0, 0, 1, 0]\
,5 : [1, 1, 0, 1, 0, 1, 1, 0]\
,6 : [1, 1, 0, 1, 1, 1, 1, 0]\
,7 : [0, 1, 1, 0, 0, 0, 1, 0]\
,8 : [1, 1, 1, 1, 1, 1, 1, 0]\
,9 : [1, 1, 1, 1, 0, 1, 1, 0]\
,10 : [1, 1, 1, 1, 1, 0, 1, 0]\
,11 : [1, 0, 0, 1, 1, 1, 1, 0]\
,12 : [1, 1, 0, 1, 1, 1, 0, 0]\
,13 : [0, 0, 1, 1, 1, 1, 1, 0]\
,14 : [1, 1, 0, 1, 1, 1, 0, 0]\
,15 : [1, 1, 1, 1, 1, 0, 0, 0]}
disp = [[2, 3, 4, 14, 15, 17, 18, 27]\
,[22, 23, 24, 10, 9, 25, 11, 8]]
valor = 0
base = 10
entrada = 7
estado = 0
estadoa = 0
try:
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(entrada, GPIO.IN)
for d in disp:
for c in d:
GPIO.setup(c, GPIO.OUT, 0)
while True:
estadoa = estado
estado = GPIO.input(entrada)
# tratando de detectar un flanco comparando el estado anterior
# de la entrada con el estado actual.
# if (estadoa == 1) and (estado == 0):
# valor += 1
ponerValor(valor, base, disp)
valor += 1
time.sleep(0.5)
finally:
GPIO.cleanup()