Actuator Codes

In this section, we will go through each code specific for the actuator card provided in the kit. All of the codes have been separated for each card and will run independently. You will be able to find each code inside the forever loop in each mode block. The mode blocks are  inside the “if counter == number” blocks in the Combined Code.

LED

link: https://makecode.com/_7KC5FH4fPXjm

LED actuator would need a digital write block. This means that the CPX will set the voltage of the pin to HIGH (3.3Volts) or LOW (0 volts). . So, here we check if button B is pressed, if so, then we are giving the actuator pin a high signal. We can then use this voltage to turn on an LED.

Motor

link: https://makecode.com/_6hmRWEhhoi7A

The motor card is similar to the LED code. When the button A is pressed, the code digital writes A3 to HIGH, which will trigger the transistor on the card to turn the motor. To turn off, you press button B, which will digital write A3 to LOW and stop turning the motor.

Speaker

link: https://makecode.com/_EUjTozPtoAD2

The logic of the speaker card is the same as the motor card. The only difference is that Circuit Playground already has a speaker block created for you, so you can utilize that. The pin A0 is specialized for speakers and is connected to the speaker on the board: all the sound blocks will trigger the A0 pin. Instead of digital writing high, you can simply bring in the play sound block to complete the actuation. 

There is also a built-in speaker on the CPX. You would need to physically shut it off to disable this speaker so that you can hear your own speaker. To do this, you simply need to tape the special pin on the back of the CPX to Ground, using conductive tape. See images below.

On the right, conductive tape has been used to connect the speaker pin to Ground. Make sure that the copper (or conductive fabric) tape is not covering any other areas than the third circle on the right and the ground pin.

Accessing separated code

Below, you can find both sensor and actuator codes in blocks separated from the combined code. You can reference these blocks to create your own code.

link: https://makecode.com/_3b13hA8JfAAR