Umemura Runa / Mbed 2 deprecated minirobo_honban

Dependencies:   mbed

main.cpp

Committer:
rumemura
Date:
2020-10-09
Revision:
0:fabee0295f0e

File content as of revision 0:fabee0295f0e:

#include "mbed.h"
#include "string"

RawSerial con(p28,p27,115200);
RawSerial saber1(p13,p14,115200);
RawSerial pc (USBTX,USBRX,115200);
Ticker tras;
string tras_str = "";
string USBtx_str = "";

DigitalOut Ben1(p23); // 電磁弁
DigitalOut Ben2(p24); //電磁弁
DigitalOut LSwitch(p26); //リミットスイッチ
DigitalIn DS1(p28); //モーター
DigitalIn DS2(p27); //モーター
DigitalOut ledG(p17); //LEDgreen
DigitalOut ledR(p20); //LEDred
Ticker timer;

int speed;
int muki;

char button;
void atras()
{
    char con_c = con.getc();
    tras_str += con_c;
    if(con_c == '\n') {
        USBtx_str = tras_str;
        button = tras_str[0];
        tras_str = "";
    }
}
void aUSBtx()
{
    //con.printf("LPCtras41\n");
    //pc.printf(USBtx_str.c_str());
    pc.printf("%d\n",int(button));

}
int main()
{
    tras.attach(&aUSBtx,0.5);

    con.attach(&atras,RawSerial::RxIrq);
    while(1) {
        if(button == 1) {
            muki = 1;
            speed = 100;

            saber1.putc(132);
            saber1.putc(muki);
            saber1.putc(speed);
            saber1.putc( ( 132 + muki + speed ) & 127 );
        }
        if(button == 2) {
            muki = 0;
            speed = 100;

            saber1.putc(132);
            saber1.putc(muki);
            saber1.putc(speed);
            saber1.putc( ( 132 + muki + speed ) & 127 );
        }
    }
    if(button == 8) {
        pc.printf("8!!!!!!!!!!!");
    }


    if(button == 4) {
        Ben1 = 1;
        ledR = 1;
        wait(0.1);
        pc.printf("4!!!!!!!!!!!");
    }


    if(button == 16) {
        Ben2 = 1;
        ledG = 1;
        wait(0.1);
        pc.printf("16!!!!!!!!!!!");
    }
}