Adafruit Sensors: Difference between revisions
Line 27: | Line 27: | ||
[[File:Circuit playground buttons.jpg|450px|none|left|thumb|Buttons A & B]] | [[File:Circuit playground buttons.jpg|450px|none|left|thumb|Buttons A & B]] | ||
On the CPX, there are 2 buttons : <code>Button A</code> or <code>Button B</code>. The two buttons could be coded together <code> Button A + B</code>. | On the CPX, there are 2 buttons : <code>Button A</code> or <code>Button B</code>. The two buttons could be coded together <code> Button A + B</code>. | ||
; Event : the <code>OnEvent</code> block allows to respond to action (click, long click | ; Event : the <code>OnEvent</code> block allows to respond to action (click, long click and other events. | ||
; Live date : the button can be read in live by using the input <code>IsPressed</code> that is to say the code check if the button is pressed. In certain situations, if there is a lot odf | |||
== Adafruit Capacitive touch == | == Adafruit Capacitive touch == |
Revision as of 12:57, 24 September 2019
Introduction
In this article,we propose an overview of the Adafruit Circuit Playground Express (CPX) built-in sensors. This aim of this page is to show you how to leverage them in MakeCode. So, if you are not familiar with MakeCode, we advise to have a look on MakeCode page in this wiki.
The CPX built-on sensors available are :
- Buttons
- Capacitive touch
- Accelerometer
- Light sensor
- Microphone
- Switch button
- Thermometer
- Infrared Transceiver.
Coding sensors in MakeCode
In MakeCode, there are two means to read the code : through events or by reading live data:
- Events: code runs when an event is detected. For example, the
OnShake
event runs code when a certain type of shaking is detected by the accelerometer. - Live data: live reading of the sensor data without a particular event taking place. For example,
Rotation
gets a immediate reading from the accelerometer.
You will find below the 2 style of programming with sensors : through events (on left of the picture below) and through live data (on right on the picture below).
Sensors
Buttons
On the CPX, there are 2 buttons : Button A
or Button B
. The two buttons could be coded together Button A + B
.
- Event
- the
OnEvent
block allows to respond to action (click, long click and other events. - Live date
- the button can be read in live by using the input
IsPressed
that is to say the code check if the button is pressed. In certain situations, if there is a lot odf
Adafruit Capacitive touch
On the CPX, there are 7 capacitive pins (A1, A2, A3, A4, A5, A6 and A7). They can be used as buttons (like buttons A or B).
- Event
- The pins can be used as touch inputs, the code use them like buttons. Instead of saying
Button A
orButton B
as the input source, use a pin name likeA1
.
Links
- At Adafruit
Aknowledgement
Pictures as well as some text was reproduced from the Adafruit circuit playground express documentation. Some pictures are available under a CC BY-NC-SA license. Others are copyright AdaFruit and "all rights reserved" and reproduced with permission. Before you reuse any picture from this website, make sure to look at the license information.
For more information about using Adafruit, see https://learn.adafruit.com.