Nespresso RGB Sensor / ColorDetectorV2

Dependencies:   GroveColourSensor

Dependents:   nespresso_endpoint CapsuleCalibrator EnvoyNespressoEndpointColorDetectorV2

Committer:
bridadan
Date:
Thu Jul 16 18:25:18 2015 +0000
Revision:
4:b7ce6f2b2a46
Parent:
3:3fca51432fd3
Changing default photoresistor value for 3.3v devices

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bridadan 0:a00a518e19b2 1 #ifndef _COLOR_DETECTOR_H_
bridadan 0:a00a518e19b2 2 #define _COLOR_DETECTOR_H_
bridadan 0:a00a518e19b2 3
bridadan 0:a00a518e19b2 4 #include "mbed.h"
bridadan 0:a00a518e19b2 5 #include "GroveColourSensor.h"
bridadan 0:a00a518e19b2 6
bridadan 0:a00a518e19b2 7 #define CD_BUFF_LEN 512
bridadan 0:a00a518e19b2 8 #define CD_PR_BUFF_LEN 30
bridadan 0:a00a518e19b2 9
bridadan 0:a00a518e19b2 10
bridadan 0:a00a518e19b2 11 /** ColorDetector class.
bridadan 0:a00a518e19b2 12 * Used for detecting changes in color readings from a Grove colour sensor: http://www.seeedstudio.com/depot/Grove-I2C-Color-Sensor-p-854.html.
bridadan 1:ccb3cd3f9c22 13 * Also uses a photoresistor to detect when an object passes between the colour sensor and the photoresistor.
bridadan 0:a00a518e19b2 14 */
bridadan 0:a00a518e19b2 15 class ColorDetector {
bridadan 0:a00a518e19b2 16 public:
bridadan 0:a00a518e19b2 17 /**
bridadan 0:a00a518e19b2 18 * Constructor.
bridadan 0:a00a518e19b2 19 *
bridadan 0:a00a518e19b2 20 * @param sensor Pointer to instantiated and powered up Grove colour sensor.
bridadan 1:ccb3cd3f9c22 21 * @param photoresistorPin The pin of the photoresistor.
bridadan 1:ccb3cd3f9c22 22 * @param prThreshold The value that the photoresistor must dip below before samples are taken.
bridadan 1:ccb3cd3f9c22 23 * NOTE: Lower this if no samples are being taken.
bridadan 3:3fca51432fd3 24 * @param minNumSamples The minimum number of samples that must be taken for a capture event to be considered valid.
bridadan 3:3fca51432fd3 25 * NOTE: Lower this if no samples are being taken.
bridadan 0:a00a518e19b2 26 */
bridadan 4:b7ce6f2b2a46 27 ColorDetector(GroveColourSensor *sensor, PinName photoresistorPin, float prThreshold = 0.55, int minNumSamples = 100);
bridadan 0:a00a518e19b2 28
bridadan 0:a00a518e19b2 29 /**
bridadan 1:ccb3cd3f9c22 30 * Takes a new reading from the sensor. If the value of the photoresistor is below prThreshold,
bridadan 1:ccb3cd3f9c22 31 * then the color sensor is sampled. Once the photoresistor value rises above prThresholdagain,
bridadan 1:ccb3cd3f9c22 32 * it returns the number of samples it took. Otherwise, it returns 0;
bridadan 0:a00a518e19b2 33 */
bridadan 0:a00a518e19b2 34 int sample();
bridadan 0:a00a518e19b2 35
bridadan 0:a00a518e19b2 36 /**
bridadan 0:a00a518e19b2 37 * Returns a pointer to the sample buffer (pointer does not change).
bridadan 0:a00a518e19b2 38 */
bridadan 0:a00a518e19b2 39 RGBC* getBuffer();
bridadan 0:a00a518e19b2 40
bridadan 0:a00a518e19b2 41 private:
bridadan 0:a00a518e19b2 42 GroveColourSensor *sensor;
bridadan 1:ccb3cd3f9c22 43 AnalogIn photoresistor;
bridadan 0:a00a518e19b2 44 float prThreshold;
bridadan 3:3fca51432fd3 45 int minNumSamples;
bridadan 0:a00a518e19b2 46 RGBC* curBufPtr;
bridadan 0:a00a518e19b2 47 bool capturing;
bridadan 0:a00a518e19b2 48 RGBC sample_buf[CD_BUFF_LEN];
bridadan 0:a00a518e19b2 49 };
bridadan 0:a00a518e19b2 50
bridadan 0:a00a518e19b2 51 #endif