READY FOR ROS

Dependencies:   FastAnalogIn mbed

Fork of Fast_blink by CLUE

Revision:
2:a215212e9a78
Parent:
1:8e7e9ef6b0bd
Child:
4:ae2202b25d49
--- a/main.cpp	Tue Mar 07 18:43:43 2017 +0000
+++ b/main.cpp	Wed Mar 08 16:48:24 2017 +0000
@@ -5,8 +5,8 @@
 
 Serial pc(USBTX, USBRX); // tx, rx
 
-FastAnalogIn ain(p20); //Fast&Furious:Tokyo Drift Analog Input to PDmux
-//AnalogIn ain(p20); //Analog Input to PDmux
+//FastAnalogIn ain(p20); //Fast&Furious:Tokyo Drift Analog Input to PDmux
+AnalogIn ain(p20); //Analog Input to PDmux
 
 DigitalOut LEDout(p8); //5V output to LED mux
 DigitalOut LEDmux0(p9); //s0
@@ -20,12 +20,12 @@
 DigitalOut PDmux3(p17); //s3
 AnalogOut aout(p18);
 
+int LED; //counter for LEDs
 
 double voltageOut;
 double readIn[5];
 
-
-double alpha; //dummy variable for ADC
+double alpha; //dummy variable for ADC timing
 
 
 
@@ -35,18 +35,11 @@
     //pc.format();
 
 //   double ADCtime=.000000116; //1.6 us
-    double time=.000029;  // ~15kHz
+    double time=.000029;  // ~10kHz
 //    double time=.0000029; //100 kHz
 //    double time=.0003;
 
 
-    //counters for various while loops
-//    int mPD=0;
-//    int nPD=0;
-//    int mLED=0;
-//    int nLED=0;
-    //int pd=0;
-    //int i=0;
 
     //boolean bits for multiplexing
     LEDmux0=0;
@@ -72,29 +65,18 @@
                 readIn[i]=ain.read();
                 wait(time);
 
-                //LEDout = 0;
-                //alpha=ain.read();
-                //wait(time);
+                LEDout = 0;
+                alpha=ain.read();
+                wait(time);
             }
 
-            voltageOut=(readIn[2]+readIn[3]+readIn[4])/3;
-            aout=voltageOut;
+            voltageOut=(readIn[2]+readIn[3]+readIn[4])/3; //Average of last three values
+            aout=voltageOut; //Sets Voltage out to Pin 18 for debugging on scope
 
-            //send the diode readings to Matlab
-            if(pd==0) {
-                pc.printf("1,%f \n", voltageOut);
-            } else if(pd==1) {
-                pc.printf("2,%f \n", voltageOut+10);
-            } else if(pd==2) {
-                pc.printf("3,%f \n", voltageOut+20);
-            } else if(pd==3) {
-                pc.printf("4,%f \n", voltageOut+30);
-            } else if(pd==4) {
-                pc.printf("5,%f \n", voltageOut+40);
-            } else {
-                pc.printf("6,%f \n", voltageOut+50);
-            }
-
+            //send the diode readings to MATlab in format: LED,PD,Voltageout
+            //I think this is where you want to report voltageOut to ROS for the PD/LED combo
+            
+            pc.printf("%d,%d,%f \n",LED,pd,voltageOut);
 
 
             //PD multiplexing
@@ -115,30 +97,37 @@
                 PDmux0=0;
                 PDmux2=0;
             }
-
-        }
-                if((LEDmux0==0) && (LEDmux1==0) && (LEDmux2==0)) {
-                    LEDmux0=1;
-                } else if((LEDmux0==1) && (LEDmux1==0) && (LEDmux2==0)) {
-                    LEDmux0=0;
-                    LEDmux1=1;
-                } else if((LEDmux0==0) && (LEDmux1==1) && (LEDmux2==0)) {
-                    LEDmux0=1;
-                } else if((LEDmux0==1) && (LEDmux1==1) && (LEDmux2==0)) {
-                    LEDmux0=0;
-                    LEDmux1=0;
-                    LEDmux2=1;
-                } else if((LEDmux0==0) && (LEDmux1==0) && (LEDmux2==1)) {
-                    LEDmux0=1;
-                } else {
-                    LEDmux0=0;
-                    LEDmux2=0;
-                }
-        
+            
+            
+        }//end of PD for loop
 
 
+        //LED multiplexing
+        if((LEDmux0==0) && (LEDmux1==0) && (LEDmux2==0)) {
+            LEDmux0=1;
+            LED=1;
+        } else if((LEDmux0==1) && (LEDmux1==0) && (LEDmux2==0)) {
+            LEDmux0=0;
+            LEDmux1=1;
+            LED=2;
+        } else if((LEDmux0==0) && (LEDmux1==1) && (LEDmux2==0)) {
+            LEDmux0=1;
+            LED=3;
+        } else if((LEDmux0==1) && (LEDmux1==1) && (LEDmux2==0)) {
+            LEDmux0=0;
+            LEDmux1=0;
+            LEDmux2=1;
+            LED=4;
+        } else if((LEDmux0==0) && (LEDmux1==0) && (LEDmux2==1)) {
+            LEDmux0=1;
+            LED=5;
+        } else {
+            LEDmux0=0;
+            LEDmux2=0;
+            LED=0;
+        }
 
-    }
+    }//end of While(1) loop
 }