Hsieh JenYun
/
I2C_Master
a
Fork of I2C_Master by
main.cpp
- Committer:
- Tanakacool
- Date:
- 2018-10-24
- Revision:
- 2:3d64970eeb96
- Parent:
- 1:6926cb0de2b0
- Child:
- 3:996d0d74fb11
File content as of revision 2:3d64970eeb96:
#include "mbed.h" DigitalOut led_red(LED_RED); InterruptIn sw2(SW2); I2C i2c( PTB1, PTB0); Serial serialPort( PTE0, PTE1); 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(0xe2); i2c.write(0); i2c.stop(); } int main() { sw2.rise(&sw2_release); serialPort.baud(115200); serialPort.printf("WPI Serial Port Started\n"); i2c.frequency(100000); wait_ms(100); Driving_Right(); wait_ms(100); Driving_Left(); while (true) { } }