-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cbaffd5
commit 86896f3
Showing
10 changed files
with
122 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
####################################### | ||
# Syntax Coloring Map TroykaLight | ||
####################################### | ||
|
||
####################################### | ||
# Datatypes (KEYWORD1) | ||
####################################### | ||
|
||
TroykaLight KEYWORD1 | ||
|
||
####################################### | ||
# Methods and Functions (KEYWORD2) | ||
####################################### | ||
|
||
read KEYWORD2 | ||
getLightLux KEYWORD2 | ||
getLightFootCandles KEYWORD2 | ||
|
||
####################################### | ||
# Constants (LITERAL1) | ||
####################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name=TroykaLight | ||
version=1.0.0 | ||
author=Igor Dementiev <igor@amperka.ru> | ||
maintainer=Amperka <amperka.ru> | ||
sentence=Allows you to read the Illuminance from the light sensor (GL5528). | ||
paragraph=The library allows you to obtain Illuminance data in Luxes and Foot Candles. | ||
category=Sensors | ||
url=https://github.com/amperka/TroykaLight | ||
architectures=* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/****************************************************************************/ | ||
// Function: Cpp file for TroykaLight | ||
// Hardware: GL5528 | ||
// Arduino IDE: Arduino-1.8.3 | ||
// Author: Igor Dementiev | ||
// Date: Apr 19,2018 | ||
// Version: v1.0.0 | ||
// by www.amperka.ru | ||
/****************************************************************************/ | ||
|
||
#include "TroykaLight.h" | ||
|
||
TroykaLight::TroykaLight(uint8_t pin) { | ||
_pin = pin; | ||
} | ||
|
||
void TroykaLight::read() { | ||
int sensorADC = 0; | ||
float sensorRatio = 0; | ||
float sensorResistance = 0; | ||
for (int i = 0; i < SAMPLE_TIMES; i++) { | ||
sensorADC += analogRead(_pin); | ||
} | ||
sensorADC = sensorADC >> 5; | ||
sensorRatio = (float)ADC_VALUE_MAX / (float)sensorADC - 1.0; | ||
sensorResistance = RES_DIVIDER / sensorRatio; | ||
_sensorLight = MULT_VALUE / (float)pow(sensorResistance, POW_VALUE); | ||
} | ||
|
||
float TroykaLight::getLightLux() { | ||
return _sensorLight; | ||
} | ||
|
||
float TroykaLight::getLightFootCandles() { | ||
return _sensorLight / LUX_TO_FOOT_CANDLES; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/****************************************************************************/ | ||
// Function: Header file for TroykaLight | ||
// Hardware: GL5528 | ||
// Arduino IDE: Arduino-1.8.3 | ||
// Author: Igor Dementiev | ||
// Date: Apr 19,2018 | ||
// Version: v1.0.0 | ||
// by www.amperka.ru | ||
/****************************************************************************/ | ||
|
||
#ifndef TROYKA_LIGHT_H_ | ||
#define TROYKA_LIGHT_H_ | ||
|
||
#include <Arduino.h> | ||
|
||
// resistance other resistor for divider (Ohm) | ||
#define RES_DIVIDER 10000.0 | ||
#define MULT_VALUE 32017200.0 | ||
#define POW_VALUE 1.5832 | ||
#define LUX_TO_FOOT_CANDLES 10.764 | ||
|
||
#define SAMPLE_TIMES 32 | ||
#define ADC_BIT 10 | ||
#define ADC_VALUE_MAX pow(2, ADC_BIT) | ||
|
||
#if defined(__AVR__) | ||
#define OPERATING_VOLTAGE 5.0 | ||
|
||
#elif defined(__SAM3X8E__) || defined(__SAM3A8C__) || defined(__SAM3A4C__) || defined(__SAMD21G18A__) || defined(ARDUINO_ARCH_ESP8266) || defined(__arm__) | ||
#define OPERATING_VOLTAGE 3.3 | ||
#endif | ||
|
||
class TroykaLight | ||
{ | ||
public: | ||
TroykaLight(uint8_t pin); | ||
void read(); | ||
float getLightLux(); | ||
float getLightFootCandles(); | ||
private: | ||
uint8_t _pin; | ||
float _sensorLight; | ||
}; | ||
#endif // TROYKA_LIGHT_H_ | ||
|