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:
Mon Mar 23 03:50:12 2015 +0000
Revision:
2:4601839c95d1
Parent:
1:5b588cbaccae
ADDED MSG STRINGS

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