Skip to content

Instantly share code, notes, and snippets.

@cowdinosaur
Created August 5, 2019 07:26
Show Gist options
  • Save cowdinosaur/07b07f7bc170c253536282265cb09a89 to your computer and use it in GitHub Desktop.
Save cowdinosaur/07b07f7bc170c253536282265cb09a89 to your computer and use it in GitHub Desktop.
Microbit Accelerometer Dashboard
import processing.serial.*;
Serial port;
int x, y, z, strength;
void setup() {
printArray(Serial.list());
port = new Serial(this, Serial.list()[1], 115200);
port.bufferUntil(10);
size(700, 550);
textSize(32);
}
void draw() {
background(255);
fill(0, 0, 255);
line(0, 250, 500, 250);
rect(90, 250 - x/5, 80, x/5);
rect(240, 250 - y/5, 80, y/5);
rect(390, 250 - z/5, 80, z/5);
fill(0, 0, 0);
text("X", 60, 30);
text(x, 60, 60);
text("Y", 210, 30);
text(y, 210, 60);
text("Z", 360, 30);
text(z, 360, 60);
fill(0, 255, 0);
rect(540, height - 20 - strength/5, 80, strength/5);
text("S", 510, height - 20);
text(strength, 530, 30);
fill(0, 0, 0);
text("Accelerometer Data", 30, height - 30);
}
void serialEvent(Serial port) {
String inData = port.readString();
if (inData.charAt(0) == 'a') {
inData = inData.substring(1);
inData = trim(inData);
String items[] = (split(inData, ' '));
x = int(items[0]);
y = int(items[1]);
z = int(items[2]);
strength = int(items[3]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment