The first assignment of many for my CS10 (Introduction to Computer Science) Honors Project.
Using an ARM Chip, I deployed my code from https://os.mbed.com/.
Spring 2017
Sample Code:
#include "mbed.h"
Serial pc(USBTX, USBRX);
DigitalOut myled(LED1);
I2C i2c(D7, D8);
const int addr = 0x50;
int main()
{
char data[3];
char cmd[3];
int d;
cmd[0] = 0;// read chip_id
i2c.write(addr, cmd, 1);
i2c.read(addr, data, 1);
pc.printf("chip_id %02x", data[0] );
// OPR_MODE to IMU : 8 Reg. : 3D
cmd[0] = 0x3D;// OPR_MODE Reg
cmd[1] = 8; //IMU mode
i2c.write(addr, cmd, 2);
while(1)
{
cmd[0] = 0x1E; // read euler pitch
i2c.write(addr, cmd, 1);
i2c.read(addr, data, 2);
d = data[1] << 8 + data[0];
pc.printf("Euler Pitch %d\r\n", d );
myled = 1; // LED is ON wait(0.1); // 200 ms myled = 0; // LED is OFF wait(0.1); // 1 sec } }
コメント