send microbit compass and accelerometer data
Fork of compass_data_sender by
Revision 3:92910c8d63e4, committed 2017-02-14
- Comitter:
- kinga
- Date:
- Tue Feb 14 10:56:01 2017 +0000
- Parent:
- 2:89097482d7f1
- Child:
- 4:b8aa76f28112
- Commit message:
- refactor compass and accelerometer data sender;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Feb 09 13:17:51 2017 +0000 +++ b/main.cpp Tue Feb 14 10:56:01 2017 +0000 @@ -3,24 +3,36 @@ MicroBit uBit; MicroBitSerial serial(USBTX, USBRX); MicroBitI2C i2c(I2C_SDA0, I2C_SCL0); +MicroBitAccelerometer accelerometer(i2c); +MicroBitStorage storage; +MicroBitCompass compass(i2c, accelerometer, storage); -MicroBitAccelerometer accelerometer(i2c); +ManagedString getCompassHeading() +{ + int heading = compass.heading(); + return (ManagedString)heading; +} -MicroBitStorage storage; +ManagedString getAccelerometerVectors() +{ + int x = uBit.accelerometer.getX(); + int y = uBit.accelerometer.getY(); + int z = uBit.accelerometer.getZ(); + return (ManagedString)x + ',' + (ManagedString)y + ',' + (ManagedString)z + ','; +} -MicroBitCompass compass(i2c, accelerometer, storage); +ManagedString getMessage() +{ + return getCompassHeading() + ',' + getAccelerometerVectors(); +} int main() { uBit.init(); - while (1) { - int heading = compass.heading(); - int x = uBit.accelerometer.getX(); - int y = uBit.accelerometer.getY(); - int z = uBit.accelerometer.getZ(); - ManagedString message = (ManagedString)heading + ',' + (ManagedString)x + ',' + (ManagedString)y + ',' + (ManagedString)z + ','; - serial.send(message); + while (1) + { + serial.send(getMessage()); uBit.sleep(500); }