VISHAY CNY70 reflective sensor library

Dependents:   FRC_2018 0hackton_08_06_18 lib_FRC_2019 lib_FRC_2019 ... more

Committer:
haarkon
Date:
Thu May 31 17:26:08 2018 +0000
Revision:
3:18466f4e1a2c
Parent:
2:9dec6e856355
Tested CNY70 library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
haarkon 0:94ce69cee360 1 /**
haarkon 0:94ce69cee360 2 * @author Hugues Angelis
haarkon 0:94ce69cee360 3 *
haarkon 0:94ce69cee360 4 * @section LICENSE
haarkon 0:94ce69cee360 5 *
haarkon 0:94ce69cee360 6 * Copyright (c) 2010 ARM Limited
haarkon 0:94ce69cee360 7 *
haarkon 0:94ce69cee360 8 * Permission is hereby granted, free of charge, to any person obtaining a copy
haarkon 0:94ce69cee360 9 * of this software and associated documentation files (the "Software"), to deal
haarkon 0:94ce69cee360 10 * in the Software without restriction, including without limitation the rights
haarkon 0:94ce69cee360 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
haarkon 0:94ce69cee360 12 * copies of the Software, and to permit persons to whom the Software is
haarkon 0:94ce69cee360 13 * furnished to do so, subject to the following conditions:
haarkon 0:94ce69cee360 14 *
haarkon 0:94ce69cee360 15 * The above copyright notice and this permission notice shall be included in
haarkon 0:94ce69cee360 16 * all copies or substantial portions of the Software.
haarkon 0:94ce69cee360 17 *
haarkon 0:94ce69cee360 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
haarkon 0:94ce69cee360 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
haarkon 0:94ce69cee360 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
haarkon 0:94ce69cee360 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
haarkon 0:94ce69cee360 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
haarkon 0:94ce69cee360 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
haarkon 0:94ce69cee360 24 * THE SOFTWARE.
haarkon 0:94ce69cee360 25 *
haarkon 0:94ce69cee360 26 * @section DESCRIPTION
haarkon 0:94ce69cee360 27 *
haarkon 0:94ce69cee360 28 * VISHAY CNY70 Analog reflective sensor library
haarkon 0:94ce69cee360 29 *
haarkon 0:94ce69cee360 30 * @note this library provide a simple equivalent of the reading the voltage of
haarkon 0:94ce69cee360 31 * an analog input.
haarkon 0:94ce69cee360 32 */
haarkon 0:94ce69cee360 33
haarkon 0:94ce69cee360 34 #ifndef CNY70_H
haarkon 0:94ce69cee360 35 #define CNY70_H
haarkon 0:94ce69cee360 36
haarkon 0:94ce69cee360 37 /**
haarkon 2:9dec6e856355 38 * Includes : Mbed Library
haarkon 0:94ce69cee360 39 */
haarkon 0:94ce69cee360 40 #include "mbed.h"
haarkon 0:94ce69cee360 41
haarkon 0:94ce69cee360 42 /**
haarkon 2:9dec6e856355 43 * CNY70 Optical Reflective Sensor.
haarkon 2:9dec6e856355 44 * More info : https://www.vishay.com/docs/83751/cny70.pdf
haarkon 0:94ce69cee360 45 */
haarkon 0:94ce69cee360 46 class CNY70 {
haarkon 0:94ce69cee360 47
haarkon 0:94ce69cee360 48 public :
haarkon 0:94ce69cee360 49
haarkon 0:94ce69cee360 50 /**
haarkon 2:9dec6e856355 51 * Constructor of a CNY70 object.
haarkon 0:94ce69cee360 52 *
haarkon 2:9dec6e856355 53 * @param vmes : the Mbed pin used to connect with CNY70 sensor
haarkon 0:94ce69cee360 54 */
haarkon 0:94ce69cee360 55 CNY70(PinName vmes);
haarkon 0:94ce69cee360 56
haarkon 0:94ce69cee360 57 /**
haarkon 0:94ce69cee360 58 * Return the voltage on the CNY70 output pin
haarkon 0:94ce69cee360 59 *
haarkon 2:9dec6e856355 60 * @return Voltage between 0 and 3.3V
haarkon 0:94ce69cee360 61 */
haarkon 1:95219d950eeb 62 double getVoltage (void);
haarkon 1:95219d950eeb 63
haarkon 3:18466f4e1a2c 64 /**
haarkon 3:18466f4e1a2c 65 * Return the type of the ground (blue carpet or white stripe)
haarkon 3:18466f4e1a2c 66 *
haarkon 3:18466f4e1a2c 67 * @return 0 over a blue carpet, 1 over a PVC white stripe
haarkon 3:18466f4e1a2c 68 */
haarkon 3:18466f4e1a2c 69 int whatAmIOn (void);
haarkon 3:18466f4e1a2c 70
haarkon 1:95219d950eeb 71 /**
haarkon 1:95219d950eeb 72 * A short hand of getVoltage
haarkon 1:95219d950eeb 73 */
haarkon 1:95219d950eeb 74 operator double();
haarkon 1:95219d950eeb 75
haarkon 0:94ce69cee360 76
haarkon 0:94ce69cee360 77 protected :
haarkon 0:94ce69cee360 78
haarkon 0:94ce69cee360 79 AnalogIn _sensor ;
haarkon 0:94ce69cee360 80
haarkon 0:94ce69cee360 81 };
haarkon 0:94ce69cee360 82 #endif //CNY70_H