Sensorian  1.0
C API Reference Guide Library
main.c
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (C) 2015 Sensorian
3  * *
4  * This file is part of Sensorian. *
5  * *
6  * Sensorian is free software: you can redistribute it and/or modify it *
7  * under the terms of the GNU Lesser General Public License as published *
8  * by the Free Software Foundation, either version 3 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * Sensorian is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with Sensorian. *
18  * If not, see <http://www.gnu.org/licenses/>. *
19  ****************************************************************************/
20 
28 #include <stdio.h>
29 #include <unistd.h>
30 #include "APDS9300.h"
31 #include "Utilities.h"
32 #include "i2c.h"
33 
34 int main(int argc, char **argv)
35 {
36  float lux =0;
37 
38  I2C_Initialize(APDS9300ADDR); //Initialize I2C controller
39  AL_Initialize();
40  printf("Ambient light Chip ID: 0x%02X. \r\n",AL_ChipID());
41 
42  AL_SetGain(GAIN_16); //Gain of 16x for low lighting conditions
45  delay_ms(1000);
46 
47  while(1)
48  {
49  unsigned int channel1 = AL_ReadChannel(CH0); //Take a reading from channel one
50  printf("Channel one value: %d.\r\n" ,channel1);
51  unsigned int channel2 = AL_ReadChannel(CH1); //Take a reading from channel two
52  printf("Channel two value: %d.\r\n" ,channel2);
53  lux = AL_Lux(channel1,channel2);
54  printf("Lux value: %f.\r\n" ,lux);
55  delay_ms(1000);
56  }
57 
58  I2C_Close(); //Return I2C pins to default status
59 
60  return 0;
61 }
void AL_SetSamplingTime(sampTime_t sampling_time)
Sets the sampling time for the sensor,can be one of three predetermined values.
Definition: APDS9300.c:153
void I2C_Close(void)
Closes the I2C peripheral.
Definition: i2c.c:174
unsigned char AL_ChipID(void)
Returns the CHIP id.
Definition: APDS9300.c:65
Definition: APDS9300.h:90
unsigned char AL_Initialize(void)
Powers on the sensor , sets sensor gain to 1x and clears any existing interrupts. ...
Definition: APDS9300.c:42
unsigned char AL_SetGain(gain val)
Set sensor gain. Default gain value is GAIN_1 or 1x.
Definition: APDS9300.c:126
void I2C_Initialize(unsigned char address)
Initializes the I2C peripheral.
Definition: i2c.c:36
Definition: APDS9300.h:91
Utilities driver.
Definition: APDS9300.h:104
void AL_Clear_Interrupt(void)
Clear any existing interrupts.
Definition: APDS9300.c:183
APDS9300 driver header file.
int main(int argc, char **argv)
Definition: main.c:34
void delay_ms(unsigned int ms)
Delay in ms.
Definition: Utilities.c:39
I2C driver.
unsigned int AL_ReadChannel(channel chan)
Reads the value from one of the two photodiode channels.
Definition: APDS9300.c:77
float AL_Lux(unsigned int ch0, unsigned int ch1)
Computes LUX ambient light value from sensor data.
Definition: APDS9300.c:103
#define APDS9300ADDR
The I2C address of the APDS9300 ambient light sensor.
Definition: APDS9300.h:37