00001 00007 // 00008 // The contents of this file are subject to the Mozilla Public License 00009 // Version 1.0 (the "License"); you may not use this file except in 00010 // compliance with the License. You may obtain a copy of the License 00011 // at http://www.mozilla.org/MPL/ 00012 // 00013 // Software distributed under the License is distributed on an "AS IS" 00014 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00015 // the License for the specific language governing rights and 00016 // limitations under the License. 00017 // 00018 // This software was developed as part of the legOS project. 00019 // 00020 // Contributor: Pat Welch (legOS@mousebrains.com) 00021 00022 #ifndef _LightSensor_H_ 00023 #define _LightSensor_H_ 00024 00025 #include <config.h> 00026 #include <c++/Sensor.H> 00027 00028 #if defined(CONF_DSENSOR) 00029 00046 class LightSensor : public Sensor { 00047 public: 00053 LightSensor(const Sensor::Port port) : Sensor(port, true) {} 00061 unsigned int get() const {return LIGHT(sensor);} 00069 unsigned int sample(unsigned int size = 10, int wait = 2) const { 00070 if (size == 0) size = 1; 00071 unsigned int sum(get()); 00072 for (unsigned int i = 1; i < size; ++i) { 00073 sum += get(); 00074 delay(wait); 00075 } 00076 return sum / size; 00077 } 00078 }; 00079 00080 #else // CONF_DSENSOR 00081 #warning Enable CONF_DSENSOR to use LightSensor.H 00082 #endif // CONF_DSENSOR 00083 #endif // _LightSensor_H_
brickOS is released under the
Mozilla Public License.
Original code copyright 1998-2002 by the authors. |