TP7_DS_7_Correction
Dependencies: C12832 MMA7660 mbed
Fork of app-shield-accelerometer by
main.cpp@6:305ed72790a4, 2015-11-02 (annotated)
- Committer:
- rtk
- Date:
- Mon Nov 02 22:36:41 2015 +0000
- Revision:
- 6:305ed72790a4
- Parent:
- 5:636ebfdf373b
.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreschpe | 0:f6a57b843f79 | 1 | #include "mbed.h" |
chris | 3:2db94ee076ee | 2 | #include "C12832.h" |
chris | 5:636ebfdf373b | 3 | #include "MMA7660.h" |
dreschpe | 0:f6a57b843f79 | 4 | |
chris | 4:39c7c31b8fb0 | 5 | // Using Arduino pin notation |
chris | 4:39c7c31b8fb0 | 6 | C12832 lcd(D11, D13, D12, D7, D10); |
rtk | 6:305ed72790a4 | 7 | MMA7660 MMA(I2C_SDA,I2C_SCL); |
rtk | 6:305ed72790a4 | 8 | enum Orientation {Up, Down, |
rtk | 6:305ed72790a4 | 9 | Right, Left, |
rtk | 6:305ed72790a4 | 10 | Back, Front, |
rtk | 6:305ed72790a4 | 11 | Unknown |
rtk | 6:305ed72790a4 | 12 | }; |
dreschpe | 1:1c6a9eaf55b5 | 13 | |
dreschpe | 0:f6a57b843f79 | 14 | int main() |
dreschpe | 0:f6a57b843f79 | 15 | { |
chris | 2:a87e255a8f3a | 16 | lcd.cls(); |
chris | 2:a87e255a8f3a | 17 | lcd.locate(0,3); |
rtk | 6:305ed72790a4 | 18 | // lcd.printf("mbed application shield!"); |
dreschpe | 0:f6a57b843f79 | 19 | |
chris | 5:636ebfdf373b | 20 | while(1) { |
rtk | 6:305ed72790a4 | 21 | lcd.locate(60,0); |
rtk | 6:305ed72790a4 | 22 | lcd.printf("x=%.2f",MMA.x()); |
rtk | 6:305ed72790a4 | 23 | lcd.locate(60,8); |
rtk | 6:305ed72790a4 | 24 | lcd.printf("y=%.2f",MMA.y()); |
rtk | 6:305ed72790a4 | 25 | lcd.locate(60,16); |
rtk | 6:305ed72790a4 | 26 | lcd.printf("z=%.2f",MMA.z()); |
rtk | 6:305ed72790a4 | 27 | lcd.locate(0,8); |
rtk | 6:305ed72790a4 | 28 | if (MMA.getSide()==Front) lcd.printf("Front"); |
rtk | 6:305ed72790a4 | 29 | else if (MMA.getSide()==Back) lcd.printf("Back"); |
rtk | 6:305ed72790a4 | 30 | lcd.locate(0,16); |
rtk | 6:305ed72790a4 | 31 | switch (MMA.getOrientation()) { |
rtk | 6:305ed72790a4 | 32 | case Left : |
rtk | 6:305ed72790a4 | 33 | lcd.printf("Left"); |
rtk | 6:305ed72790a4 | 34 | break; |
rtk | 6:305ed72790a4 | 35 | case Right : |
rtk | 6:305ed72790a4 | 36 | lcd.printf("Right"); |
rtk | 6:305ed72790a4 | 37 | break; |
rtk | 6:305ed72790a4 | 38 | case Up : |
rtk | 6:305ed72790a4 | 39 | lcd.printf(" ");lcd.locate(0,16); |
rtk | 6:305ed72790a4 | 40 | lcd.printf("Up"); |
rtk | 6:305ed72790a4 | 41 | break; |
rtk | 6:305ed72790a4 | 42 | case Down : |
rtk | 6:305ed72790a4 | 43 | lcd.printf("Down"); |
rtk | 6:305ed72790a4 | 44 | break; |
rtk | 6:305ed72790a4 | 45 | } |
rtk | 6:305ed72790a4 | 46 | |
chris | 5:636ebfdf373b | 47 | wait(0.2); |
dreschpe | 0:f6a57b843f79 | 48 | } |
dreschpe | 0:f6a57b843f79 | 49 | } |