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  unsigned int i = 0;
37  unsigned int channel1,channel2;
38 
39  I2C_Initialize(APDS9300ADDR); //Initialize I2C and setup chip address
40  AL_Initialize();
41 
42  while(1)
43  {
44  AL_SetGain(GAIN_1); //Set gain to 1x , take 10 consecutive readings
45  for(i=0;i<10;i++)
46  {
47  channel1 = AL_ReadChannel(CH0);
48  channel2 = AL_ReadChannel(CH1);
49  printf("Gain 1: %d\t%d.\r\n" ,channel1,channel2);
50  delay_ms(500);
51  }
52 
53  AL_SetGain(GAIN_16); //Set gain to 16x , take 10 consecutive readings
54  for(i=0;i<10;i++)
55  {
56  channel1 = AL_ReadChannel(CH0);
57  channel2 = AL_ReadChannel(CH1);
58  printf("Gain 16: %d\t%d.\r\n" ,channel1,channel2);
59  delay_ms(500);
60  }
61  }
62  I2C_Close(); //Return I2C pins to default status
63  return 0;
64 }
void I2C_Close(void)
Closes the I2C peripheral.
Definition: i2c.c:174
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
Utilities driver.
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
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
#define APDS9300ADDR
The I2C address of the APDS9300 ambient light sensor.
Definition: APDS9300.h:37