first commit
This commit is contained in:
58
ESP8266_DOMOTICZ_HALL/Modules.cpp
Normal file
58
ESP8266_DOMOTICZ_HALL/Modules.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "Modules.h"
|
||||
|
||||
Modules::Modules()
|
||||
{
|
||||
|
||||
}
|
||||
void Modules::sleep(int sleepTime)
|
||||
{
|
||||
Serial.print("Go to sleep ");
|
||||
Serial.println(sleepTime);
|
||||
delay(20);
|
||||
|
||||
ESP.deepSleep(sleepTime * 1000000L); // Infini
|
||||
|
||||
//sleepWifi();
|
||||
delay(200);
|
||||
}
|
||||
|
||||
int Modules::readIntensite()
|
||||
{
|
||||
int mVperAmp = 185; // use 100 for 20A Module and 66 for 30A Module
|
||||
int RawValue= 0;
|
||||
int ACSoffset = 2500;
|
||||
double Voltage = 0; //voltage measuring
|
||||
double Amps = 0;// Current measuring
|
||||
|
||||
int valeur;
|
||||
float moyenne = 0;
|
||||
int nbr_lectures = 50;
|
||||
|
||||
for( int i = 0; i < nbr_lectures; i++ )
|
||||
{
|
||||
valeur = analogRead( A0 );
|
||||
moyenne = moyenne + float(valeur);
|
||||
delay(10);
|
||||
}
|
||||
moyenne = moyenne / float(nbr_lectures);
|
||||
RawValue = moyenne -235;
|
||||
|
||||
// RawValue = valeurACS712(analogIn);//reading the value from the analog pin
|
||||
Voltage = (RawValue / 1024.0) * 5000; // Gets you mV
|
||||
Amps = ((Voltage - ACSoffset) / mVperAmp);
|
||||
|
||||
//Prints on the serial port
|
||||
Serial.print("Raw Value = " ); // prints on the serial monitor
|
||||
Serial.print(RawValue); //prints the results on the serial monitor
|
||||
|
||||
|
||||
Serial.print("\t mV = "); // shows the voltage measured
|
||||
Serial.print(Voltage,3); // the '3' after voltage allows you to display 3 digits after decimal point
|
||||
|
||||
Serial.print("\t Amps = "); // shows the voltage measured
|
||||
Serial.println(Amps,3);// the '3' after voltage allows you to display 3 digits after decimal point
|
||||
|
||||
lum = Amps;
|
||||
return Amps * 1000;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user