Example code

Dependencies:   mbed

Committer:
MadhuraT
Date:
Wed Mar 06 23:04:28 2019 +0000
Revision:
2:384c0e3bb7ab
Parent:
1:ce08f1d8140c
EXAMPLE CODE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:0ee4748f4c5c 1 #include "mbed.h"
bcostm 0:0ee4748f4c5c 2
bcostm 1:ce08f1d8140c 3 /*------------------------------------------------------------------------------
bcostm 1:ce08f1d8140c 4 Before to use this example, ensure that you an hyperterminal installed on your
bcostm 1:ce08f1d8140c 5 computer. More info here: https://developer.mbed.org/handbook/Terminals
bcostm 1:ce08f1d8140c 6
bcostm 1:ce08f1d8140c 7 The default serial comm port uses the SERIAL_TX and SERIAL_RX pins (see their
bcostm 1:ce08f1d8140c 8 definition in the PinNames.h file).
bcostm 1:ce08f1d8140c 9
bcostm 1:ce08f1d8140c 10 The default serial configuration in this case is 9600 bauds, 8-bit data, no parity
bcostm 1:ce08f1d8140c 11
bcostm 1:ce08f1d8140c 12 If you want to change the baudrate for example, you have to redeclare the
bcostm 1:ce08f1d8140c 13 serial object in your code:
bcostm 1:ce08f1d8140c 14
bcostm 1:ce08f1d8140c 15 Serial pc(SERIAL_TX, SERIAL_RX);
bcostm 1:ce08f1d8140c 16
bcostm 1:ce08f1d8140c 17 Then, you can modify the baudrate and print like this:
bcostm 1:ce08f1d8140c 18
bcostm 1:ce08f1d8140c 19 pc.baud(115200);
bcostm 1:ce08f1d8140c 20 pc.printf("Hello World !\n");
bcostm 1:ce08f1d8140c 21 ------------------------------------------------------------------------------*/
bcostm 0:0ee4748f4c5c 22
MadhuraT 2:384c0e3bb7ab 23 DigitalOut led(LED2);
MadhuraT 2:384c0e3bb7ab 24 char buf[256];
MadhuraT 2:384c0e3bb7ab 25 CAN can1 (PB_8,PB_9);
MadhuraT 2:384c0e3bb7ab 26 char counter=0;
bcostm 0:0ee4748f4c5c 27
MadhuraT 2:384c0e3bb7ab 28 Serial pc(SERIAL_TX, SERIAL_RX);
bcostm 0:0ee4748f4c5c 29 int main()
bcostm 0:0ee4748f4c5c 30 {
bcostm 0:0ee4748f4c5c 31 int i = 1;
bcostm 0:0ee4748f4c5c 32
bcostm 0:0ee4748f4c5c 33 printf("Hello World !\n");
bcostm 0:0ee4748f4c5c 34
bcostm 0:0ee4748f4c5c 35 while(1) {
bcostm 0:0ee4748f4c5c 36 wait(1); // 1 second
MadhuraT 2:384c0e3bb7ab 37 //led = !led; // Toggle LED
MadhuraT 2:384c0e3bb7ab 38 pc.gets(buf,3);
MadhuraT 2:384c0e3bb7ab 39 if(buf[0] == 'f')
MadhuraT 2:384c0e3bb7ab 40 {
MadhuraT 2:384c0e3bb7ab 41 led =1;
MadhuraT 2:384c0e3bb7ab 42 can1.write(CANMessage(1337, &counter,1));
MadhuraT 2:384c0e3bb7ab 43 }
MadhuraT 2:384c0e3bb7ab 44 else if (buf[0] == 'g')
MadhuraT 2:384c0e3bb7ab 45 {
MadhuraT 2:384c0e3bb7ab 46 led =0;
MadhuraT 2:384c0e3bb7ab 47 }
MadhuraT 2:384c0e3bb7ab 48
MadhuraT 2:384c0e3bb7ab 49 pc.printf("buffer is %s",buf);
MadhuraT 2:384c0e3bb7ab 50
MadhuraT 2:384c0e3bb7ab 51 //printf("This program runs since %d seconds.\n", i++);
bcostm 0:0ee4748f4c5c 52 }
bcostm 0:0ee4748f4c5c 53 }