/*******************************************************************************
* Copyright (c) 2016 Julien Louette & Gaƫl Wittorski
*
* This file is part of Raspoid.
*
* Raspoid is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspoid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Raspoid. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package com.raspoid.additionalcomponents;
import com.raspoid.AnalogComponent;
import com.raspoid.additionalcomponents.adc.ADC;
import com.raspoid.additionalcomponents.adc.ADCChannel;
import com.raspoid.examples.additionalcomponents.PhotoresistorExample;
/**
* A photoresistor is a light-controlled variable resistor. The resistance of a
* photoresistor decreases with increasing incident light intensity.
*
* <p>Unlike infrared detectors, photocells are good at detecting yellow/green visible light,
* but not infrared light.</p>
*
* <p>This component uses an ADC (Anolog to Digital Converter) to transform the analog
* signal generated by the photoresistor variations.</p>
*
* <p>Example Datasheet: <a href="http://raspoid.com/download/datasheet/Photoresistor">Photoresistor</a></p>
*
* <p>Example of use: {@link PhotoresistorExample}</p>
*
* @see ADC
*
* @author Julien Louette & Gaël Wittorski
* @version 1.0
*/
public class Photoresistor extends AnalogComponent {
private ADCChannel photoresistorChannel;
/**
* Constructor for a photoresistor using a specific ADC instance, and a specific
* channel on this ADC to decode the analog input from the photoresistor.
* @param adc the ADC to use to decode analogic signals from the photoresistor.
* @param photoresistorChannel the channel on the ADC used to read inputs from the photoresistor.
*/
public Photoresistor(ADC adc, ADCChannel photoresistorChannel) {
super(adc);
this.photoresistorChannel = photoresistorChannel;
}
/**
* Get the light intensity read from the photoresistor.
* @return the light intensity read from the photoresistor.
*/
public int getIntensity() {
return adc.analogToDigital(photoresistorChannel);
}
}