Finn Quicke / Mbed 2 deprecated TDP3_ColourSensor_OOP

Dependencies:   mbed

Revision:
1:e4320a230347
Parent:
0:c3344ac96db1
--- a/ColourSensor.cpp	Thu Mar 14 12:53:00 2019 +0000
+++ b/ColourSensor.cpp	Mon Mar 18 11:04:39 2019 +0000
@@ -13,7 +13,7 @@
 
 void ColourSensor::initialConditions() {
     // set initial conditions & variables
-    printf("Setting Initial Conditions\n\r");
+    //printf("Setting Initial Conditions\n\r");
     detectedIf = 0;
     detectedIfOld = 0;
     newDetection = 0;
@@ -34,12 +34,12 @@
     
     if (state) {
         solenoid.write(1);
-        printf("Solenoid has been turn ON\n\r");
+        //printf("Solenoid has been turn ON\n\r");
     }
     
     else {
         solenoid.write(0);
-        printf("Solenoid has been turned OFF\n\r");
+        //printf("Solenoid has been turned OFF\n\r");
     }
     
     solenoidState = state;
@@ -52,24 +52,24 @@
     detectedIfOld = detectedIf;
     newDetection = 0;
     
-    printf("Reading colour detection state\n\r");
+    //printf("Reading colour detection state\n\r");
     
-    detectedIf = inIf.read();
+    detectedIf = !inIf.read();
     
     if ((detectedIf && !detectedIfOld)) {
         // if colour is newly detected
         newDetection = 1;
         toggleA = 1;
-        printf("Colour newly detected\n\r");
+        //printf("Colour newly detected\n\r");
     }
 }
 
 void ColourSensor::readWhich() {
     //Interrupt function (software): reads in which colour is detected
     
-    detectedWhich = inWhich.read();
+    detectedWhich = !inWhich.read();
     
-    printf("Colour detected; code: %d\n\r", detectedWhich);
+    //printf("Colour detected; code: %d\n\r", detectedWhich);
 
     toggleB = 1;
 }
@@ -78,16 +78,16 @@
     // Interrupt function (software): reactivates colour processing 
     toggleConst = 1;
     
-    printf("Colour processing Activated\n\r");
+    //printf("Colour processing Activated\n\r");
 }
 
 void ColourSensor::process() {
     // Processes change of state in colour detection
-    printf("Colour process() called\n\r");
+    //printf("Colour process() called\n\r");
     
     if (!diskHave && newDetection) {
         // If: No disk & colour newly detected, turn on solenoid
-        printf("Colour detected; collecting disk\n\r");
+        //printf("Colour detected; collecting disk\n\r");
         
         solenoidSet(1);
         diskHave = 1;
@@ -96,21 +96,21 @@
     
     else if ((diskHave && newDetection) && (detectedWhich == diskColour)) {
         // If: Have disk & colour newly detected & disk colour is same as detected colour, turn off solenoid
-        printf("Correct colour detected; depositing disk\n\r");
+        //printf("Correct colour detected; depositing disk\n\r");
         solenoidSet(0);
         diskHave = 0;
     }
     
     else if ((diskHave && newDetection) && (detectedWhich != diskColour)) {
         // If: Have disk & colour newly detected & disk colour is NOT same as detected colour, update variables
-        printf("Wrong colour detected; keeping disk\n\r");
+        //printf("Wrong colour detected; keeping disk\n\r");
     }
     
     else {
-        printf("Cool (y)\n\r");
+        //printf("Cool (y)\n\r");
     }
     
     // Temporarily disable colour processing
-    printf("Disabling colour processing\n\r");
+    //printf("Disabling colour processing\n\r");
     toggleConst = 0;
 }
\ No newline at end of file