Dec-28-2017, 10:08 PM
Hello all,
I am new to Python, hardware guy trying to learn something new and help cross the gap. I decided to make a cable checker that tests 156 pins from one connector to another and off of the user input see if the pins are connected as the user intends (i.e Pin 1 on left connector goes to Pin 30 on right connector, test and verify)
I am using MUX's to switch between SIPO shift registers and three GPIOs have to be set in order to choose each shift register (well right now the first 8 shift registers as I only have 1 MUX connected) and the same on the output.
So here is my question, I have this code:
So to follow DRY (Don't Repeat Yourself) I decided to write a function that set them accordingly, but my lack of knowledge caught up with me. I need the GPIO's to be returned from the function and set when I hit the start button in my GUI, right now I get a return of NONE or if I place this in a class I get the placeholder returned:
(pinIn is a list of values 1 - 156)
Thank you[/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i]
I am new to Python, hardware guy trying to learn something new and help cross the gap. I decided to make a cable checker that tests 156 pins from one connector to another and off of the user input see if the pins are connected as the user intends (i.e Pin 1 on left connector goes to Pin 30 on right connector, test and verify)
I am using MUX's to switch between SIPO shift registers and three GPIOs have to be set in order to choose each shift register (well right now the first 8 shift registers as I only have 1 MUX connected) and the same on the output.
So here is my question, I have this code:
def MUX1shift1_Y0(): GPIO.output(17,GPIO.LOW) GPIO.output(27,GPIO.LOW) GPIO.output(22,GPIO.LOW) def MUX1shift2_Y1(): GPIO.output(17,GPIO.HIGH) GPIO.output(27,GPIO.LOW) GPIO.output(22,GPIO.LOW) def MUX1shift3_Y2(): GPIO.output(17,GPIO.LOW) GPIO.output(27,GPIO.HIGH) GPIO.output(22,GPIO.LOW) def MUX1shift4_Y3(): GPIO.output(17,GPIO.HIGH) GPIO.output(27,GPIO.HIGH) GPIO.output(22,GPIO.LOW) def MUX1shift5_Y4(): GPIO.output(17,GPIO.LOW) GPIO.output(27,GPIO.LOW) GPIO.output(22,GPIO.HIGH) def MUX1shift6_Y5(): GPIO.output(17,GPIO.HIGH) GPIO.output(27,GPIO.LOW) GPIO.output(22,GPIO.HIGH) def MUX1shift7_Y6(): GPIO.output(17,GPIO.LOW) GPIO.output(27,GPIO.HIGH) GPIO.output(22,GPIO.HIGH) def MUX1shift8_Y7(): GPIO.output(17,GPIO.HIGH) GPIO.output(27,GPIO.HIGH) GPIO.output(22,GPIO.HIGH)Now as per each pin input by the user I have to set each of these by the range of numbers (i.e. pins 1-8 need to be set to MUX1shift1_Y0)
So to follow DRY (Don't Repeat Yourself) I decided to write a function that set them accordingly, but my lack of knowledge caught up with me. I need the GPIO's to be returned from the function and set when I hit the start button in my GUI, right now I get a return of NONE or if I place this in a class I get the placeholder returned:
(pinIn is a list of values 1 - 156)
def setMUXvalue(): for i in range (0,156): if pinIn[i] in range (1,8): return MUX1shift1_Y0() elif pinIn[i] in range (9,16): return MUX1shift2_Y1() elif pinIn[i] in range (17,24): return MUX1shift3_Y2() elif pinIn[i] in range (25,32): return MUX1shift4_Y3() elif pinIn[i] in range (33,40): return MUX1shift5_Y4() elif pinIn[i] in range (41,48): return MUX1shift6_Y5() elif pinIn[i] in range (49,56): return MUX1shift7_Y6() elif pinIn[i] in range (57,64): return MUX1shift8_Y7() elif pinIn[i] in range (65,72): return MUX2shift9_Y0() elif pinIn[i] in range (73,80): return MUX2shift10_Y1() elif pinIn[i] in range (81,88): return MUX2shift11_Y2() elif pinIn[i] in range (89,96): return MUX2shift12_Y3() elif pinIn[i] in range (97,104): return MUX2shift13_Y4() elif pinIn[i] in range (105,112): return MUX2shift14_Y5() elif pinIn[i] in range (113,120): return MUX2shift15_Y6() elif pinIn[i] in range (121,128): return MUX2shift16_Y7() elif pinIn[i] in range (129,136): return MUX3shift17_Y0() elif pinIn[i] in range (137,144): return MUX3shift18_Y1() elif pinIn[i] in range (145,152): return MUX3shift19_Y2() elif pinIn[i] in range (153,156): return MUX3shift20_Y3()Any help and explanation would be great and I am extremely grateful for any helpful pointers.
Thank you[/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i]