Skip to content

Commit

Permalink
fix library
Browse files Browse the repository at this point in the history
  • Loading branch information
nomad605dis committed Apr 23, 2018
1 parent cbaffd5 commit 86896f3
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 63 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Датчик освещённости (Troyka-модуль)
===================================

Библиотека для Arduino, позволяющая считывать показатели [датчика освещённости](http://amperka.ru/product/troyka-light-sensor) в Люксах.
Библиотека для Arduino, позволяющая считывать показатели [датчика освещённости](http://amperka.ru/product/troyka-light-sensor) в люксах и фут-канделах.

Установка библиотеки
====================
Expand Down
33 changes: 0 additions & 33 deletions TroykaLight.cpp

This file was deleted.

24 changes: 0 additions & 24 deletions TroykaLight.h

This file was deleted.

15 changes: 10 additions & 5 deletions examples/lightTest/lightTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// создаём объект для работы с датчиком освещённости
// и передаём ему номер пина выходного сигнала
LIGHT sensorLight(A4);
TroykaLight sensorLight(A0);

void setup()
{
Expand All @@ -13,9 +13,14 @@ void setup()

void loop()
{
// вывод показателей сенсора освещённости в люксах
// считывание данных с датчика освещённости
sensorLight.read();
// вывод показателей сенсора освещённости в люксахи
Serial.print("Light is ");
Serial.print(sensorLight.readLight());
Serial.println(" Lx");
delay(100);
Serial.print(sensorLight.getLightLux());
Serial.print(" Lx\t");
// вывод показателей сенсора освещённости в фут-свечах
Serial.print(sensorLight.getLightFootCandles());
Serial.println(" Foot Candles");
delay(300);
}
Binary file added extras/GL5528_calculation.xls
Binary file not shown.
Binary file added extras/GL5528_datasheet.pdf
Binary file not shown.
21 changes: 21 additions & 0 deletions keywords.txt
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)
#######################################
9 changes: 9 additions & 0 deletions library.properties
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=*
36 changes: 36 additions & 0 deletions src/TroykaLight.cpp
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;
}
45 changes: 45 additions & 0 deletions src/TroykaLight.h
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_

0 comments on commit 86896f3

Please sign in to comment.