Punch Through
Published © MIT

LightBlue Sandbox: Trackpad Visualization

Use LightBlue Explorer for iOS to visualize your Bean's data in Bean Sandbox.

EasyProtip390
LightBlue Sandbox: Trackpad Visualization

Things used in this project

Hardware components

LightBlue Bean
Punch Through LightBlue Bean
×1

Hand tools and fabrication machines

Punch Through LightBlue Explorer for iOS

Story

Read more

Code

TrackpadVisualization.ino

Arduino
// Sandbox control IDs
char MSG_XYPAD_X = 8;
char MSG_XYPAD_Y = 9;

void setup() {
  // Bean starts serial automatically; no need to set baud rate
}

void loop() {
  AccelerationReading accel = Bean.getAcceleration();
  // Acceleration values range from -512 to 511
  // Bean Sandbox accepts values from 0 to 255
  uint8_t x_axis = map(accel.xAxis, -512, 511, 0, 255);
  uint8_t y_axis = map(accel.yAxis, -512, 511, 0, 255);

  // Construct two sandbox messages, two bytes each: set X axis, set Y axis
  char buffer[4];
  buffer[0] = MSG_XYPAD_X;
  buffer[1] = x_axis;
  buffer[2] = MSG_XYPAD_Y;
  buffer[3] = y_axis;

  // Write messages to serial and sleep for 50 ms
  uint8_t* buf = reinterpret_cast(buffer)
  Serial.write(buf, 4);
  Bean.sleep(50);
}

Credits

Punch Through

Punch Through

16 projects • 39 followers
We’ve been building connected products since 2009. Our diverse team has expertise in every layer from hardware to software to web.

Comments

Add projectSign up / Login