Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Files at this revision

API Documentation at this revision

Comitter:
kyleliangus
Date:
Thu May 04 21:38:20 2017 +0000
Parent:
5:7e1e4cc19044
Child:
7:6f5cb6377bd4
Commit message:
Fixed stuff

Changed in this revision

irled.cpp Show diff for this revision Revisions of this file
irled.h Show diff for this revision Revisions of this file
irpair.cpp Show annotated file Show diff for this revision Revisions of this file
irpair.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
--- a/irled.cpp	Fri Apr 28 04:08:34 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +0,0 @@
-#include "irled.h"
-#include "mbed.h"
-
-void IrLed::calibrateSensor() {
-
-    for (int i = 0; i < samplesToTake; ++i) 
-        sensorAvg += recv.read();
-        
-    sensorAvg /= samplesToTake;
-}
-
-float IrLed::getSamples( int samples )
-{
-    float z = 0;
-    ir.write( 1 );
-    for( int i = 0; i < samples; ++i )
-        z += recv.read();
-    ir.write( 0 );
-    return z / samples;
-}
-
-/*
-inline float IrLED::blinkLED( int i, int samples )
-{
-    float z = 0;
-    if( i == 1 )
-    {
-        IR_LED1.write(1);
-        for( int j = 0; j < samples; j++ )
-            z += IR_Sensor1.read();
-        IR_LED1.write(0);
-    }
-    if( i == 2 )
-    {
-        IR_LED2.write(1);
-        for( int j = 0; j < samples; j++ )
-            z += IR_Sensor2.read();
-        IR_LED2.write(0);
-    }
-    if( i == 3 )
-    {
-        IR_LED3.write(1);   
-        for( int j = 0; j < samples; j++ )
-            z += IR_Sensor3.read();
-        IR_LED4.write(0);
-    }
-    if( i == 4 )
-    {
-        IR_LED4.write(1);
-        for( int j = 0; j < samples; j++ )
-            z += IR_Sensor4.read();
-        IR_LED4.write(0);
-    }
-    if( DEBUGGING )
-        serial.println( "Sample by IR %d: %f\n", i, z );
-    return z / samples;
-}*/
\ No newline at end of file
--- a/irled.h	Fri Apr 28 04:08:34 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-#ifndef IRLED_H
-#define IRLED_H
-
-#include "mbed.h"
-
-#define samplesToTake 1000
-
-class IrLed
-{
-    public:
-        IrLed( PinName pin, PinName rec ) : ir( pin ), recv( rec )
-        {
-            calibrateSensor();
-        }
-        
-        float getSamples( int i );
-        
-    private:
-        void calibrateSensor();
-        
-        // internal values
-        DigitalOut ir;
-        AnalogIn recv;
-        float sensorAvg;
-};
-
-
-
-#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/irpair.cpp	Thu May 04 21:38:20 2017 +0000
@@ -0,0 +1,57 @@
+#include "irpair.h"
+#include "mbed.h"
+
+void IRPair::calibrateSensor() {
+
+    for (int i = 0; i < samplesToTake; ++i) 
+        sensorAvg += recv.read();
+        
+    sensorAvg /= samplesToTake;
+}
+
+float IRPair::getSamples( int samples )
+{
+    float z = 0;
+    ir.write( 1 );
+    for( int i = 0; i < samples; ++i )
+        z += recv.read();
+    ir.write( 0 );
+    return z / samples;
+}
+
+/*
+inline float IrLED::blinkLED( int i, int samples )
+{
+    float z = 0;
+    if( i == 1 )
+    {
+        IR_LED1.write(1);
+        for( int j = 0; j < samples; j++ )
+            z += IR_Sensor1.read();
+        IR_LED1.write(0);
+    }
+    if( i == 2 )
+    {
+        IR_LED2.write(1);
+        for( int j = 0; j < samples; j++ )
+            z += IR_Sensor2.read();
+        IR_LED2.write(0);
+    }
+    if( i == 3 )
+    {
+        IR_LED3.write(1);   
+        for( int j = 0; j < samples; j++ )
+            z += IR_Sensor3.read();
+        IR_LED4.write(0);
+    }
+    if( i == 4 )
+    {
+        IR_LED4.write(1);
+        for( int j = 0; j < samples; j++ )
+            z += IR_Sensor4.read();
+        IR_LED4.write(0);
+    }
+    if( DEBUGGING )
+        serial.println( "Sample by IR %d: %f\n", i, z );
+    return z / samples;
+}*/
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/irpair.h	Thu May 04 21:38:20 2017 +0000
@@ -0,0 +1,29 @@
+#ifndef IRPAIR_H
+#define IRPAIR_H
+
+#include "mbed.h"
+
+#define samplesToTake 1000
+
+class IRPair
+{
+    public:
+        IRPair( PinName pin, PinName rec ) : ir( pin ), recv( rec )
+        {
+            calibrateSensor();
+        }
+        
+        float getSamples( int i );
+        
+    private:
+        void calibrateSensor();
+        
+        // internal values
+        DigitalOut ir;
+        AnalogIn recv;
+        float sensorAvg;
+};
+
+
+
+#endif
\ No newline at end of file
--- a/main.cpp	Fri Apr 28 04:08:34 2017 +0000
+++ b/main.cpp	Thu May 04 21:38:20 2017 +0000
@@ -1,6 +1,6 @@
 #include "mbed.h"
 
-#include "irled.h"
+#include "irpair.h"
 #include "main.h"
 #include "motor.h"
 
--- a/main.h	Fri Apr 28 04:08:34 2017 +0000
+++ b/main.h	Thu May 04 21:38:20 2017 +0000
@@ -16,6 +16,8 @@
 DigitalOut greenLed(PC_2);
 
 // IRs
+
+/*
 DigitalOut IR_1(PB_1);
 DigitalOut IR_2(PB_13);
 DigitalOut IR_3(PB_0);
@@ -26,6 +28,7 @@
 AnalogIn Rec_2(PC_4);
 AnalogIn Rec_3(PA_6);
 AnalogIn Rec_4(PA_7);
+*/
 
 // Doing DEBUGGING
 #define DEBUGGING 1