How can I generate a code to set interval every 1kwh consumption?

Hello everyone.......i'm actually doing something with prepaid electricity....basically i just extract analog data from mains through an ac power analyzer ...which serially outputs data in a csv format....my problem is....i want to set an interval in every 1 kwh consumption...my code would have to look like this:

void loop(){
receivedDataFromPowerAnalyzer(); //buffer,parse,delimiter code...
calculateWatthour();
displayDataToLCD();}

can someone help me how i can be able to generate a code that would be sending data every 1kwh consumption ....
it's like the pulse data out of electricity meters with led blinkers...in every n pulses, that'd to indicate a 1 kwh consumption...

i'd appreciate if someone helps...thanks

Easy:

void loop(){
  receivedDataFromPowerAnalyzer(); //buffer,parse,delimiter code...
  consumption=calculateWatthour();
  displayDataToLCD();
  if (consumption - last_consumption > CONSUMPTION_1KWH) {last_consumption+=CONSTUMPTION_1KWH; send_pulses();}}

something like this?

long KWHtrigger = 0;

long totalWatts = 0;

void loop()
{
  totalWatts = receivedDataFromPowerAnalyzer(); // buffer,parse,delimiter code... 
  if (totalWatts > KWHtrigger)
  {
    KWHtrigger += 1000;  // set for next KWH trigger

    do_your_thing();
  }
  calculateWatthour();
  displayDataToLCD();
}

sir...... the receivedDataFromPowerAnalyzer(); is a function....this can be assigned to a variable with long int data type??? ...and that data out from the ac power analyzer is in character array....could you please clear my doubts sir.....

dhenry:
Easy:

void loop(){

receivedDataFromPowerAnalyzer(); //buffer,parse,delimiter code...
  consumption=calculateWatthour();
  displayDataToLCD();
  if (consumption - last_consumption > CONSUMPTION_1KWH) {last_consumption+=CONSTUMPTION_1KWH; send_pulses();}}

sir dhenry......where is this CONSUMPTION_1KWH??? is there some initialization ....? and what is send_pulses();?? i'm not using electric meters with pulse out sir.... :slight_smile:

That's something for YOU to write.

@phoenix1118

How much electro and software experience do you have?