LightBlue offers some features that enable you to test devices. However, with the Bean, LightBlue also offers a Sandbox view that can interact with the connected Bean. There are three different ways the Sanbox subviews can interact with the Bean. We will be exploring with the track pad view.
This sketch lets you control your Bean's LED with the trackpad in LightBlue Explorer's Bean Sandbox. If you modify it, you can control any hardware component with the app's XY trackpad on your iOS device.
Software
* LightBlue App
* Bean Loader App for iOS
Hardware
* LightBlue Bean
* iOS device
To open the XY trackpad in your LightBlue app:
- Connect to a Bean.
- Select Options in the upper-right corner.
- Select Sandbox View.
- Select the second tab on the bottom of the screen:
*Line 1: we define a macro. The compiler can then substitute the token string for each occurrence in the source file.
*Line 4-5 : sets the variables for the control IDs
*Line 8-10: we define state variables and default values
*Line 12: is the setup function. This function is executed only once during the duration of the program.
*Line 18: is the loop function. This function is executed multiple times.
*Line 19: we read the bytes and set the variable 'length' to it.
*Line 19: if the Bean is receiving data from LightBlue, and if the buffer at a position point is equal to MSG_XYPAD_X variable, then increase the rate.
*Line 27-28: caps the the rate if it is less than 5 to 5.
*Line18-23: Creates a 4-byte long buffer and assign each index to specific values.
*Line 31-32: if the Bean is receiving data from LightBlue, and if the buffer at a position point is equal to MSG_XYPAD_Y variable, then increase the intensity.
*Line 38-41: we set the rate and Bean's LED to the new intensity and rate values.
This sketch parses incoming serial data received from LightBlue. It uses that data to set the blink rate (X axis) and intensity (Y axis) of Bean's onboard LED.
Whenever a sandbox control is changed, the following two-byte message is sent to Bean as serial data:
- Byte 1: Control ID
- Byte 2: Value
The control ID can be found on the screen for each control. For example, the XY trackpad IDs are 8 for the X value and 9 for the Y value.
The range of values depends on the type of control. Buttons and checkboxes send either 0 or 1, while the trackpad axes and sliders send values from 0 to 255.
Having trouble with this guide? Reach out to BeanTalk to get directed feedback from our developers and community!
Comments
Please log in or sign up to comment.