SciJoy
Published

Circuit Playground Express

This is an overview of how to use and code the sensors on the Circuit Playground Express. I am using MakeCode.

BeginnerProtip1 hour3,685
Circuit Playground Express

Things used in this project

Hardware components

Adafruit Circuit Playground Express Advanced Pack
This is the one I have but there are other versions. I've also adde the basic version below.
×1
Circuit Playground Express
Adafruit Circuit Playground Express
×1

Software apps and online services

MakeCode
Microsoft MakeCode

Story

Read more

Schematics

Pinouts of Circuit Playground Express

Code

MakeCode Example

JavaScript
There are links to all the code under each sensor.
// This event is triggered when the accelerometer
// detects a shaking motion.
input.onGesture(Gesture.Shake, function () {
    // A sound is played when the board detects that it is
    // shook.
    music.playSoundUntilDone(music.sounds(Sounds.PowerUp))
})
// This event is triggered when the accelerometer
// detects that the board is tilted down.
input.onGesture(Gesture.TiltDown, function () {
    // A sound is played when the board is tilted down.
    music.playSoundUntilDone(music.sounds(Sounds.JumpDown))
})
// This event is triggered when the accelerometer
// detects that the board is tilted upwards.
input.onGesture(Gesture.TiltUp, function () {
    // A sound is played when the board is tilted upwards.
    music.playSoundUntilDone(music.sounds(Sounds.JumpUp))
})
// This event is triggered when the accelerometer
// detects that the board is tilted to the left.
input.onGesture(Gesture.TiltLeft, function () {
    // A sound is played when the board is tilted to the
    // left.
    music.playTone(349, music.beat(BeatFraction.Half))
})
// This event is triggered when the accelerometer
// detects when the board is flipped face up.
input.onGesture(Gesture.FaceUp, function () {
    // A sound is played when the board overtime the board
    // is flipped face up.
    music.playTone(131, music.beat(BeatFraction.Half))
})
// This event is triggered when the accelerometer
// detects that the board is tilted to the right.
input.onGesture(Gesture.TiltRight, function () {
    // A sound is played when the board is tilted to the
    // right.
    music.playTone(988, music.beat(BeatFraction.Half))
})
// This event is triggered when the accelerometer
// detects when the board is flipped face down.
input.onGesture(Gesture.FaceDown, function () {
    // A sound is played when the board is flipped faced
    // down.
    music.playSoundUntilDone(music.sounds(Sounds.BaDing))
})
// This event is triggered when the accelerometer
// detects that the board is in free fall.
input.onGesture(Gesture.FreeFall, function () {
    // A sound is played when the board is in free fall.
    music.playSoundUntilDone(music.sounds(Sounds.Wawawawaa))
})
// This event is triggered when the accelerometer hits
// 8g.
input.onGesture(Gesture.EightG, function () {
    // A sound is played when the board reaches 8g.
    music.playSoundUntilDone(music.sounds(Sounds.MagicWand))
})
// This event is triggered when the accelerometer hits
// 3g.
input.onGesture(Gesture.ThreeG, function () {
    // A sound is played when the board reaches 3g.
    music.playSoundUntilDone(music.sounds(Sounds.Siren))
})
// This set the threshold for the accelerometer.
input.setAccelerometerRange(AcceleratorRange.OneG)
// Forever loops the step inside this block, well,
// forever. Events interrupts the steps in this block.
// In this example, the rotation of the board is
// graphed in neopixels. The lower the degrees, the
// fewer pixels are lit. It also logs the x value of
// acceleration.
forever(function () {
    // This graphs the rotation of the board. The higher
    // the angle, the more neopixels are lit.
    light.graph(input.rotation(Rotation.Pitch))
    // This logs the value of acceleration in the x
    // direction.
    console.logValue("x", input.acceleration(Dimension.X))
})

Credits

SciJoy

SciJoy

7 projects • 15 followers
We run a YouTube channel where we share what we are learning and building with others.

Comments