Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TestColorSensorSadPanda
Fork of ADJD-S371_ColourSens by
ADJDColourSensor.h@2:f4607f324f03, 2013-12-14 (annotated)
- Committer:
- nolanwagener
- Date:
- Sat Dec 14 08:17:51 2013 +0000
- Revision:
- 2:f4607f324f03
- Parent:
- 1:7944a9bbbe4f
additional functions
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| MichaelW | 0:47465be3223d | 1 | /** |
| MichaelW | 0:47465be3223d | 2 | * @section LICENSE |
| MichaelW | 0:47465be3223d | 3 | *Copyright (c) 2010 ARM Ltd. |
| MichaelW | 0:47465be3223d | 4 | * |
| MichaelW | 0:47465be3223d | 5 | *Permission is hereby granted, free of charge, to any person obtaining a copy |
| MichaelW | 0:47465be3223d | 6 | *of this software and associated documentation files (the "Software"), to deal |
| MichaelW | 0:47465be3223d | 7 | *in the Software without restriction, including without limitation the rights |
| MichaelW | 0:47465be3223d | 8 | *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| MichaelW | 0:47465be3223d | 9 | *copies of the Software, and to permit persons to whom the Software is |
| MichaelW | 0:47465be3223d | 10 | *furnished to do so, subject to the following conditions: |
| MichaelW | 0:47465be3223d | 11 | * |
| MichaelW | 0:47465be3223d | 12 | *The above copyright notice and this permission notice shall be included in |
| MichaelW | 0:47465be3223d | 13 | *all copies or substantial portions of the Software. |
| MichaelW | 0:47465be3223d | 14 | * |
| MichaelW | 0:47465be3223d | 15 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| MichaelW | 0:47465be3223d | 16 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| MichaelW | 0:47465be3223d | 17 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| MichaelW | 0:47465be3223d | 18 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| MichaelW | 0:47465be3223d | 19 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| MichaelW | 0:47465be3223d | 20 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| MichaelW | 0:47465be3223d | 21 | *THE SOFTWARE. |
| MichaelW | 0:47465be3223d | 22 | * |
| MichaelW | 0:47465be3223d | 23 | * |
| MichaelW | 0:47465be3223d | 24 | * @section DESCRIPTION |
| MichaelW | 0:47465be3223d | 25 | * |
| MichaelW | 0:47465be3223d | 26 | * |
| MichaelW | 0:47465be3223d | 27 | */ |
| MichaelW | 0:47465be3223d | 28 | |
| MichaelW | 0:47465be3223d | 29 | #ifndef ADJDCOLOURSENS_H_ |
| MichaelW | 0:47465be3223d | 30 | #define ADJDCOLOURSENS_H_ |
| MichaelW | 0:47465be3223d | 31 | |
| MichaelW | 0:47465be3223d | 32 | /** |
| MichaelW | 0:47465be3223d | 33 | * |
| MichaelW | 0:47465be3223d | 34 | * Includes |
| MichaelW | 0:47465be3223d | 35 | * |
| MichaelW | 0:47465be3223d | 36 | */ |
| MichaelW | 0:47465be3223d | 37 | #include "mbed.h" |
| MichaelW | 0:47465be3223d | 38 | /** |
| MichaelW | 0:47465be3223d | 39 | * A class to interface with an Avago ADJD-S371-QR999. |
| MichaelW | 0:47465be3223d | 40 | * The class allows you to read the light levels setected by the sensor for each colour and to set the gain settings. |
| MichaelW | 0:47465be3223d | 41 | */ |
| MichaelW | 0:47465be3223d | 42 | class ADJDColourSensor{ |
| MichaelW | 0:47465be3223d | 43 | public: |
| MichaelW | 0:47465be3223d | 44 | ADJDColourSensor(PinName sda, PinName scl, PinName LED); |
| nolanwagener | 1:7944a9bbbe4f | 45 | |
| nolanwagener | 1:7944a9bbbe4f | 46 | /** |
| nolanwagener | 1:7944a9bbbe4f | 47 | * Read all the colors. |
| nolanwagener | 1:7944a9bbbe4f | 48 | */ |
| nolanwagener | 1:7944a9bbbe4f | 49 | |
| nolanwagener | 1:7944a9bbbe4f | 50 | void readColors(); |
| nolanwagener | 1:7944a9bbbe4f | 51 | |
| nolanwagener | 1:7944a9bbbe4f | 52 | int red(); |
| nolanwagener | 1:7944a9bbbe4f | 53 | int green(); |
| nolanwagener | 1:7944a9bbbe4f | 54 | int blue(); |
| nolanwagener | 1:7944a9bbbe4f | 55 | int clear(); |
| nolanwagener | 2:f4607f324f03 | 56 | int redCap(); |
| nolanwagener | 2:f4607f324f03 | 57 | int greenCap(); |
| nolanwagener | 2:f4607f324f03 | 58 | int blueCap(); |
| nolanwagener | 2:f4607f324f03 | 59 | int clearCap(); |
| nolanwagener | 2:f4607f324f03 | 60 | int redInt(); |
| nolanwagener | 2:f4607f324f03 | 61 | int greenInt(); |
| nolanwagener | 2:f4607f324f03 | 62 | int blueInt(); |
| nolanwagener | 2:f4607f324f03 | 63 | int clearInt(); |
| nolanwagener | 1:7944a9bbbe4f | 64 | |
| nolanwagener | 1:7944a9bbbe4f | 65 | int dotProduct(int* features); |
| nolanwagener | 1:7944a9bbbe4f | 66 | double dotProduct(double* features); |
| MichaelW | 0:47465be3223d | 67 | |
| MichaelW | 0:47465be3223d | 68 | /** |
| MichaelW | 0:47465be3223d | 69 | * Read the colour sensor channels. |
| MichaelW | 0:47465be3223d | 70 | * The red, green and blue values are |
| MichaelW | 0:47465be3223d | 71 | * |
| MichaelW | 0:47465be3223d | 72 | * @returns The clear result, ie the overall brightness |
| MichaelW | 0:47465be3223d | 73 | */ |
| MichaelW | 0:47465be3223d | 74 | float read(); |
| MichaelW | 0:47465be3223d | 75 | |
| MichaelW | 0:47465be3223d | 76 | /** |
| MichaelW | 0:47465be3223d | 77 | * Read the offsets from the device and into the corresponding members. |
| MichaelW | 0:47465be3223d | 78 | * |
| MichaelW | 0:47465be3223d | 79 | * @returns The value of the clear offset |
| MichaelW | 0:47465be3223d | 80 | */ |
| MichaelW | 0:47465be3223d | 81 | int readOffset(); |
| MichaelW | 0:47465be3223d | 82 | |
| nolanwagener | 1:7944a9bbbe4f | 83 | //float red, green, blue; |
| MichaelW | 0:47465be3223d | 84 | |
| MichaelW | 0:47465be3223d | 85 | signed int redOffset, greenOffset, blueOffset, clearOffset; |
| MichaelW | 0:47465be3223d | 86 | |
| MichaelW | 0:47465be3223d | 87 | /** |
| MichaelW | 0:47465be3223d | 88 | * Set the number of capacitors for each channel of the ADC. |
| MichaelW | 0:47465be3223d | 89 | * |
| MichaelW | 0:47465be3223d | 90 | * The values of the parameters must be between 0x00 and 0x0F |
| MichaelW | 0:47465be3223d | 91 | * @param redCap The number of capacitors for the red channel |
| MichaelW | 0:47465be3223d | 92 | */ |
| MichaelW | 0:47465be3223d | 93 | void setCapacitors(int redCap, int greenCap, int blueCap, int clearCap); |
| MichaelW | 0:47465be3223d | 94 | |
| MichaelW | 0:47465be3223d | 95 | /** |
| MichaelW | 0:47465be3223d | 96 | * Set the integration time slot for each of the ADCs. |
| MichaelW | 0:47465be3223d | 97 | * |
| MichaelW | 0:47465be3223d | 98 | * All the values are as a 12 bit number |
| MichaelW | 0:47465be3223d | 99 | * @param redInt The integration time slot for the red channel |
| MichaelW | 0:47465be3223d | 100 | * @param greenInt The integration time slot for the green channel |
| MichaelW | 0:47465be3223d | 101 | * @param blueInt The integration time slot for the blue channel |
| MichaelW | 0:47465be3223d | 102 | * @param clearInt The integration time slot for the clear channel |
| MichaelW | 0:47465be3223d | 103 | */ |
| MichaelW | 0:47465be3223d | 104 | void setIntegrationTimeSlot(int redInt, int greenInt, int blueInt, int ClearInt); |
| MichaelW | 0:47465be3223d | 105 | |
| MichaelW | 0:47465be3223d | 106 | void optimise(); |
| MichaelW | 0:47465be3223d | 107 | void optimise(int optimum); |
| MichaelW | 0:47465be3223d | 108 | void optimise(int redTarget, int blueTarget, int greenTarget, int clearTarget); |
| MichaelW | 0:47465be3223d | 109 | |
| MichaelW | 0:47465be3223d | 110 | |
| MichaelW | 0:47465be3223d | 111 | private: |
| MichaelW | 0:47465be3223d | 112 | I2C _sensor; |
| MichaelW | 0:47465be3223d | 113 | DigitalOut _LED; |
| MichaelW | 0:47465be3223d | 114 | int _red, _green, _blue, _clear; |
| MichaelW | 0:47465be3223d | 115 | int _address; |
| nolanwagener | 2:f4607f324f03 | 116 | int _redCap, _greenCap, _blueCap, _clearCap; |
| nolanwagener | 2:f4607f324f03 | 117 | int _redInt, _greenInt, _blueInt, _clearInt; |
| MichaelW | 0:47465be3223d | 118 | }; |
| MichaelW | 0:47465be3223d | 119 | #endif |
