Alright so we’ve learned the hard way for all the sensors using low level control of the various sensors. Let’s now import the simple adafruit_circuitplayground.express module. The Adafruit Learn site offers pretty much every example code snippet you’d ever need for all the different push buttons and sensors on the CPX[32]. Head over there if you ever need something outside of the scope of this text. As I said before, the main module you need to import is done by adding the following to the top of your code
from adafruit_circuitplayground.express import cpx
Note that if you have a CPB you need to change that line to adafruit_circuitplayground.bluefruit import cpb. Then everywhere you see cpx you replace with cpb. Also, keep in mind that you will need to install modules onto your CPX/CPB (See Section 7.2). Assuming you have the right module, the line above will import the cpx module into your working code. From here the commands to read different things are relatively simple. Here are the commands for all the various sensors
light = cpx.light
x,y,z = cpx.acceleration
temperature = cpx.temperature
There unfortunately is no simple module for the sound sensor on the CPX. You’ll still need to use the low level control no matter what. However, if you get the Circuit Playground Bluefruit there is a simple way to read the sound level using cpb.sound_level[32]. Implementing the various sensors into a while loop on my CPX looks like this.
I left out the low level sound sensor stuff just because it kind of messes with the simplicity of the code above. The adafruit_circuitplayground.express module outputs just as before except for the light sensor. In the low level control we simply computed the voltage across the photocell but the adafruit_circuitplayground.express module outputs data in Lux[62]. Recall, if you have a CPB you can use the high level cpb.sound_level command as shown in the Figure below. Notice that the import command has changed to adafruit_circuitplayground.bluefruit import cpb.
Figure15.2.2.Example High Level Sound Level on the CPB