This program exercises many of the peripherials including serial communication (prints bargraph on screen), as well as pushbutton (SW1 and SW2) and led red/blue usage. Based on Freescale program: frdm_helloworld, see http://developer.mbed.org/teams/Freescale/code/frdm_helloworld/?platform=FRDM-K64F REVISIONS: PC.BAUD = 115200-FAST, ADDED MSG STRINGS
main.cpp@0:87236080673f, 2015-03-22 (annotated)
- Committer:
- strain11
- Date:
- Sun Mar 22 19:08:17 2015 +0000
- Revision:
- 0:87236080673f
- Child:
- 1:5b588cbaccae
FRDM_K64F example program. This program exercises many of the peripherials including serial (prints bargraph), as well as pushbutton with interupts ; Led red and blue usage (based on Freescale program frdm_helloworld).
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
strain11 | 0:87236080673f | 1 | #include "mbed.h" |
strain11 | 0:87236080673f | 2 | |
strain11 | 0:87236080673f | 3 | DigitalOut led_red(LED_RED); |
strain11 | 0:87236080673f | 4 | DigitalOut led_3(LED_BLUE); |
strain11 | 0:87236080673f | 5 | DigitalOut led_2(LED_GREEN); |
strain11 | 0:87236080673f | 6 | InterruptIn sw2(SW2); |
strain11 | 0:87236080673f | 7 | InterruptIn sw1(PTA4); |
strain11 | 0:87236080673f | 8 | Serial pc(USBTX, USBRX); |
strain11 | 0:87236080673f | 9 | //============================================================== |
strain11 | 0:87236080673f | 10 | char contador ; |
strain11 | 0:87236080673f | 11 | int temp_led; |
strain11 | 0:87236080673f | 12 | //int i; |
strain11 | 0:87236080673f | 13 | //-------------------------------------------------------------- |
strain11 | 0:87236080673f | 14 | //============================================================== |
strain11 | 0:87236080673f | 15 | void sw1_release(void) |
strain11 | 0:87236080673f | 16 | { |
strain11 | 0:87236080673f | 17 | |
strain11 | 0:87236080673f | 18 | pc.printf("\n"); |
strain11 | 0:87236080673f | 19 | pc.printf("-------------------------------------------\n"); |
strain11 | 0:87236080673f | 20 | pc.printf("-----------SW1 PRESSED: BARGRAPH-----------\n"); |
strain11 | 0:87236080673f | 21 | pc.printf("-------------------------------------------\n"); |
strain11 | 0:87236080673f | 22 | pc.printf("----------------PERCENTAGE-----------------\n"); |
strain11 | 0:87236080673f | 23 | pc.printf("0--------25--------50--------75--------100\n"); |
strain11 | 0:87236080673f | 24 | |
strain11 | 0:87236080673f | 25 | |
strain11 | 0:87236080673f | 26 | for(int i=0 ; i<=40 ; i++) |
strain11 | 0:87236080673f | 27 | { |
strain11 | 0:87236080673f | 28 | |
strain11 | 0:87236080673f | 29 | pc.printf("|"); |
strain11 | 0:87236080673f | 30 | led_2 = !led_2; |
strain11 | 0:87236080673f | 31 | wait(0.050); |
strain11 | 0:87236080673f | 32 | } |
strain11 | 0:87236080673f | 33 | pc.printf("\n"); |
strain11 | 0:87236080673f | 34 | pc.printf("-------------------------------------------\n"); |
strain11 | 0:87236080673f | 35 | } |
strain11 | 0:87236080673f | 36 | //------------------------------------------------------------- |
strain11 | 0:87236080673f | 37 | //============================================================== |
strain11 | 0:87236080673f | 38 | void sw2_release(void) |
strain11 | 0:87236080673f | 39 | |
strain11 | 0:87236080673f | 40 | { |
strain11 | 0:87236080673f | 41 | wait(.011); |
strain11 | 0:87236080673f | 42 | contador = contador + 1; |
strain11 | 0:87236080673f | 43 | led_red = !led_red; |
strain11 | 0:87236080673f | 44 | temp_led = led_red; |
strain11 | 0:87236080673f | 45 | pc.printf("BUTTON SW2 PRESSED "); |
strain11 | 0:87236080673f | 46 | //----------------------------------------------------------- |
strain11 | 0:87236080673f | 47 | if (contador < 2){ |
strain11 | 0:87236080673f | 48 | pc.printf("%d",contador); |
strain11 | 0:87236080673f | 49 | pc.printf(" TIME"); |
strain11 | 0:87236080673f | 50 | } |
strain11 | 0:87236080673f | 51 | else { |
strain11 | 0:87236080673f | 52 | pc.printf("%d",contador); |
strain11 | 0:87236080673f | 53 | pc.printf(" TIMES"); |
strain11 | 0:87236080673f | 54 | } |
strain11 | 0:87236080673f | 55 | //----------------------------------------------------------- |
strain11 | 0:87236080673f | 56 | pc.printf("\n"); |
strain11 | 0:87236080673f | 57 | |
strain11 | 0:87236080673f | 58 | //----------------------------------------------------- |
strain11 | 0:87236080673f | 59 | if (temp_led == 1) { |
strain11 | 0:87236080673f | 60 | pc.printf("LED RED OFF"); |
strain11 | 0:87236080673f | 61 | pc.printf("\n"); |
strain11 | 0:87236080673f | 62 | } |
strain11 | 0:87236080673f | 63 | else { |
strain11 | 0:87236080673f | 64 | pc.printf("RED LED ON"); |
strain11 | 0:87236080673f | 65 | pc.printf("\n"); |
strain11 | 0:87236080673f | 66 | } |
strain11 | 0:87236080673f | 67 | //------------------------------------------------------------------ |
strain11 | 0:87236080673f | 68 | pc.printf("-------------------------------------------\n"); |
strain11 | 0:87236080673f | 69 | pc.printf(" CHART HOW MANY TIMES WAS PRESSED SW2 \n"); |
strain11 | 0:87236080673f | 70 | |
strain11 | 0:87236080673f | 71 | pc.printf("----------------PERCENTAGE-----------------\n"); |
strain11 | 0:87236080673f | 72 | pc.printf("0--------25--------50--------75--------100\n"); |
strain11 | 0:87236080673f | 73 | for(int i=1 ; i<=contador ; i++) |
strain11 | 0:87236080673f | 74 | { |
strain11 | 0:87236080673f | 75 | |
strain11 | 0:87236080673f | 76 | pc.printf("|"); |
strain11 | 0:87236080673f | 77 | |
strain11 | 0:87236080673f | 78 | wait(0.050); |
strain11 | 0:87236080673f | 79 | } |
strain11 | 0:87236080673f | 80 | pc.printf("\n"); |
strain11 | 0:87236080673f | 81 | pc.printf("-------------------------------------------\n"); |
strain11 | 0:87236080673f | 82 | pc.printf("===========================================\n"); |
strain11 | 0:87236080673f | 83 | //------------------------------------------------------------------ |
strain11 | 0:87236080673f | 84 | led_3 = 0; |
strain11 | 0:87236080673f | 85 | pc.printf("LED BLUE ON [TWO SECONDS]"); |
strain11 | 0:87236080673f | 86 | pc.printf("\n"); |
strain11 | 0:87236080673f | 87 | |
strain11 | 0:87236080673f | 88 | for(int i=0 ; i<=42 ; i++) |
strain11 | 0:87236080673f | 89 | { |
strain11 | 0:87236080673f | 90 | pc.printf(":"); |
strain11 | 0:87236080673f | 91 | |
strain11 | 0:87236080673f | 92 | wait(2.0/43); |
strain11 | 0:87236080673f | 93 | } |
strain11 | 0:87236080673f | 94 | pc.printf("\n"); |
strain11 | 0:87236080673f | 95 | pc.printf("===========================================\n"); |
strain11 | 0:87236080673f | 96 | |
strain11 | 0:87236080673f | 97 | led_3 = 1; |
strain11 | 0:87236080673f | 98 | if (contador > 40){ |
strain11 | 0:87236080673f | 99 | contador = 0; |
strain11 | 0:87236080673f | 100 | pc.printf("*******************************************\n"); |
strain11 | 0:87236080673f | 101 | pc.printf(" COUNTER RESET, START NEW CYCLE \n"); |
strain11 | 0:87236080673f | 102 | pc.printf("*******************************************\n"); |
strain11 | 0:87236080673f | 103 | } |
strain11 | 0:87236080673f | 104 | |
strain11 | 0:87236080673f | 105 | } |
strain11 | 0:87236080673f | 106 | //----------------------------------------------------------------------- |
strain11 | 0:87236080673f | 107 | |
strain11 | 0:87236080673f | 108 | //------------------------------------------------------------------------ |
strain11 | 0:87236080673f | 109 | int main() |
strain11 | 0:87236080673f | 110 | |
strain11 | 0:87236080673f | 111 | { |
strain11 | 0:87236080673f | 112 | led_3 = 1; |
strain11 | 0:87236080673f | 113 | wait(2.0); |
strain11 | 0:87236080673f | 114 | pc.printf("-------------------------------------------\n"); |
strain11 | 0:87236080673f | 115 | pc.printf("** SERIAL ENABLED! **\n"); |
strain11 | 0:87236080673f | 116 | pc.printf("-------------------------------------------\n"); |
strain11 | 0:87236080673f | 117 | pc.printf("* TEST PROGRAM BOARD FRDM-K64F *\n"); |
strain11 | 0:87236080673f | 118 | pc.printf("-------------------------------------------\n"); |
strain11 | 0:87236080673f | 119 | pc.printf("* 120MHz, 256KB RAM, 1MB FLASH *\n"); |
strain11 | 0:87236080673f | 120 | pc.printf("-------------------------------------------\n"); |
strain11 | 0:87236080673f | 121 | pc.printf("* PRESS SW2: CONTROL RED LED *\n"); |
strain11 | 0:87236080673f | 122 | pc.printf("-------------------------------------------\n"); |
strain11 | 0:87236080673f | 123 | pc.printf("* PRESS SW1: SHOW GRAPHIC BARS *\n"); |
strain11 | 0:87236080673f | 124 | pc.printf("-------------------------------------------\n"); |
strain11 | 0:87236080673f | 125 | pc.printf("* MBED COMPILER [21/03/2015] *\n"); |
strain11 | 0:87236080673f | 126 | pc.printf("-------------------------------------------\n"); |
strain11 | 0:87236080673f | 127 | pc.printf("===========================================\n"); |
strain11 | 0:87236080673f | 128 | pc.printf("\n"); |
strain11 | 0:87236080673f | 129 | pc.printf("\n"); |
strain11 | 0:87236080673f | 130 | sw2.rise(&sw2_release); |
strain11 | 0:87236080673f | 131 | sw1.rise(&sw1_release); |
strain11 | 0:87236080673f | 132 | while (true) { |
strain11 | 0:87236080673f | 133 | } |
strain11 | 0:87236080673f | 134 | } |