I'm currrently working on a simple count program for RPi-3 with a seven-segment-Display. I have two ways of counting from one to ten, one manually, always lighting up the single segments I need, and another way, which is based on a numpy matrix.
The manual way works fine but I have Problems with the matrix way of doing it. Here is the code with some explications for understanding:
import RPi.GPIO as GPIO
import time
import numpy
GPIO.setmode(GPIO.BOARD)
GPIO.setup(31, GPIO.OUT) #up right
GPIO.setup(32, GPIO.OUT) #up
GPIO.setup(33, GPIO.OUT) #up left
GPIO.setup(35, GPIO.OUT) #middle
GPIO.setup(36, GPIO.OUT) #down right
GPIO.setup(37, GPIO.OUT) #down left
GPIO.setup(38, GPIO.OUT) #decimal point(in the bottom right corner)
GPIO.setup(40, GPIO.OUT) #down
def all_off(): #turns all segments off, works as well!
GPIO.output(31, False)
GPIO.output(32, False)
GPIO.output(33, False)
GPIO.output(35, False)
GPIO.output(36, False)
GPIO.output(37, False)
GPIO.output(38, False)
GPIO.output(40, False)
matrix = numpy.matrix([[1,0,0,0,1,0,0,0], #those are the combinations
[1,1,0,1,0,1,0,1], #from one to nine and finishing
[1,1,0,1,1,0,0,1], #with zero
[1,0,1,1,1,0,0,0], #first number of a line is value for Pin31 then 32,
[0,1,1,1,1,0,0,1], #33, 35, 36, 37, 38, 40
[0,1,1,1,1,1,0,1],
[1,1,0,0,1,0,0,0], #combinations are correct, btw!
[1,1,1,1,1,1,0,1],
[1,1,1,1,1,0,0,1]])
def set_to(byte):
all_off()
GPIO.output(31, int(byte[0])) #<-- this is the line where the error
GPIO.output(32, int(byte[1])) #occurs
GPIO.output(33, int(byte[2]))
GPIO.output(35, int(byte[3]))
GPIO.output(36, int(byte[4]))
GPIO.output(37, int(byte[5]))
GPIO.output(38, int(byte[6]))
GPIO.output(40, int(byte[7]))
for line in matrix: #the actual counting program
set_to(matrix[line])
time.sleep(1)
GPIO.cleanup()
The problem is apparently, that the array can't be read? I don't get what the problem is or what to do to fix this issue. It seems to have something to do with the 'line' of the matrix is just anouther matrix(with just one line).
I really don't know what to do, please help!!