![MicroPython Cookbook](https://wfqqreader-1252317822.image.myqcloud.com/cover/609/36698609/b_36698609.jpg)
上QQ阅读APP看书,第一时间看更新
How to do it...
Let's perform the following steps:
- Ensure that the slide switch is flipped to the left-hand side. Run the following lines of code in the REPL:
>>> from adafruit_circuitplayground.express import cpx >>> cpx.switch True
- Change the slide switch to be flipped to the right-hand side. Run the following code block:
>>> cpx.switch False
- Add the following code to the main.py file and it will repeatedly print the state of the slide switch on execution. Turn the slide switch to the left and right to observe the change in output:
from adafruit_circuitplayground.express import cpx import time while True: print(cpx.switch) time.sleep(0.05)