Skip to content

Commit d3fc1cb

Browse files
committed
Simplify code using conditional expressions
1 parent 999ca3c commit d3fc1cb

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

examples/circuitplayground_buttons_1_neopixel.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,5 @@
66
cpx.pixels.fill((0, 0, 0)) # Turn off the NeoPixels if they're on!
77

88
while True:
9-
if cpx.button_a:
10-
cpx.pixels[2] = (0, 255, 0)
11-
else:
12-
cpx.pixels[2] = (0, 0, 0)
13-
14-
if cpx.button_b:
15-
cpx.pixels[7] = (0, 0, 255)
16-
else:
17-
cpx.pixels[7] = (0, 0, 0)
9+
cpx.pixels[2] = (0, 255, 0) if cpx.button_a else (0, 0, 0)
10+
cpx.pixels[7] = (0, 0, 255) if cpx.button_b else (0, 0, 0)

0 commit comments

Comments
 (0)