test water meter
Dependencies: MAG3110 MMA8451Q TSI mbed
main.cpp@1:43d8cd5f8197, 2015-10-15 (annotated)
- Committer:
- ratsept
- Date:
- Thu Oct 15 12:01:53 2015 +0000
- Revision:
- 1:43d8cd5f8197
- Parent:
- 0:6e75a6dbdc05
mj?u
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ratsept | 0:6e75a6dbdc05 | 1 | #include "mbed.h" |
ratsept | 0:6e75a6dbdc05 | 2 | #include "MMA8451Q.h" |
ratsept | 0:6e75a6dbdc05 | 3 | #include "MAG3110.h" |
ratsept | 0:6e75a6dbdc05 | 4 | |
ratsept | 0:6e75a6dbdc05 | 5 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
ratsept | 0:6e75a6dbdc05 | 6 | |
ratsept | 0:6e75a6dbdc05 | 7 | Serial pc(USBTX,USBRX); |
ratsept | 0:6e75a6dbdc05 | 8 | |
ratsept | 0:6e75a6dbdc05 | 9 | int main(void) { |
ratsept | 0:6e75a6dbdc05 | 10 | |
ratsept | 0:6e75a6dbdc05 | 11 | MAG3110 mag(PTE0,PTE1,&pc); |
ratsept | 1:43d8cd5f8197 | 12 | //mag.setCalibration(64140,64550,900,1145); |
ratsept | 0:6e75a6dbdc05 | 13 | |
ratsept | 0:6e75a6dbdc05 | 14 | MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); |
ratsept | 0:6e75a6dbdc05 | 15 | PwmOut rled(LED_RED); |
ratsept | 0:6e75a6dbdc05 | 16 | PwmOut gled(LED_GREEN); |
ratsept | 0:6e75a6dbdc05 | 17 | PwmOut bled(LED_BLUE); |
ratsept | 0:6e75a6dbdc05 | 18 | |
ratsept | 0:6e75a6dbdc05 | 19 | int x,y,z; |
ratsept | 1:43d8cd5f8197 | 20 | int xnew = 0; |
ratsept | 0:6e75a6dbdc05 | 21 | |
ratsept | 0:6e75a6dbdc05 | 22 | while (true) { |
ratsept | 0:6e75a6dbdc05 | 23 | mag.getValues(&x, &y, &z); |
ratsept | 1:43d8cd5f8197 | 24 | pc.printf("%d %d %d\n\r", x, y, z); |
ratsept | 1:43d8cd5f8197 | 25 | |
ratsept | 1:43d8cd5f8197 | 26 | float xnew = x; |
ratsept | 1:43d8cd5f8197 | 27 | float ynew = y; |
ratsept | 1:43d8cd5f8197 | 28 | float znew = z; |
ratsept | 1:43d8cd5f8197 | 29 | |
ratsept | 0:6e75a6dbdc05 | 30 | rled = 1.0 - abs(float(x)/65535); |
ratsept | 0:6e75a6dbdc05 | 31 | gled = 1.0 - abs(float(y)/65535); |
ratsept | 0:6e75a6dbdc05 | 32 | bled = 1.0 - abs(float(z)/65535); |
ratsept | 1:43d8cd5f8197 | 33 | |
ratsept | 1:43d8cd5f8197 | 34 | |
ratsept | 0:6e75a6dbdc05 | 35 | //rled = 1.0 - abs(acc.getAccX()); |
ratsept | 0:6e75a6dbdc05 | 36 | //gled = 1.0 - abs(acc.getAccY()); |
ratsept | 0:6e75a6dbdc05 | 37 | //bled = 1.0 - abs(acc.getAccZ()); |
ratsept | 0:6e75a6dbdc05 | 38 | //mag.getValues(&x,&y,&z); |
ratsept | 0:6e75a6dbdc05 | 39 | //pc.printf("%f\n\r",mag.getHeading()); |
ratsept | 0:6e75a6dbdc05 | 40 | wait(0.1); |
ratsept | 0:6e75a6dbdc05 | 41 | } |
ratsept | 0:6e75a6dbdc05 | 42 | } |