import stamp.core.*; /** * A luminositymeasurer with photoresistor. *
* Call on object with Luminosity(int minimumlight, int photopin) * Class has two methods. measure() returns xxx int value and staus * boolean value if there is enough light compared with minimumlight. * * * @version 1.0 13.02.2004 * @author Jaakko Pajunen */ public class Luminosity{ private int pin, min, dischargeTime; public Luminosity(){ } public Luminosity(int min,int pin){ this.pin = pin; this.min = min; } //Light amount can be derived from /tau = RC, where capacity C is constant //and dischargetime /tau measured so that R can be calculated. public int measure() { try{ CPU.writePin(pin,true); CPU.delay(10); this.dischargeTime = CPU.rcTime(5000,pin,false); if(this.dischargeTime==-1) this.dischargeTime=Integer.MAX_VALUE; return this.dischargeTime; } catch (Exception e){ System.out.println("DischargeTime error"); return 0; } } public boolean status() { if (dischargeTime > min) return false; //Return false when there is not enough light else return true; } }