Example code

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 /*------------------------------------------------------------------------------
00004 Before to use this example, ensure that you an hyperterminal installed on your
00005 computer. More info here: https://developer.mbed.org/handbook/Terminals
00006 
00007 The default serial comm port uses the SERIAL_TX and SERIAL_RX pins (see their
00008 definition in the PinNames.h file).
00009 
00010 The default serial configuration in this case is 9600 bauds, 8-bit data, no parity
00011 
00012 If you want to change the baudrate for example, you have to redeclare the
00013 serial object in your code:
00014 
00015 Serial pc(SERIAL_TX, SERIAL_RX);
00016 
00017 Then, you can modify the baudrate and print like this:
00018 
00019 pc.baud(115200);
00020 pc.printf("Hello World !\n");
00021 ------------------------------------------------------------------------------*/
00022 
00023 DigitalOut led(LED2);
00024 char buf[256];
00025 CAN can1 (PB_8,PB_9);
00026 char counter=0;
00027 
00028 Serial pc(SERIAL_TX, SERIAL_RX);
00029 int main()
00030 {
00031     int i = 1;
00032 
00033     printf("Hello World !\n");
00034 
00035     while(1) {
00036         wait(1); // 1 second
00037         //led = !led; // Toggle LED
00038         pc.gets(buf,3);
00039         if(buf[0] == 'f')
00040         {
00041             led =1;
00042             can1.write(CANMessage(1337, &counter,1));
00043         }
00044         else if (buf[0] == 'g')
00045         {
00046             led =0;
00047         }
00048             
00049         pc.printf("buffer is %s",buf);
00050         
00051         //printf("This program runs since %d seconds.\n", i++);
00052     }
00053 }