a

Fork of I2C_Master by LAXAN01

main.cpp

Committer:
Tanakacool
Date:
2018-10-24
Revision:
3:996d0d74fb11
Parent:
2:3d64970eeb96
Child:
4:186241a75818

File content as of revision 3:996d0d74fb11:

#include "mbed.h"

DigitalOut led_red(LED_RED);
InterruptIn sw2(SW2);
I2C i2c( PTB1, PTB0);

Serial serialPort( PTE0, PTE1);

char motobuffer[3];

int Right_ADDR = 0x14<<1;
int Left_ADDR  = 0x15<<1;

void sw2_release(void)
{
    led_red = !led_red;
    serialPort.printf("On-board button SW2 was released.\n");
}
void Driving_Right(void)
{
    i2c.start();
    i2c.write(Right_ADDR);
    i2c.write(0);
    i2c.write(0xe2);
    i2c.write(0);
    i2c.stop();
}
void Driving_Left(void)
{
    i2c.start();
    i2c.write(Left_ADDR);
    i2c.write(0);
    i2c.write(motobuffer[1]);
    i2c.write(motobuffer[2]);
    i2c.stop();
}

int main()
{

    sw2.rise(&sw2_release);
    serialPort.baud(115200);
    serialPort.printf("WPI Serial Port Started\n");

    i2c.frequency(100000);
    wait_ms(100);

    int motorOutPut=2000;
    motobuffer[0]=0x00;
    motobuffer[1]= motorOutPut>>8;
    motobuffer[2]=motorOutPut;

    Driving_Right();
    wait_ms(100);
    Driving_Left();

    while (true) {

    }
}