mbed同士の間に線をつなぐだけで通信確認できるやつです。

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //送信側
00002 #include "mbed.h"
00003 
00004 Serial rs485(p9,p10);
00005 Serial pc(USBTX,USBRX);
00006 
00007 DigitalOut Driver(p5);
00008 
00009 //int message1 = 0;
00010 //int message2 = 0;
00011 int loopcounter = 0;
00012 
00013 int main(){
00014     rs485.baud(38400);
00015     Driver = 1;
00016     while(1){
00017           loopcounter++;//byteで宣言したほうがいいかも
00018    int analog_num1 = ((loopcounter / 10) * 10) % 150;
00019 int analog_num2 = ((loopcounter / 10) * 10) % 150;
00020 //putcがうまくいきにくい感がある
00021   rs485.printf("A");
00022    rs485.putc(analog_num1);
00023    pc.printf("%d\n\r",analog_num2);
00024    rs485.printf("B");
00025    rs485.putc(analog_num2);
00026    //pc.printf("%d\n\r",analog_num2);
00027    wait_ms(50);
00028         }
00029 }