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

Dependencies:   mbed

/media/uploads/strain11/inicial1.jpg /media/uploads/strain11/drawing11.jpg

Committer:
strain11
Date:
Sun Mar 22 21:16:41 2015 +0000
Revision:
1:5b588cbaccae
Parent:
0:87236080673f
Child:
2:4601839c95d1
baud rate change to 115200

Who changed what in which revision?

UserRevisionLine numberNew 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 1:5b588cbaccae 10
strain11 1:5b588cbaccae 11 //==============================================================
strain11 0:87236080673f 12 char contador ;
strain11 0:87236080673f 13 int temp_led;
strain11 0:87236080673f 14 //int i;
strain11 0:87236080673f 15 //--------------------------------------------------------------
strain11 0:87236080673f 16 //==============================================================
strain11 0:87236080673f 17 void sw1_release(void)
strain11 0:87236080673f 18 {
strain11 0:87236080673f 19
strain11 0:87236080673f 20 pc.printf("\n");
strain11 0:87236080673f 21 pc.printf("-------------------------------------------\n");
strain11 0:87236080673f 22 pc.printf("-----------SW1 PRESSED: BARGRAPH-----------\n");
strain11 0:87236080673f 23 pc.printf("-------------------------------------------\n");
strain11 0:87236080673f 24 pc.printf("----------------PERCENTAGE-----------------\n");
strain11 0:87236080673f 25 pc.printf("0--------25--------50--------75--------100\n");
strain11 0:87236080673f 26
strain11 0:87236080673f 27
strain11 0:87236080673f 28 for(int i=0 ; i<=40 ; i++)
strain11 0:87236080673f 29 {
strain11 0:87236080673f 30
strain11 0:87236080673f 31 pc.printf("|");
strain11 0:87236080673f 32 led_2 = !led_2;
strain11 0:87236080673f 33 wait(0.050);
strain11 0:87236080673f 34 }
strain11 0:87236080673f 35 pc.printf("\n");
strain11 0:87236080673f 36 pc.printf("-------------------------------------------\n");
strain11 0:87236080673f 37 }
strain11 0:87236080673f 38 //-------------------------------------------------------------
strain11 0:87236080673f 39 //==============================================================
strain11 0:87236080673f 40 void sw2_release(void)
strain11 0:87236080673f 41
strain11 0:87236080673f 42 {
strain11 0:87236080673f 43 wait(.011);
strain11 0:87236080673f 44 contador = contador + 1;
strain11 0:87236080673f 45 led_red = !led_red;
strain11 0:87236080673f 46 temp_led = led_red;
strain11 0:87236080673f 47 pc.printf("BUTTON SW2 PRESSED ");
strain11 0:87236080673f 48 //-----------------------------------------------------------
strain11 0:87236080673f 49 if (contador < 2){
strain11 0:87236080673f 50 pc.printf("%d",contador);
strain11 0:87236080673f 51 pc.printf(" TIME");
strain11 0:87236080673f 52 }
strain11 0:87236080673f 53 else {
strain11 0:87236080673f 54 pc.printf("%d",contador);
strain11 0:87236080673f 55 pc.printf(" TIMES");
strain11 0:87236080673f 56 }
strain11 0:87236080673f 57 //-----------------------------------------------------------
strain11 0:87236080673f 58 pc.printf("\n");
strain11 0:87236080673f 59
strain11 0:87236080673f 60 //-----------------------------------------------------
strain11 0:87236080673f 61 if (temp_led == 1) {
strain11 0:87236080673f 62 pc.printf("LED RED OFF");
strain11 0:87236080673f 63 pc.printf("\n");
strain11 0:87236080673f 64 }
strain11 0:87236080673f 65 else {
strain11 0:87236080673f 66 pc.printf("RED LED ON");
strain11 0:87236080673f 67 pc.printf("\n");
strain11 0:87236080673f 68 }
strain11 0:87236080673f 69 //------------------------------------------------------------------
strain11 0:87236080673f 70 pc.printf("-------------------------------------------\n");
strain11 0:87236080673f 71 pc.printf(" CHART HOW MANY TIMES WAS PRESSED SW2 \n");
strain11 0:87236080673f 72
strain11 0:87236080673f 73 pc.printf("----------------PERCENTAGE-----------------\n");
strain11 0:87236080673f 74 pc.printf("0--------25--------50--------75--------100\n");
strain11 0:87236080673f 75 for(int i=1 ; i<=contador ; i++)
strain11 0:87236080673f 76 {
strain11 0:87236080673f 77
strain11 0:87236080673f 78 pc.printf("|");
strain11 0:87236080673f 79
strain11 0:87236080673f 80 wait(0.050);
strain11 0:87236080673f 81 }
strain11 0:87236080673f 82 pc.printf("\n");
strain11 0:87236080673f 83 pc.printf("-------------------------------------------\n");
strain11 0:87236080673f 84 pc.printf("===========================================\n");
strain11 0:87236080673f 85 //------------------------------------------------------------------
strain11 0:87236080673f 86 led_3 = 0;
strain11 0:87236080673f 87 pc.printf("LED BLUE ON [TWO SECONDS]");
strain11 0:87236080673f 88 pc.printf("\n");
strain11 1:5b588cbaccae 89
strain11 1:5b588cbaccae 90 pc.printf("W");
strain11 1:5b588cbaccae 91 wait(2.0/40);
strain11 1:5b588cbaccae 92 pc.printf("A");
strain11 1:5b588cbaccae 93 wait(2.0/40);
strain11 1:5b588cbaccae 94 pc.printf("I");
strain11 1:5b588cbaccae 95 wait(2.0/40);
strain11 1:5b588cbaccae 96 pc.printf("T");
strain11 1:5b588cbaccae 97 wait(2.0/40);
strain11 1:5b588cbaccae 98 pc.printf(" ");
strain11 1:5b588cbaccae 99 wait(2.0/40);
strain11 1:5b588cbaccae 100 pc.printf("2");
strain11 1:5b588cbaccae 101 wait(2.0/40);
strain11 1:5b588cbaccae 102 pc.printf(" ");
strain11 1:5b588cbaccae 103 wait(2.0/4);
strain11 1:5b588cbaccae 104 pc.printf("S");
strain11 1:5b588cbaccae 105 wait(2.0/43);
strain11 1:5b588cbaccae 106 pc.printf("E");
strain11 1:5b588cbaccae 107 wait(2.0/43);
strain11 1:5b588cbaccae 108 pc.printf("C");
strain11 1:5b588cbaccae 109 wait(2.0/43);
strain11 1:5b588cbaccae 110 pc.printf("O");
strain11 1:5b588cbaccae 111 wait(2.0/43);
strain11 1:5b588cbaccae 112 pc.printf("N");
strain11 1:5b588cbaccae 113 wait(2.0/43);
strain11 1:5b588cbaccae 114 pc.printf("D");
strain11 1:5b588cbaccae 115 wait(2.0/43);
strain11 1:5b588cbaccae 116 pc.printf("S");
strain11 1:5b588cbaccae 117 wait(2.0/43);
strain11 1:5b588cbaccae 118
strain11 1:5b588cbaccae 119 for(char i=0 ; i<=25 ; i++)
strain11 0:87236080673f 120 {
strain11 1:5b588cbaccae 121 pc.printf(".");
strain11 0:87236080673f 122
strain11 1:5b588cbaccae 123 wait(2.0/40);
strain11 0:87236080673f 124 }
strain11 0:87236080673f 125 pc.printf("\n");
strain11 0:87236080673f 126 pc.printf("===========================================\n");
strain11 0:87236080673f 127
strain11 0:87236080673f 128 led_3 = 1;
strain11 0:87236080673f 129 if (contador > 40){
strain11 0:87236080673f 130 contador = 0;
strain11 0:87236080673f 131 pc.printf("*******************************************\n");
strain11 0:87236080673f 132 pc.printf(" COUNTER RESET, START NEW CYCLE \n");
strain11 0:87236080673f 133 pc.printf("*******************************************\n");
strain11 0:87236080673f 134 }
strain11 0:87236080673f 135
strain11 0:87236080673f 136 }
strain11 0:87236080673f 137 //-----------------------------------------------------------------------
strain11 0:87236080673f 138
strain11 0:87236080673f 139 //------------------------------------------------------------------------
strain11 0:87236080673f 140 int main()
strain11 0:87236080673f 141
strain11 0:87236080673f 142 {
strain11 1:5b588cbaccae 143
strain11 1:5b588cbaccae 144 pc.baud(115200);
strain11 0:87236080673f 145 led_3 = 1;
strain11 0:87236080673f 146 wait(2.0);
strain11 0:87236080673f 147 pc.printf("-------------------------------------------\n");
strain11 0:87236080673f 148 pc.printf("** SERIAL ENABLED! **\n");
strain11 0:87236080673f 149 pc.printf("-------------------------------------------\n");
strain11 0:87236080673f 150 pc.printf("* TEST PROGRAM BOARD FRDM-K64F *\n");
strain11 0:87236080673f 151 pc.printf("-------------------------------------------\n");
strain11 0:87236080673f 152 pc.printf("* 120MHz, 256KB RAM, 1MB FLASH *\n");
strain11 0:87236080673f 153 pc.printf("-------------------------------------------\n");
strain11 0:87236080673f 154 pc.printf("* PRESS SW2: CONTROL RED LED *\n");
strain11 0:87236080673f 155 pc.printf("-------------------------------------------\n");
strain11 0:87236080673f 156 pc.printf("* PRESS SW1: SHOW GRAPHIC BARS *\n");
strain11 0:87236080673f 157 pc.printf("-------------------------------------------\n");
strain11 0:87236080673f 158 pc.printf("* MBED COMPILER [21/03/2015] *\n");
strain11 0:87236080673f 159 pc.printf("-------------------------------------------\n");
strain11 0:87236080673f 160 pc.printf("===========================================\n");
strain11 0:87236080673f 161 pc.printf("\n");
strain11 0:87236080673f 162 pc.printf("\n");
strain11 0:87236080673f 163 sw2.rise(&sw2_release);
strain11 0:87236080673f 164 sw1.rise(&sw1_release);
strain11 0:87236080673f 165 while (true) {
strain11 0:87236080673f 166 }
strain11 0:87236080673f 167 }