-
-
Save RockinPaul/e860952054ef1ee12b4019c89d4e4d61 to your computer and use it in GitHub Desktop.
Extracting BBC Micro:bit accelerometer data using Flutter Blue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// This gist assumes that Flutter Blue (https://github.com/pauldemarco/flutter_blue) is used to connect to a BBC Micro:bit | |
/// and is listening to the [device.onValueChanged] for the correct characteristic ("E95DCA4B-251D-470A-A062FA1922DFA9A8") | |
/// | |
/// this will be something similar to | |
/// | |
/// device.onValueChanged( (accChar).listen( (value){ convertRawData(value)})); | |
/// | |
/// the 'raw' listen value is a List<int> of length 6 this needs to be converted into the X,Y and Z values from the | |
/// accelerometer and is done with the function below | |
/// | |
/// The result is a List<double> with 3 values for X, Y & Z with values approx -1 to +1 | |
convertRawData(data) { | |
Uint8List reading = Uint8List.fromList(value); | |
ByteData buffer = ByteData.view(reading.buffer); | |
double x = buffer.getInt16(0, Endian.little)/1000; | |
double y = buffer.getInt16(2, Endian.little)/1000; | |
double z = buffer.getInt16(4, Endian.little)/1000; | |
return [x, y, z]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment