Chris Styles
/
apps-shield-pots
Test program for mbed app shield pots
Fork of mbed-app-shield by
main.cpp@1:e50da1f1f653, 2014-01-08 (annotated)
- Committer:
- chris
- Date:
- Wed Jan 08 16:58:55 2014 +0000
- Revision:
- 1:e50da1f1f653
- Parent:
- 0:cca95aa94e09
- Child:
- 2:989f84939300
added Temp Accelerometer;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris | 0:cca95aa94e09 | 1 | #include "mbed.h" |
chris | 0:cca95aa94e09 | 2 | #include "C12832_lcd.h" |
chris | 0:cca95aa94e09 | 3 | |
chris | 1:e50da1f1f653 | 4 | #include "LM75B.h" |
chris | 1:e50da1f1f653 | 5 | #include "MMA7660.h" |
chris | 1:e50da1f1f653 | 6 | |
chris | 0:cca95aa94e09 | 7 | // Map the LPC1768 pins to the arduino pin names |
chris | 0:cca95aa94e09 | 8 | // These are the only things that are constant between ARCH, FRDM, u-blox etc |
chris | 0:cca95aa94e09 | 9 | #define ARD_D5 P2_1 |
chris | 0:cca95aa94e09 | 10 | #define ARD_D7 P2_11 |
chris | 0:cca95aa94e09 | 11 | #define ARD_D10 P1_21 |
chris | 0:cca95aa94e09 | 12 | #define ARD_D11 P1_24 |
chris | 0:cca95aa94e09 | 13 | #define ARD_D12 P1_23 |
chris | 0:cca95aa94e09 | 14 | #define ARD_D13 P1_20 |
chris | 1:e50da1f1f653 | 15 | #define ARD_SDA P0_0 |
chris | 1:e50da1f1f653 | 16 | #define ARD_SCL P0_1 |
chris | 0:cca95aa94e09 | 17 | |
chris | 0:cca95aa94e09 | 18 | DigitalOut redled(ARD_D5); |
chris | 0:cca95aa94e09 | 19 | |
chris | 1:e50da1f1f653 | 20 | LM75B sensor(ARD_SDA,ARD_SCL); |
chris | 1:e50da1f1f653 | 21 | MMA7660 MMA(ARD_SDA,ARD_SCL); |
chris | 1:e50da1f1f653 | 22 | |
chris | 0:cca95aa94e09 | 23 | // ==== Using SDK primitives ====== |
chris | 0:cca95aa94e09 | 24 | // Construct the required pin functions, this works! |
chris | 0:cca95aa94e09 | 25 | |
chris | 0:cca95aa94e09 | 26 | /* |
chris | 0:cca95aa94e09 | 27 | DigitalOut a_d7 (ARD_D7); // a0 |
chris | 0:cca95aa94e09 | 28 | DigitalOut a_d10 (ARD_D10); // nCS |
chris | 0:cca95aa94e09 | 29 | DigitalOut a_d12 (ARD_D12); // reset |
chris | 0:cca95aa94e09 | 30 | SPI myspi (ARD_D11,NC,ARD_D13); // MOSI |
chris | 0:cca95aa94e09 | 31 | */ |
chris | 0:cca95aa94e09 | 32 | |
chris | 0:cca95aa94e09 | 33 | |
chris | 0:cca95aa94e09 | 34 | // ==== Using the LCD library ====== |
chris | 0:cca95aa94e09 | 35 | |
chris | 0:cca95aa94e09 | 36 | // Use my fork of the original library that allows pin names to be passed in |
chris | 0:cca95aa94e09 | 37 | // This works on KL25Z and Seeedstudio Arch |
chris | 0:cca95aa94e09 | 38 | // C12832_LCD(PinName mosi, PinName sck, PinName reset, PinName a0, PinName ncs, const char* name = "LCD"); |
chris | 0:cca95aa94e09 | 39 | // using this causes the program to hang |
chris | 0:cca95aa94e09 | 40 | C12832_LCD lcd(ARD_D11, ARD_D13, ARD_D12, ARD_D7, ARD_D10); |
chris | 0:cca95aa94e09 | 41 | |
chris | 0:cca95aa94e09 | 42 | |
chris | 0:cca95aa94e09 | 43 | |
chris | 0:cca95aa94e09 | 44 | int main() |
chris | 0:cca95aa94e09 | 45 | { |
chris | 0:cca95aa94e09 | 46 | |
chris | 0:cca95aa94e09 | 47 | int i=0; |
chris | 1:e50da1f1f653 | 48 | |
chris | 1:e50da1f1f653 | 49 | |
chris | 1:e50da1f1f653 | 50 | |
chris | 1:e50da1f1f653 | 51 | while(1) { |
chris | 1:e50da1f1f653 | 52 | lcd.cls(); |
chris | 1:e50da1f1f653 | 53 | lcd.locate(0,3); |
chris | 1:e50da1f1f653 | 54 | lcd.printf("Temp = %.3f", (float)sensor); |
chris | 1:e50da1f1f653 | 55 | lcd.locate(0,14); |
chris | 1:e50da1f1f653 | 56 | lcd.printf("x=%.2f y=%.2f z=%.2f",MMA.x(), MMA.y(), MMA.z()); |
chris | 1:e50da1f1f653 | 57 | redled = !redled; |
chris | 1:e50da1f1f653 | 58 | wait(1.0); |
chris | 1:e50da1f1f653 | 59 | i++; |
chris | 1:e50da1f1f653 | 60 | |
chris | 1:e50da1f1f653 | 61 | } |
chris | 1:e50da1f1f653 | 62 | |
chris | 1:e50da1f1f653 | 63 | |
chris | 1:e50da1f1f653 | 64 | |
chris | 1:e50da1f1f653 | 65 | |
chris | 1:e50da1f1f653 | 66 | |
chris | 1:e50da1f1f653 | 67 | |
chris | 1:e50da1f1f653 | 68 | /* |
chris | 1:e50da1f1f653 | 69 | |
chris | 1:e50da1f1f653 | 70 | |
chris | 1:e50da1f1f653 | 71 | |
chris | 1:e50da1f1f653 | 72 | |
chris | 0:cca95aa94e09 | 73 | while(1) { |
chris | 0:cca95aa94e09 | 74 | |
chris | 0:cca95aa94e09 | 75 | // === USING THE LCD ==== |
chris | 0:cca95aa94e09 | 76 | // Note that the program will hang, even if we do not call any of the LCD functions |
chris | 0:cca95aa94e09 | 77 | // Is it the cosntructor breaking things |
chris | 1:e50da1f1f653 | 78 | lcd.cls(); |
chris | 1:e50da1f1f653 | 79 | lcd.locate(0,3); |
chris | 1:e50da1f1f653 | 80 | lcd.printf("Hello %d",i); |
chris | 0:cca95aa94e09 | 81 | |
chris | 0:cca95aa94e09 | 82 | |
chris | 0:cca95aa94e09 | 83 | // === USING THE SDK Primitives === |
chris | 0:cca95aa94e09 | 84 | // If we just use the SPI and DigitalOut, instead we can access them happily |
chris | 0:cca95aa94e09 | 85 | // and the program runs |
chris | 0:cca95aa94e09 | 86 | // a_d7 = !a_d7; |
chris | 0:cca95aa94e09 | 87 | // a_d10 = !a_d10; |
chris | 0:cca95aa94e09 | 88 | // a_d12 = !a_d12; |
chris | 0:cca95aa94e09 | 89 | // myspi.write(i); |
chris | 0:cca95aa94e09 | 90 | |
chris | 0:cca95aa94e09 | 91 | |
chris | 0:cca95aa94e09 | 92 | wait(0.2); |
chris | 0:cca95aa94e09 | 93 | redled = !redled; // I have an red LED on my test board.. for sanity :) |
chris | 0:cca95aa94e09 | 94 | i++; |
chris | 0:cca95aa94e09 | 95 | } |
chris | 1:e50da1f1f653 | 96 | */ |
chris | 1:e50da1f1f653 | 97 | |
chris | 1:e50da1f1f653 | 98 | |
chris | 1:e50da1f1f653 | 99 | |
chris | 0:cca95aa94e09 | 100 | |
chris | 0:cca95aa94e09 | 101 | } |