Example code

Dependencies:   mbed

main.cpp

Committer:
MadhuraT
Date:
2019-03-06
Revision:
2:384c0e3bb7ab
Parent:
1:ce08f1d8140c

File content as of revision 2:384c0e3bb7ab:

#include "mbed.h"

/*------------------------------------------------------------------------------
Before to use this example, ensure that you an hyperterminal installed on your
computer. More info here: https://developer.mbed.org/handbook/Terminals

The default serial comm port uses the SERIAL_TX and SERIAL_RX pins (see their
definition in the PinNames.h file).

The default serial configuration in this case is 9600 bauds, 8-bit data, no parity

If you want to change the baudrate for example, you have to redeclare the
serial object in your code:

Serial pc(SERIAL_TX, SERIAL_RX);

Then, you can modify the baudrate and print like this:

pc.baud(115200);
pc.printf("Hello World !\n");
------------------------------------------------------------------------------*/

DigitalOut led(LED2);
char buf[256];
CAN can1 (PB_8,PB_9);
char counter=0;

Serial pc(SERIAL_TX, SERIAL_RX);
int main()
{
    int i = 1;

    printf("Hello World !\n");

    while(1) {
        wait(1); // 1 second
        //led = !led; // Toggle LED
        pc.gets(buf,3);
        if(buf[0] == 'f')
        {
            led =1;
            can1.write(CANMessage(1337, &counter,1));
        }
        else if (buf[0] == 'g')
        {
            led =0;
        }
            
        pc.printf("buffer is %s",buf);
        
        //printf("This program runs since %d seconds.\n", i++);
    }
}