zinnet yazıcı
/
BMA220
j
main.cpp@1:dc9389ccc09d, 2019-09-11 (annotated)
- Committer:
- zinnetyazicii53
- Date:
- Wed Sep 11 12:15:15 2019 +0000
- Revision:
- 1:dc9389ccc09d
- Parent:
- 0:d861e7a56281
commit to pass repo another account
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
zinnetyazicii53 | 1:dc9389ccc09d | 1 | #include "mbed.h" |
zinnetyazicii53 | 1:dc9389ccc09d | 2 | #include "math.h" |
zinnetyazicii53 | 1:dc9389ccc09d | 3 | #include "bma220.h" |
zinnetyazicii53 | 1:dc9389ccc09d | 4 | #include "thermistor.h" |
zinnetyazicii53 | 0:d861e7a56281 | 5 | |
zinnetyazicii53 | 0:d861e7a56281 | 6 | Serial pc(USBTX, USBRX); |
zinnetyazicii53 | 1:dc9389ccc09d | 7 | AnalogIn ain(A0); |
zinnetyazicii53 | 0:d861e7a56281 | 8 | |
zinnetyazicii53 | 0:d861e7a56281 | 9 | void display(Quanterion Q){ |
zinnetyazicii53 | 1:dc9389ccc09d | 10 | pc.printf("%f+ %fi+ %fj+ %fk \t Angle is: %f\n",Q.q0, Q.q1, Q.q2, Q.q3, Q.angle); |
zinnetyazicii53 | 0:d861e7a56281 | 11 | } |
zinnetyazicii53 | 0:d861e7a56281 | 12 | |
zinnetyazicii53 | 0:d861e7a56281 | 13 | int main() { |
zinnetyazicii53 | 0:d861e7a56281 | 14 | pc.baud(115200); |
zinnetyazicii53 | 1:dc9389ccc09d | 15 | |
zinnetyazicii53 | 1:dc9389ccc09d | 16 | I2C i2c(I2C_SDA, I2C_SCL); |
zinnetyazicii53 | 1:dc9389ccc09d | 17 | i2c.frequency(400000); |
zinnetyazicii53 | 1:dc9389ccc09d | 18 | BMA220 Sensor(&i2c); |
zinnetyazicii53 | 1:dc9389ccc09d | 19 | Thermistor thermistor(&ain); |
zinnetyazicii53 | 1:dc9389ccc09d | 20 | |
zinnetyazicii53 | 0:d861e7a56281 | 21 | if (!Sensor.begin()) { |
zinnetyazicii53 | 0:d861e7a56281 | 22 | pc.printf("No valid BMA220 sensor found, check wiring"); |
zinnetyazicii53 | 0:d861e7a56281 | 23 | } |
zinnetyazicii53 | 0:d861e7a56281 | 24 | // Set sensor sensitivity to 4g |
zinnetyazicii53 | 0:d861e7a56281 | 25 | Sensor.setRegister(SENSITIVITY_REG, SENS_2g); |
zinnetyazicii53 | 0:d861e7a56281 | 26 | |
zinnetyazicii53 | 0:d861e7a56281 | 27 | while(1){ |
zinnetyazicii53 | 0:d861e7a56281 | 28 | Sensor.readAcceleration(64); |
zinnetyazicii53 | 0:d861e7a56281 | 29 | pc.printf("x-axis: "); |
zinnetyazicii53 | 0:d861e7a56281 | 30 | pc.printf("%f\n", Sensor.getAcceleration_X()); |
zinnetyazicii53 | 0:d861e7a56281 | 31 | pc.printf("y-axis: "); |
zinnetyazicii53 | 0:d861e7a56281 | 32 | pc.printf("%f\n",Sensor.getAcceleration_Y()); |
zinnetyazicii53 | 0:d861e7a56281 | 33 | pc.printf("z-axis: "); |
zinnetyazicii53 | 0:d861e7a56281 | 34 | pc.printf("%f\n",Sensor.getAcceleration_Z()); |
zinnetyazicii53 | 0:d861e7a56281 | 35 | |
zinnetyazicii53 | 0:d861e7a56281 | 36 | pc.printf("rho: "); |
zinnetyazicii53 | 0:d861e7a56281 | 37 | pc.printf("%f\n",Sensor.getPitch()); |
zinnetyazicii53 | 0:d861e7a56281 | 38 | |
zinnetyazicii53 | 0:d861e7a56281 | 39 | pc.printf("phi: "); |
zinnetyazicii53 | 0:d861e7a56281 | 40 | pc.printf("%f\n",Sensor.getRoll()); |
zinnetyazicii53 | 0:d861e7a56281 | 41 | |
zinnetyazicii53 | 0:d861e7a56281 | 42 | pc.printf("theta: "); |
zinnetyazicii53 | 0:d861e7a56281 | 43 | pc.printf("%f\n",Sensor.getTheta()); |
zinnetyazicii53 | 0:d861e7a56281 | 44 | |
zinnetyazicii53 | 0:d861e7a56281 | 45 | pc.printf("Mag: "); |
zinnetyazicii53 | 0:d861e7a56281 | 46 | pc.printf("%f\n",Sensor.getMag()); |
zinnetyazicii53 | 0:d861e7a56281 | 47 | |
zinnetyazicii53 | 0:d861e7a56281 | 48 | Sensor.FallDetection(); |
zinnetyazicii53 | 0:d861e7a56281 | 49 | display(Sensor.Q_result1); |
zinnetyazicii53 | 0:d861e7a56281 | 50 | display(Sensor.Q_result2); |
zinnetyazicii53 | 0:d861e7a56281 | 51 | |
zinnetyazicii53 | 0:d861e7a56281 | 52 | wait(1); |
zinnetyazicii53 | 1:dc9389ccc09d | 53 | } |
zinnetyazicii53 | 0:d861e7a56281 | 54 | } |