Alec Arce / Mbed OS PROJECT

Dependencies:   TCS3200

Files at this revision

API Documentation at this revision

Comitter:
xalec
Date:
Sat Dec 05 06:19:45 2020 +0000
Commit message:
CS 435

Changed in this revision

.gitignore Show annotated file Show diff for this revision Revisions of this file
Map.cpp Show annotated file Show diff for this revision Revisions of this file
Map.hpp Show annotated file Show diff for this revision Revisions of this file
TCS3200.lib 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
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
resources/official_armmbed_example_badge.png Show annotated file Show diff for this revision Revisions of this file
rgbhlr.cpp Show annotated file Show diff for this revision Revisions of this file
rgbhlr.h Show annotated file Show diff for this revision Revisions of this file
rgbstats.cpp Show annotated file Show diff for this revision Revisions of this file
rgbstats.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Sat Dec 05 06:19:45 2020 +0000
@@ -0,0 +1,4 @@
+.build
+.mbed
+projectfiles
+*.py*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Map.cpp	Sat Dec 05 06:19:45 2020 +0000
@@ -0,0 +1,14 @@
+#include "Map.hpp"
+
+Map::Map(int inMin, int inMax, int outMin, int outMax)
+{
+  _inMin = inMin;
+  _inMax = inMax;
+  _outMin = outMin;
+  _outMax = outMax;
+}
+
+int Map::Calculate(int inVal)
+{
+    return ((inVal - _inMin)*(_outMax - _outMin)/(_inMax - _inMin) + _outMin );
+    }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Map.hpp	Sat Dec 05 06:19:45 2020 +0000
@@ -0,0 +1,34 @@
+#ifndef MAP_H
+#define MAP_H
+
+#include "mbed.h"
+
+/**
+ *  A library that maps one range (inMin -> inMax) to another (outMin -> outMax)
+ *
+ * @author CA Bezuidenhout
+ */
+class Map
+{
+public:
+  /**
+   * @param inMin : Minimum value of input range
+   * @param inMax : Maximum value of input range
+   * @param outMin : Minimum value of output range
+   * @param outMax : Maximum value of output range
+   */
+  Map(int inMin, int inMax, int outMin, int outMax);
+
+  /**
+   * Map inVal onto the output range
+   *
+   * @param inVal : A value in the input range to be mapped onto the output range
+   * @returns A value in the output range
+   */
+  int Calculate(int inVal);
+private:
+  int _inMin,_inMax;
+  int _outMin,_outMax;
+
+};
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TCS3200.lib	Sat Dec 05 06:19:45 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/grantphillips/code/TCS3200/#b98e768bc655
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Dec 05 06:19:45 2020 +0000
@@ -0,0 +1,92 @@
+#include <iostream>
+
+#include "mbed.h"
+#include "Map.hpp"
+#include "TCS3200.h"
+
+DigitalOut red(PA_9);
+DigitalOut green(PC_7);
+DigitalOut blue(PB_6);
+
+Serial pc(USBTX, USBRX);
+
+/**
+Nucleo - TCS3200 interfacing pins 
+s0 (PA_8);    // pin D7
+s1 (PB_10);   // pin D6
+s2 (PB_4);    // pin D5
+s3 (PB_5);    // pin D4
+*/
+
+int main() {
+  
+    
+    int red_pw, green_pw, blue_pw;
+    int input; 
+    int counter = 0;
+    
+    // Pulse width calibration values
+    int red_min    = 31;
+    int red_max    = 301;
+    int green_min  = 37;
+    int green_max  = 389;
+    int blue_min   = 29;
+    int blue_max   = 310;
+    int R, G, B;
+    
+    TCS3200 pw(PA_8, PB_10, PB_4, PB_5, PA_5);
+    
+    Map r_map(red_min, red_max, 255, 0);    
+    Map g_map(green_min, green_max, 255, 0);
+    Map b_map(blue_min, blue_max, 255, 0);
+    
+    
+    pw.SetMode(TCS3200::SCALE_100);
+   
+         pc.printf("Please type a value:");
+         pc.scanf("%i", &input);  // & to pass a pointer to input
+         pc.printf("\nThe input value is: %i\n", input);
+         pc.printf("Reading in 3...");
+         wait(1.5);
+         pc.printf("2...");
+         wait(1.5);
+         pc.printf("1\n");
+    while(counter < input){
+         
+         
+        red_pw     = pw.ReadRed();
+        green_pw   = pw.ReadGreen();
+        blue_pw    = pw.ReadBlue();
+      
+        //printf("Red:    %d        Green: %d         Blue: %d  \n\r",  red_pw, green_pw, blue_pw);
+       
+        
+        R = r_map.Calculate(red_pw);
+        G = g_map.Calculate(green_pw);
+        B = b_map.Calculate(blue_pw);
+        
+        if(R < 0)
+        R = 0;      
+        else if(R > 255)
+        R = 255;
+
+            
+        if(G < 0)
+        G = 0;       
+        else if(G > 255)
+        G = 255;
+
+        
+        if(B < 0)
+        B = 0;   
+        else if(B > 255)
+        B = 255;
+        
+        printf("Red:   %i     Green:   %i     Blue:   %i \n", R, G, B);
+        
+        wait(.5);
+        
+        counter++;
+        }  
+        
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Sat Dec 05 06:19:45 2020 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#cf4f12a123c05fcae83fc56d76442015cb8a39e9
Binary file resources/official_armmbed_example_badge.png has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rgbhlr.cpp	Sat Dec 05 06:19:45 2020 +0000
@@ -0,0 +1,30 @@
+#include "rgbhlr.h"
+
+//////////////////////////////////////////////////
+// RGB methods
+//////////////////////////////////////////////////
+
+// Constructors
+rgb_dws:: RGB::RGB() : red(0), green(0), blue(0) 
+{}
+
+rgb_dws:: RGB::RGB(short r, short g, short b) : red(r), green(g), blue(b) 
+{}
+
+rgb_dws:: RGB::RGB(const RGB& c) : red(c.red), green(c.green), blue(c.blue)
+{}
+
+//////////////////////////////////////////////////
+// RGBCalc methods
+//////////////////////////////////////////////////
+
+// Constructors
+rgb_dws:: RGBCalc::RGBCalc() : redC(0), greenC(0), blueC(0)
+{}
+
+rgb_dws:: RGBCalc::RGBCalc(double r, double g, double b) : redC(r), greenC(g), blueC(b)
+{}
+
+rgb_dws:: RGBCalc::RGBCalc(const rgb_dws::RGBCalc& c) : redC(c.redC), greenC(c.greenC), blueC(c.blueC)
+{}
+    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rgbhlr.h	Sat Dec 05 06:19:45 2020 +0000
@@ -0,0 +1,34 @@
+#ifndef RGB_HANDLER_H
+#define RGB_HANDLER_H
+
+namespace rgb_dws {
+    struct RGB {
+        //
+        // Constructors
+        RGB();
+        RGB(short r, short g, short b);
+        RGB(const RGB& c);
+
+        //
+        // Methods
+
+        // A conversion method from input of the color sensor to accurate RGB value needed?
+
+        //
+        // Fields
+        short red, green, blue;
+    };
+
+    // struct for calculations on RGB values (i.e mean, stand. dev., etc)
+    struct RGBCalc {
+        RGBCalc();
+        RGBCalc(double r, double g, double b);
+        RGBCalc(const RGBCalc& c);
+
+        double redC, greenC, blueC;
+
+    };
+
+} // END OF NAMESPACE 'rgb_dws'
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rgbstats.cpp	Sat Dec 05 06:19:45 2020 +0000
@@ -0,0 +1,26 @@
+#include <vector>
+#include <algorithm>
+
+#include "rgbhlr.h"
+#include "rgbstats.h"
+
+using namespace rgb_dws;
+
+RGB rgb_dws::samp_mean(std::vector<RGB> data) {
+    
+    RGB color;
+    int sum_red = 0, sum_green = 0, sum_blue = 0;
+
+    // Sum the squared RGB values
+    for(int i = 0; i < data.size(); i++) {
+        sum_red     += data[i].red; 
+        sum_green   += data[i].green;
+        sum_blue    += data[i].blue;
+    }
+    // Compute their means
+    color.red       = (short)sum_red/data.size();
+    color.green     = (short)sum_green/data.size();
+    color.blue      = (short)sum_blue/data.size();
+
+    return color;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rgbstats.h	Sat Dec 05 06:19:45 2020 +0000
@@ -0,0 +1,39 @@
+#ifndef RGB_STATS_HANDLER_H
+#define RGB_STATS_HANDLER_H
+
+#include "rgbhlr.h"
+#include <vector>
+
+//
+    // A collection of methods encompassing statistical anaylsis for 
+    // live data readings of RGB values
+//
+namespace rgb_dws {
+
+    // Methods for RGB data
+    
+    RGB samp_mean(std::vector<RGB> data);
+    RGB median(const std::vector<RGB>& data);
+    RGB mode(const std::vector<RGB>& data);
+    RGBCalc variance(const std::vector<RGB>& data, double mean);
+    RGBCalc samp_stand_dev(const std::vector<RGB>& data, double mean);
+
+// Needed statistical computations:
+    // Finding the sample mean
+    // Finding median (only viable for individual color values)
+    // Finding variance 
+    // Finding sample standard deviation
+    // Partitioning distribution using quartiles (calculate quartiles)
+    // Calculate IQR
+    // Calculate Five Number Summary
+    // Calculate outliers
+        // For both the left and right of the distribution
+// Questions to ask:
+    // Should we determine the overall average color? ANS: Yes
+    // Should we determine the averages of red, green,
+        // and blue? ANS: Yes 
+    // Should the RGB values be ordered in sep. arrays
+        //  of three? ANS: We will need to consider three distributions if thats the case
+
+} // END OF NAMESPACE 'rgb_dws'
+#endif
\ No newline at end of file