a

Fork of I2C_Master by LAXAN01

Committer:
Tanakacool
Date:
Wed Oct 24 06:03:27 2018 +0000
Revision:
2:3d64970eeb96
Parent:
1:6926cb0de2b0
Child:
3:996d0d74fb11
k22_i2c_motor

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:f76c26307f9a 1 #include "mbed.h"
cathy101 1:6926cb0de2b0 2
Tanakacool 2:3d64970eeb96 3 DigitalOut led_red(LED_RED);
Tanakacool 2:3d64970eeb96 4 InterruptIn sw2(SW2);
Tanakacool 2:3d64970eeb96 5 I2C i2c( PTB1, PTB0);
mbed_official 0:f76c26307f9a 6
Tanakacool 2:3d64970eeb96 7 Serial serialPort( PTE0, PTE1);
Tanakacool 2:3d64970eeb96 8
Tanakacool 2:3d64970eeb96 9 int Right_ADDR = 0x14<<1;
Tanakacool 2:3d64970eeb96 10 int Left_ADDR = 0x15<<1;
mbed_official 0:f76c26307f9a 11
Tanakacool 2:3d64970eeb96 12 void sw2_release(void)
Tanakacool 2:3d64970eeb96 13 {
Tanakacool 2:3d64970eeb96 14 led_red = !led_red;
Tanakacool 2:3d64970eeb96 15 serialPort.printf("On-board button SW2 was released.\n");
Tanakacool 2:3d64970eeb96 16 }
Tanakacool 2:3d64970eeb96 17 void Driving_Right(void)
Tanakacool 2:3d64970eeb96 18 {
Tanakacool 2:3d64970eeb96 19 i2c.start();
Tanakacool 2:3d64970eeb96 20 i2c.write(Right_ADDR);
Tanakacool 2:3d64970eeb96 21 i2c.write(0);
Tanakacool 2:3d64970eeb96 22 i2c.write(0xe2);
Tanakacool 2:3d64970eeb96 23 i2c.write(0);
Tanakacool 2:3d64970eeb96 24 i2c.stop();
Tanakacool 2:3d64970eeb96 25 }
Tanakacool 2:3d64970eeb96 26 void Driving_Left(void)
Tanakacool 2:3d64970eeb96 27 {
Tanakacool 2:3d64970eeb96 28 i2c.start();
Tanakacool 2:3d64970eeb96 29 i2c.write(Left_ADDR);
Tanakacool 2:3d64970eeb96 30 i2c.write(0);
Tanakacool 2:3d64970eeb96 31 i2c.write(0xe2);
Tanakacool 2:3d64970eeb96 32 i2c.write(0);
Tanakacool 2:3d64970eeb96 33 i2c.stop();
Tanakacool 2:3d64970eeb96 34 }
Tanakacool 2:3d64970eeb96 35
Tanakacool 2:3d64970eeb96 36 int main()
Tanakacool 2:3d64970eeb96 37 {
Tanakacool 2:3d64970eeb96 38
Tanakacool 2:3d64970eeb96 39 sw2.rise(&sw2_release);
Tanakacool 2:3d64970eeb96 40 serialPort.baud(115200);
Tanakacool 2:3d64970eeb96 41 serialPort.printf("WPI Serial Port Started\n");
Tanakacool 2:3d64970eeb96 42
Tanakacool 2:3d64970eeb96 43 i2c.frequency(100000);
Tanakacool 2:3d64970eeb96 44 wait_ms(100);
Tanakacool 2:3d64970eeb96 45
Tanakacool 2:3d64970eeb96 46 Driving_Right();
Tanakacool 2:3d64970eeb96 47 wait_ms(100);
Tanakacool 2:3d64970eeb96 48 Driving_Left();
Tanakacool 2:3d64970eeb96 49
Tanakacool 2:3d64970eeb96 50 while (true) {
Tanakacool 2:3d64970eeb96 51
mbed_official 0:f76c26307f9a 52 }
Tanakacool 2:3d64970eeb96 53 }