Subversion Repositories HomeAutomation

Rev

Rev 818 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /*
  2.  * LDR, Light Dependent Resistor
  3.  *
  4.  * Using ADC driver for reading sensor value.
  5.  *
  6.  * Author: Erik Larsson, Anders Runeson
  7.  * Date: 2007-04-26
  8.  *
  9.  */
  10.  
  11. /*-----------------------------------------------
  12.  * Includes
  13.  * ---------------------------------------------*/
  14. #include <avr/io.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17.  
  18. #include "ldr.h"
  19. #include <config.h>
  20. #include <drivers/adc/adc.h>
  21. /*----------------------------------------------
  22.  * Functions
  23.  * --------------------------------------------*/
  24.  
  25. uint8_t LDR_SensorInit(void)
  26. {  
  27.     return ADC_Init();
  28. }
  29.  
  30. /*
  31.  * Start reading sensor value
  32.  * returns the lightvalue in promille (0.1% per bit)
  33.  */
  34. uint16_t LDR_GetData(uint8_t sensor)
  35. {
  36.     uint16_t ldr = ADC_Get(sensor);
  37.     if (ldr>1000) {
  38.         ldr=1000;
  39.     }
  40.     return ldr;
  41. }
  42.