I am following the Freenove code (ref:- FNK0020 page 202 https://www.freenove.com/tutorial.html) to program a stepper motor. I have simplified the code a little, in any case as far as I can tell the final GPIO.LOW seems completely redundant, am I missing something?
motor_pins = (1, 2, 3, 4)
step = (0x01, 0x02, 0x04, 0x08)
for j in range(0, 4):
for i in range(0, 4):
GPIO.output(motor_pins[i], ((step[j] == 1<<i) and GPIO.HIGH or GPIO.LOW))
so the code is cycling through each pin, for each step cycle, and the output is condition and HIGH or LOW
. For each cycle through the step, one of the pins returns HIGH
and the rest LOW
but I can't understand why the or LOW
is needed at the end because the AND
function will only return a True
condition for one of the pins while the rest will be False
therefore I think the or LOW
is redundant, can someone clarify?