Samuel Mokrani
/
AngryBirdsFeasibility
Test Slingshot
main.cpp@0:9cfbae3af1ea, 2012-01-18 (annotated)
- Committer:
- samux
- Date:
- Wed Jan 18 14:37:06 2012 +0000
- Revision:
- 0:9cfbae3af1ea
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 0:9cfbae3af1ea | 1 | #include "mbed.h" |
samux | 0:9cfbae3af1ea | 2 | #include "USBMouse.h" |
samux | 0:9cfbae3af1ea | 3 | #include "ADXL345.h" |
samux | 0:9cfbae3af1ea | 4 | |
samux | 0:9cfbae3af1ea | 5 | Serial pc(USBTX, USBRX); |
samux | 0:9cfbae3af1ea | 6 | |
samux | 0:9cfbae3af1ea | 7 | USBMouse mouse; |
samux | 0:9cfbae3af1ea | 8 | ADXL345 acc(p5, p6, p7, p8); |
samux | 0:9cfbae3af1ea | 9 | AnalogIn strength(p15); |
samux | 0:9cfbae3af1ea | 10 | |
samux | 0:9cfbae3af1ea | 11 | |
samux | 0:9cfbae3af1ea | 12 | int main() { |
samux | 0:9cfbae3af1ea | 13 | uint16_t str = 0; |
samux | 0:9cfbae3af1ea | 14 | int readings[3]; |
samux | 0:9cfbae3af1ea | 15 | |
samux | 0:9cfbae3af1ea | 16 | //Initialize accelerometer |
samux | 0:9cfbae3af1ea | 17 | acc.setPowerControl(0x00); |
samux | 0:9cfbae3af1ea | 18 | acc.setDataFormatControl(0x0B); |
samux | 0:9cfbae3af1ea | 19 | acc.setDataRate(ADXL345_3200HZ); |
samux | 0:9cfbae3af1ea | 20 | acc.setPowerControl(0x08); |
samux | 0:9cfbae3af1ea | 21 | |
samux | 0:9cfbae3af1ea | 22 | while (1) { |
samux | 0:9cfbae3af1ea | 23 | wait(0.1); |
samux | 0:9cfbae3af1ea | 24 | |
samux | 0:9cfbae3af1ea | 25 | // test accelerometer |
samux | 0:9cfbae3af1ea | 26 | acc.getOutput(readings); |
samux | 0:9cfbae3af1ea | 27 | pc.printf("acc: %i, %i, %i\r\n", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]); |
samux | 0:9cfbae3af1ea | 28 | |
samux | 0:9cfbae3af1ea | 29 | // test strtch sensor |
samux | 0:9cfbae3af1ea | 30 | str = strength.read_u16(); |
samux | 0:9cfbae3af1ea | 31 | pc.printf("strength: %d\r\n", str); |
samux | 0:9cfbae3af1ea | 32 | |
samux | 0:9cfbae3af1ea | 33 | // test USB relative mouse |
samux | 0:9cfbae3af1ea | 34 | mouse.move(10, 10); |
samux | 0:9cfbae3af1ea | 35 | } |
samux | 0:9cfbae3af1ea | 36 | } |