My take on a demo for the Freescale FRDM KL25Z board showing off it's main features all at once together with USB CDC serial.
Dependencies: FRDM_MMA8451Q TSI USBDevice mbed
main.cpp@4:85ecc94a7643, 2013-11-21 (annotated)
- Committer:
- shutay
- Date:
- Thu Nov 21 06:49:25 2013 +0000
- Revision:
- 4:85ecc94a7643
- Parent:
- 1:32eacc4f6beb
- Child:
- 5:55ef207399fb
My take on a small demo program for the Freescale FRDM KL25Z board that shows off a few of it's capabilities in one single program. USB CDC Serial, capacitive touch, accelerometer and RGB LED.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shutay | 4:85ecc94a7643 | 1 | //*********************************************************** |
shutay | 4:85ecc94a7643 | 2 | // Freescale Freedom KL25Z Demo |
shutay | 4:85ecc94a7643 | 3 | // Jason CJ Tay (jason.tay@vagler.com) |
shutay | 4:85ecc94a7643 | 4 | // 30 October 2013 |
shutay | 4:85ecc94a7643 | 5 | //*********************************************************** |
shutay | 4:85ecc94a7643 | 6 | // Key things demo'd: |
shutay | 4:85ecc94a7643 | 7 | // 1. USB application serial, USB CDC serial, not over the debug port. |
shutay | 4:85ecc94a7643 | 8 | // 2. Capacitive Touch |
shutay | 4:85ecc94a7643 | 9 | // 3. Accelerometer |
shutay | 4:85ecc94a7643 | 10 | // 4. RGB LED |
shutay | 4:85ecc94a7643 | 11 | //*********************************************************** |
emilmont | 0:f59179afee57 | 12 | |
shutay | 4:85ecc94a7643 | 13 | #include "mbed.h" |
shutay | 4:85ecc94a7643 | 14 | #include "USBSerial.h" |
shutay | 4:85ecc94a7643 | 15 | #include "TSISensor.h" |
shutay | 4:85ecc94a7643 | 16 | #include "MMA8451Q.h" |
shutay | 4:85ecc94a7643 | 17 | |
shutay | 4:85ecc94a7643 | 18 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
emilmont | 0:f59179afee57 | 19 | |
shutay | 4:85ecc94a7643 | 20 | // Freescale Freedom KL25Z board has an RGB LED on it. |
shutay | 4:85ecc94a7643 | 21 | DigitalOut ledRed(LED_RED); |
shutay | 4:85ecc94a7643 | 22 | DigitalOut ledGreen(LED_GREEN); |
shutay | 4:85ecc94a7643 | 23 | DigitalOut ledBlue(LED_BLUE); |
shutay | 4:85ecc94a7643 | 24 | |
shutay | 4:85ecc94a7643 | 25 | // Setup the serial over USB virtual COM port. |
shutay | 4:85ecc94a7643 | 26 | //Serial pc(USBTX,USBRX); |
shutay | 4:85ecc94a7643 | 27 | USBSerial pc; |
shutay | 4:85ecc94a7643 | 28 | |
shutay | 4:85ecc94a7643 | 29 | int main() |
shutay | 4:85ecc94a7643 | 30 | { |
shutay | 4:85ecc94a7643 | 31 | char c; |
emilmont | 0:f59179afee57 | 32 | int i=0; |
shutay | 4:85ecc94a7643 | 33 | TSISensor tsi; |
shutay | 4:85ecc94a7643 | 34 | MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); |
shutay | 4:85ecc94a7643 | 35 | |
emilmont | 0:f59179afee57 | 36 | pc.printf("\nHello World!\n"); |
shutay | 4:85ecc94a7643 | 37 | |
emilmont | 1:32eacc4f6beb | 38 | while (true) { |
shutay | 4:85ecc94a7643 | 39 | pc.printf("\nTell me what you want!\nPress 't' to read the capacitive touch slider...\nPress 'a' to read the accelerometer...\n"); |
shutay | 4:85ecc94a7643 | 40 | pc.printf("Press 'r' to turn the LED red...\nPress 'g' to turn the LED green...\nPress 'b' to turn the LED blue...\n>>>\n"); |
shutay | 4:85ecc94a7643 | 41 | c = pc.getc(); |
shutay | 4:85ecc94a7643 | 42 | switch(c) { |
shutay | 4:85ecc94a7643 | 43 | case 't': |
shutay | 4:85ecc94a7643 | 44 | pc.printf("The current touch sensor reading is %f\n", tsi.readPercentage()); |
shutay | 4:85ecc94a7643 | 45 | break; |
shutay | 4:85ecc94a7643 | 46 | case 'a': |
shutay | 4:85ecc94a7643 | 47 | pc.printf("X: %f\nY: %f\nZ: %f\n", acc.getAccX(), acc.getAccY(), acc.getAccZ()); |
shutay | 4:85ecc94a7643 | 48 | break; |
shutay | 4:85ecc94a7643 | 49 | case 'r': |
shutay | 4:85ecc94a7643 | 50 | for(int j=0; j<4; j++) { |
shutay | 4:85ecc94a7643 | 51 | wait(0.5); |
shutay | 4:85ecc94a7643 | 52 | pc.printf("%d\n",i); |
shutay | 4:85ecc94a7643 | 53 | i++; |
shutay | 4:85ecc94a7643 | 54 | ledRed = !ledRed; |
shutay | 4:85ecc94a7643 | 55 | } |
shutay | 4:85ecc94a7643 | 56 | break; |
shutay | 4:85ecc94a7643 | 57 | case 'g': |
shutay | 4:85ecc94a7643 | 58 | for(int j=0; j<4; j++) { |
shutay | 4:85ecc94a7643 | 59 | wait(0.5); |
shutay | 4:85ecc94a7643 | 60 | pc.printf("%d\n",i); |
shutay | 4:85ecc94a7643 | 61 | i++; |
shutay | 4:85ecc94a7643 | 62 | ledGreen = !ledGreen; |
shutay | 4:85ecc94a7643 | 63 | } |
shutay | 4:85ecc94a7643 | 64 | break; |
shutay | 4:85ecc94a7643 | 65 | case 'b': |
shutay | 4:85ecc94a7643 | 66 | for(int j=0; j<4; j++) { |
shutay | 4:85ecc94a7643 | 67 | wait(0.5); |
shutay | 4:85ecc94a7643 | 68 | pc.printf("%d\n",i); |
shutay | 4:85ecc94a7643 | 69 | i++; |
shutay | 4:85ecc94a7643 | 70 | ledBlue = !ledBlue; |
shutay | 4:85ecc94a7643 | 71 | } |
shutay | 4:85ecc94a7643 | 72 | break; |
shutay | 4:85ecc94a7643 | 73 | default: |
shutay | 4:85ecc94a7643 | 74 | pc.printf("Oops. Don't have anything for you. Please try again.\n\n"); |
shutay | 4:85ecc94a7643 | 75 | } |
emilmont | 0:f59179afee57 | 76 | } |
emilmont | 0:f59179afee57 | 77 | } |