Nos partenaires et nous-mêmes utilisons différentes technologies, telles que les cookies, pour personnaliser les contenus et les publicités, proposer des fonctionnalités sur les réseaux sociaux et analyser le trafic. Merci de cliquer sur le bouton ci-dessous pour donner votre accord. Vous pouvez changer d’avis et modifier vos choix à tout moment. Informations RGPD
from grove.adc import ADC from time import sleep as delay VoutArray = [ 0.0011498, 0.0033908, 0.011498, 0.041803,0.15199, 0.53367, 1.3689, 1.9068, 2.3] LuxArray = [ 1.0108, 3.1201, 9.8051, 27.43, 69.545, 232.67, 645.11, 73.52, 1000] def main(): while True: print("Vout =") print(readAPDS9002Vout(0)) print(" V,Luminance =") print(readLuminance(0)) print("Lux") delay(500) def readAPDS9002Vout(channel): analogPort = ADC() vout = analogPort.read(channel) * (3.0 / 1023.0) # Above 2.3V , the sensor value is saturated return vout def readLuminance(channel): # MeasuredVout = ADC Value * (Vcc / 1023) * (3 / Vcc) # Vout samples are with reference to 3V Vcc # The above expression is simplified by cancelling out Vcc measuredVout = readAPDS9002Vout(channel) luminance = FmultiMap(measuredVout, VoutArray, LuxArray, 9) """ The Luminance in Lux is calculated based on APDS9002 datasheet -- > Graph 1 ( Output voltage vs. luminance at different load resistor) The load resistor is 1k in this board. Vout is referenced to 3V Vcc. The data from the graph is extracted using WebPlotDigitizer http://arohatgi.info/WebPlotDigitizer/app/ VoutArray[] and LuxArray[] are these extracted data. Using MultiMap, the data is interpolated to get the Luminance in Lux. This implementation uses floating point arithmetic and hence will consume more flash, RAM and time. The Luminance in Lux is an approximation and depends on the accuracy of Graph 1 used. """ return luminance # This code uses MultiMap implementation from http://playground.arduino.cc/Main/MultiMap def FmultiMap(val, _in, _out, size): # take care the value is within range # val = constrain(val, _in[0], _in[size-1]) if val <= _in[0]: return _out[0] if val >= _in[size-1]: return _out[size-1] # search right interval pos = 1 # _in[0] allready tested while val > _in[pos]: pos += 1 # this will handle all exact "points" in the _in array if val == _in[pos]: return _out[pos] #interpolate in the right segment for the rest return (val - _in[pos-1]) * (_out[pos] - _out[pos-1]) / (_in[pos] - _in[pos-1]) + _out[pos-1] if __name__ == "__main__": main()