Hsieh JenYun
/
I2C_Master
a
Fork of I2C_Master by
main.cpp
- Committer:
- Tanakacool
- Date:
- 2018-10-24
- Revision:
- 4:186241a75818
- Parent:
- 3:996d0d74fb11
- Child:
- 5:221ce6ba655c
File content as of revision 4:186241a75818:
#include "mbed.h" DigitalOut led_red(LED_RED); InterruptIn sw2(SW2); I2C i2c( PTB1, PTB0); Serial serialPort( PTE0, PTE1); char Rmotobuffer[3]; char Lmotobuffer[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(Lmotobuffer[1]); i2c.write(Lmotobuffer[2]); i2c.stop(); } void Driving_Left(void) { i2c.start(); i2c.write(Left_ADDR); i2c.write(0); i2c.write(Rmotobuffer[1]); i2c.write(Rmotobuffer[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; Rmotobuffer[0]=0x00; Rmotobuffer[1]= motorOutPut>>8; Rmotobuffer[2]=motorOutPut; Lmotobuffer[0]=0x00; Lmotobuffer[1]= motorOutPut>>8; Lmotobuffer[2]=motorOutPut; Driving_Right(); wait_ms(100); Driving_Left(); while (true) { } }