![](/media/cache/profiles/Chris_Profile_Pic_kyGJjzP.jpg.50x50_q85.jpg)
test program for apps shield
Dependencies: C12832_lcd_fork LM75B MMA7660 mbed C027
main.cpp@2:134ff7c6ed07, 2014-02-06 (annotated)
- Committer:
- sam_grove
- Date:
- Thu Feb 06 21:06:51 2014 +0000
- Revision:
- 2:134ff7c6ed07
- Parent:
- 1:c409f3abab09
added flow to test entire shield with terminal
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris | 0:0325ecbd1916 | 1 | #include "mbed.h" |
sam_grove | 2:134ff7c6ed07 | 2 | #include "C027.h" |
chris | 0:0325ecbd1916 | 3 | |
sam_grove | 2:134ff7c6ed07 | 4 | #include "C12832_lcd.h" |
sam_grove | 2:134ff7c6ed07 | 5 | C12832_LCD lcd(D11, D13, D12, D7, D10); |
chris | 0:0325ecbd1916 | 6 | |
chris | 0:0325ecbd1916 | 7 | #include "LM75B.h" |
sam_grove | 2:134ff7c6ed07 | 8 | LM75B sensor(D14, D15); |
sam_grove | 2:134ff7c6ed07 | 9 | |
chris | 0:0325ecbd1916 | 10 | #include "MMA7660.h" |
sam_grove | 2:134ff7c6ed07 | 11 | MMA7660 MMA(D14, D15); |
chris | 0:0325ecbd1916 | 12 | |
sam_grove | 2:134ff7c6ed07 | 13 | PwmOut spkr(D6); |
chris | 0:0325ecbd1916 | 14 | |
sam_grove | 2:134ff7c6ed07 | 15 | AnalogIn pot1 (A0); |
sam_grove | 2:134ff7c6ed07 | 16 | AnalogIn pot2 (A1); |
chris | 0:0325ecbd1916 | 17 | |
sam_grove | 2:134ff7c6ed07 | 18 | DigitalIn up(A2); |
sam_grove | 2:134ff7c6ed07 | 19 | DigitalIn down(A3); |
sam_grove | 2:134ff7c6ed07 | 20 | DigitalIn left(A4); |
sam_grove | 2:134ff7c6ed07 | 21 | AnalogIn right(A5); |
sam_grove | 2:134ff7c6ed07 | 22 | DigitalIn center(D4); |
chris | 0:0325ecbd1916 | 23 | |
sam_grove | 2:134ff7c6ed07 | 24 | DigitalOut redled(D5); |
sam_grove | 2:134ff7c6ed07 | 25 | DigitalOut blueled(D8); |
sam_grove | 2:134ff7c6ed07 | 26 | DigitalOut greenled(D9); |
chris | 0:0325ecbd1916 | 27 | |
sam_grove | 2:134ff7c6ed07 | 28 | Serial pc(USBTX, USBRX); |
chris | 0:0325ecbd1916 | 29 | |
sam_grove | 2:134ff7c6ed07 | 30 | void clearConsole() |
sam_grove | 2:134ff7c6ed07 | 31 | { |
sam_grove | 2:134ff7c6ed07 | 32 | lcd.cls(); |
sam_grove | 2:134ff7c6ed07 | 33 | lcd.locate(0,3); |
sam_grove | 2:134ff7c6ed07 | 34 | while(pc.readable()) { |
sam_grove | 2:134ff7c6ed07 | 35 | int c = pc.getc(); |
sam_grove | 2:134ff7c6ed07 | 36 | } |
sam_grove | 2:134ff7c6ed07 | 37 | } |
chris | 0:0325ecbd1916 | 38 | |
chris | 0:0325ecbd1916 | 39 | int main() |
chris | 0:0325ecbd1916 | 40 | { |
chris | 0:0325ecbd1916 | 41 | |
chris | 0:0325ecbd1916 | 42 | redled = 1; |
chris | 0:0325ecbd1916 | 43 | blueled =1; |
chris | 0:0325ecbd1916 | 44 | greenled=1; |
chris | 0:0325ecbd1916 | 45 | int i=0; |
sam_grove | 2:134ff7c6ed07 | 46 | |
sam_grove | 2:134ff7c6ed07 | 47 | puts("LCD Test"); |
chris | 0:0325ecbd1916 | 48 | |
sam_grove | 2:134ff7c6ed07 | 49 | while (!pc.readable()) { |
sam_grove | 2:134ff7c6ed07 | 50 | lcd.cls(); |
sam_grove | 2:134ff7c6ed07 | 51 | lcd.locate(0,3); |
sam_grove | 2:134ff7c6ed07 | 52 | lcd.printf("woot! %d!",i); |
sam_grove | 2:134ff7c6ed07 | 53 | i++; |
sam_grove | 2:134ff7c6ed07 | 54 | redled = !redled; |
sam_grove | 2:134ff7c6ed07 | 55 | wait(1.0); |
sam_grove | 2:134ff7c6ed07 | 56 | } |
sam_grove | 2:134ff7c6ed07 | 57 | |
sam_grove | 2:134ff7c6ed07 | 58 | clearConsole(); |
sam_grove | 2:134ff7c6ed07 | 59 | puts("Joystick Test"); |
sam_grove | 2:134ff7c6ed07 | 60 | |
sam_grove | 2:134ff7c6ed07 | 61 | while (!pc.readable()) { |
sam_grove | 2:134ff7c6ed07 | 62 | redled = !up && ! down; |
sam_grove | 2:134ff7c6ed07 | 63 | blueled = !center; |
sam_grove | 2:134ff7c6ed07 | 64 | greenled= !left && !right; |
sam_grove | 2:134ff7c6ed07 | 65 | } |
sam_grove | 2:134ff7c6ed07 | 66 | |
sam_grove | 2:134ff7c6ed07 | 67 | clearConsole(); |
sam_grove | 2:134ff7c6ed07 | 68 | puts("Pot Test"); |
sam_grove | 2:134ff7c6ed07 | 69 | |
sam_grove | 2:134ff7c6ed07 | 70 | while (!pc.readable()) { |
sam_grove | 2:134ff7c6ed07 | 71 | redled = 1; |
sam_grove | 2:134ff7c6ed07 | 72 | wait(pot1.read()); |
sam_grove | 2:134ff7c6ed07 | 73 | redled = 0; |
sam_grove | 2:134ff7c6ed07 | 74 | wait(pot2.read()); |
sam_grove | 2:134ff7c6ed07 | 75 | } |
sam_grove | 2:134ff7c6ed07 | 76 | |
sam_grove | 2:134ff7c6ed07 | 77 | clearConsole(); |
sam_grove | 2:134ff7c6ed07 | 78 | puts("Pot Test 2"); |
sam_grove | 2:134ff7c6ed07 | 79 | |
sam_grove | 2:134ff7c6ed07 | 80 | while (!pc.readable()) { |
sam_grove | 2:134ff7c6ed07 | 81 | lcd.cls(); |
sam_grove | 2:134ff7c6ed07 | 82 | lcd.locate(0,3); |
sam_grove | 2:134ff7c6ed07 | 83 | lcd.printf("%.3f %.3f %.3f", pot1.read(),pot2.read(), right.read()); |
sam_grove | 2:134ff7c6ed07 | 84 | wait(0.2); |
sam_grove | 2:134ff7c6ed07 | 85 | } |
sam_grove | 2:134ff7c6ed07 | 86 | |
sam_grove | 2:134ff7c6ed07 | 87 | clearConsole(); |
sam_grove | 2:134ff7c6ed07 | 88 | puts("Accel / Temp Test"); |
sam_grove | 2:134ff7c6ed07 | 89 | |
sam_grove | 2:134ff7c6ed07 | 90 | while (!pc.readable()) { |
sam_grove | 2:134ff7c6ed07 | 91 | lcd.cls(); |
sam_grove | 2:134ff7c6ed07 | 92 | lcd.locate(0,3); |
sam_grove | 2:134ff7c6ed07 | 93 | lcd.printf("Temp = %.3f", (float)sensor); |
sam_grove | 2:134ff7c6ed07 | 94 | lcd.locate(0,14); |
sam_grove | 2:134ff7c6ed07 | 95 | lcd.printf("x=%.2f y=%.2f z=%.2f",MMA.x(), MMA.y(), MMA.z()); |
sam_grove | 2:134ff7c6ed07 | 96 | blueled = !blueled; |
sam_grove | 2:134ff7c6ed07 | 97 | greenled = !greenled; |
sam_grove | 2:134ff7c6ed07 | 98 | wait(1.0); |
sam_grove | 2:134ff7c6ed07 | 99 | i++; |
sam_grove | 2:134ff7c6ed07 | 100 | } |
sam_grove | 2:134ff7c6ed07 | 101 | |
sam_grove | 2:134ff7c6ed07 | 102 | clearConsole(); |
sam_grove | 2:134ff7c6ed07 | 103 | puts("Speaker Test"); |
sam_grove | 2:134ff7c6ed07 | 104 | |
sam_grove | 2:134ff7c6ed07 | 105 | for(int j=0; j<3; j++) { |
sam_grove | 2:134ff7c6ed07 | 106 | for (float i=2000.0; i<4000.0; i+=100) { |
sam_grove | 2:134ff7c6ed07 | 107 | spkr.period(1.0/i); |
sam_grove | 2:134ff7c6ed07 | 108 | spkr=0.5; |
sam_grove | 2:134ff7c6ed07 | 109 | wait(0.1); |
sam_grove | 2:134ff7c6ed07 | 110 | } |
sam_grove | 2:134ff7c6ed07 | 111 | spkr=0.0; |
sam_grove | 2:134ff7c6ed07 | 112 | wait(2.0f); |
sam_grove | 2:134ff7c6ed07 | 113 | } |
sam_grove | 2:134ff7c6ed07 | 114 | |
sam_grove | 2:134ff7c6ed07 | 115 | puts("Test Complete"); |
chris | 0:0325ecbd1916 | 116 | } |
chris | 0:0325ecbd1916 | 117 | |
chris | 0:0325ecbd1916 | 118 |