Michael Limbird / Mbed 2 deprecated VideoOutput

Dependencies:   mbed

Revision:
20:03a3357de805
Parent:
19:76632ff3e9fc
Child:
22:dbd5c4af83d6
--- a/main.cpp	Sun Jan 11 16:45:40 2015 +0000
+++ b/main.cpp	Sun Jan 11 18:07:15 2015 +0000
@@ -1,13 +1,13 @@
 #include "mbed.h"
 
-//Accelerometer
+//Accelerometer addresses
 #define ADXL345_ADDRESS_W (0xA6)
 #define ADXL345_ADDRESS_R (0xA7)
 #define ADXL345_REGISTER_XLSB (0x32)
 #define ADXL_REGISTER_PWRCTL (0x2D)
 #define ADXL_PWRCTL_MEASURE (0x01 << 3)
 
-//Gyroscope
+//Gyroscope addresses
 #define ITG3200_ADDRESS_W (0xD0)
 #define ITG3200_ADDRESS_R (0xD1)
 #define ITG3200_REGISTER_XMSB (0x1D)
@@ -15,15 +15,17 @@
 #define ITG3200_FULLSCALE (0x03 << 3)
 #define ITG3200_42HZ (0x03)
 
-//3-Axis Digital Compass IC
+//3-Axis Digital Compass IC addresses
 #define HMC5883_ADDRESS_W (0x3C)
 #define HMC5883_ADDRESS_R (0x3D)
 #define HMC5883_REGISTER_XMSB (0x03)
 #define HMC5883_REGISTER_MEASMODE (0x02)
 #define HMC5883_MEASMODE_CONT (0x00)
 
+//establish I2C connections
 I2C	i2c( p9, p10 );	// sda, scl
 
+//Declare functions
 void init_adxl345();
 void read_adxl345();
 void init_itg3200();
@@ -31,40 +33,40 @@
 void init_hmc5883();
 void read_hmc5883();
 
+//establish serial communications with computer via usb
 Serial pc(USBTX, USBRX); //tx, rx
 
+//arrays to store data from 9DOF
 int accelerometer_data[3];
 int gyro_data[3];
 int magnetometer_data[3];
 
-PwmOut led(LED1);
-
-float brightness = 0.0;
-
 int main() {
 
-	init_adxl345();
+	//initialize each IC
+	//init_adxl345();
 	init_itg3200();
-	init_hmc5883();
+	//init_hmc5883();
     
     while(1) {        
+        //read from each IC
         //read_adxl345();
-        //read_itg3200();
-        read_hmc5883();
+        read_itg3200();
+        //read_hmc5883();
     }
 }
 
+//This function initializes the Digital Accelerometer ADXL345
 void init_adxl345() {
 	char data[2];
 	data[0] = ADXL_REGISTER_PWRCTL;
 	data[1] = ADXL_PWRCTL_MEASURE;
 
 	i2c.write(ADXL345_ADDRESS_W, data, 2); // first part of data is the register
-	
-	wait(0.5);
 
 	i2c.write(ADXL345_ADDRESS_W, data, 1);
 	i2c.read(ADXL345_ADDRESS_R, data, 2);
+	
 	pc.printf("%i\n",(unsigned int)data);
 }
 
@@ -93,7 +95,9 @@
 	pc.printf("Bitwise Or : %i\n", (unsigned int)data[1]);
 	
 	i2c.write(ITG3200_ADDRESS_W, data,2);
-	i2c.read(ITG3200_ADDRESS_R, data, 1);
+	
+	i2c.write(ITG3200_ADDRESS_W, data,1);
+	i2c.read(ITG3200_ADDRESS_R, data, 2);
 
 	pc.printf("%i\n",(unsigned int)data);
 }