Hi guys i've ran into some problems while trying to build my software. I have a current sensor in my Arduino Leonardo that monitors the electricity usage and serial prints the data every 0.1 sec but when I add another current sensor, my data takes longer to print despite the software having a TimerOne running every 0.1 secs.
Below is my coding, any help would be appreciated, thanks!
#include "EmonLib.h"
#include <TimerOne.h>
EnergyMonitor emon1;
EnergyMonitor emon0;
int analogInPin1 = A1;
int analogInPin0 = A0;
Timer1.initialize(100000);
Timer1.attachInterrupt(timerAction); // run every 0.1 seconds
emon0.current(A0, 28.1);
emon1.current(A1, 28.1); // Current: input pin, calibration.
unsigned short int timerCount =0;
void setup()
{
analogRead (A1) ;
analogRead (A0) ;
}
void loop()
{
readRms0();
readRms1();
timerTriger = 1;
if(timerTriger == 1)
{
ActiveLed = ~ActiveLed;
digitalWrite(13, ActiveLed);
rf_Data = RmsStr0 + "," + RmsStr1;
Serial.println(rf_Data);
timerTriger = 0;
if (timerTriger == 0){
rf_Data = "";
}
}
}
void readRms0(){
Irms0 = emon0.calcIrms(500);
RmsStr0 = String(Irms0);
}
void readRms1()
{
double Irms1= emon1.calcIrms(500);
RmsStr1= String(Irms1);
wdt_reset();
}
void timerAction(void)
{
timerCount = timerCount + 1; // increase when LED turns on
}