circuitplayground_acceleration_neopixels.py
1 """If the switch is to the right, it will appear that nothing is happening. Move the switch to the 2 left to see the NeoPixels light up in colors related to the accelerometer! The CPX has an 3 accelerometer in the center that returns (x, y, z) acceleration values. This program uses those 4 values to light up the NeoPixels based on those acceleration values.""" 5 from adafruit_circuitplayground.express import cpx 6 7 # Main loop gets x, y and z axis acceleration, prints the values, and turns on 8 # red, green and blue, at levels related to the x, y and z values. 9 while True: 10 if not cpx.switch: 11 # If the switch is to the right, it returns False! 12 print("Slide switch off!") 13 cpx.pixels.fill((0, 0, 0)) 14 continue 15 else: 16 R = 0 17 G = 0 18 B = 0 19 x, y, z = cpx.acceleration 20 print((x, y, z)) 21 cpx.pixels.fill(((R + abs(int(x))), (G + abs(int(y))), (B + abs(int(z)))))