中継機能つけた受け取りオムニ

Dependencies:   mbed MultiSerial

main.cpp

Committer:
Hatter
Date:
2014-08-19
Revision:
0:fddd018033fb
Child:
1:5d4aec3f0651

File content as of revision 0:fddd018033fb:

/*
 * 4WD_OMNI_simple  by Tomoki Hokida
 * Simple Type
 *
 * motor pins piar
 * motor(p21,p22):motor(p23,p24)
 * motor(p25,p26):motor(p27,p28)
 * 通信中継用
 * data 5~8 arm
 * data 1~4:omni
 * reset 0
 */

#include "mbed.h"
#include <math.h>
#include "RawSerial.h"

DigitalOut check(LED1);
BusOut motors(p21,p22,p23,p24,p25,p26,p27,p28);

I2C armMbed(p9,p10);
RawSerial xbee(p13,p14);

//i2c init

int addr = 0x01;
char buff[1];

uint8_t value=0;
uint8_t omni_value=0;

//armMbed.frequency(10000);

void getData() //serial xbee to mbed
{   
    value = xbee.getc();
    
    buff[0]=value>>4;
    omni_value=value<<4;                    
    armMbed.write(addr,buff,1);
}

int main()
{
    xbee.attach(&getData, Serial::RxIrq);

    for(;;){
            if(omni_value==0x0) motors = 0;
            if(omni_value&0x10) motors = 0x05; //p21,p23 
            if(omni_value&0x20) motors = 0x0A; //p22,p24 
            if(omni_value&0x40) motors = 0x50; //p25,p27        
            if(omni_value&0x80) motors = 0xA0; //p26,p28
            
             check = !check;
        }
}