Finn Quicke / Mbed 2 deprecated TDP3_ColourSensor_OOP

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
quickeman
Date:
Mon Mar 18 11:04:39 2019 +0000
Parent:
0:c3344ac96db1
Commit message:
Various updates; removed print statements

Changed in this revision

ColourSensor.cpp 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
diff -r c3344ac96db1 -r e4320a230347 ColourSensor.cpp
--- 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
diff -r c3344ac96db1 -r e4320a230347 main.cpp
--- a/main.cpp	Thu Mar 14 12:53:00 2019 +0000
+++ b/main.cpp	Mon Mar 18 11:04:39 2019 +0000
@@ -6,38 +6,36 @@
 Timeout reactivateColour;
 
 int main() {
-    printf("Program has started\n\r");
+    //printf("Program has started\n\r");
     
-    ColourSensor ColourSensor(PTC16, PTC13, PTC12);
+    ColourSensor ColourSensor(PTC16, PTC13, PTE20);
     
     // Set call rate of colour detection function
-    detectColour.attach(callback(&ColourSensor, &ColourSensor::readIf), 1.0);
+    detectColour.attach(callback(&ColourSensor, &ColourSensor::readIf), 0.5);
     
-    // Test LED
-    //testLED2.period(1.0);
-    //testLED2.write(0.5);
-    
-    int firstLoop = 1;
+//    int firstLoop = 1;
     
     while (1) {
         // main program loop
+        /*
         if (firstLoop) {
             printf("Main loop has started\n\r");
             firstLoop--;
         }
+        */
         
         if (ColourSensor.toggleConst && ColourSensor.toggleA) {
             // Call readColSenWhich after x seconds
-            printf("Toggle A\n\r");
+            //printf("Toggle A\n\r");
             
-            readColour.attach(callback(&ColourSensor, &ColourSensor::readWhich), 0.4);
+            readColour.attach(callback(&ColourSensor, &ColourSensor::readWhich), 0.2);
             
             ColourSensor.toggleA = 0;
         }
         
         if (ColourSensor.toggleConst && ColourSensor.toggleB) {
             // Process colour sensor data
-            printf("Toggle B\n\r");
+            //printf("Toggle B\n\r");
             
             ColourSensor.process();