Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#include <EEPROM.

h>
#include "EmonLib.h" // Include Emon Library

int depositpulse = 0;
volatile float revenue = 0.00; //start running total
volatile float deposit = 0.00; //start total
volatile float money = 0.00; //start total
int totalcan1 = 12; //total possible cans to fit in machine

int can1sold = 0; //start record of cans sold


int can1amount = 0; //cans in machine

int voltage1 = Vrms;

int mem_can1sold = 2; //Address for can1 eeprom

int mem_can1amount = 5; //cans in machine eeprom

int mem_deposit = 9; //deposit eeprom

int errorstate = 0; //error flag

int freestate = 0;

float AMP=0;
int coinsecurity = 0;
int currentMillis = 0;
int oldMillis = 0;
const int coinInt = 0;
volatile float coinsValue = 0.00; //start current credit
int coinsChange = 0;

volatile float cost = 1; //cost of pop


volatile float energyused = 0.00;

void setup()
{

Serial.begin(9600);
///////////////////////////
attachInterrupt(coinInt, coinInserted, RISING);

///////////////////////////////////////////////////////////////////////////////

void coinInserted()
//The function that is called every time it recieves a pulse
{

//As we set the Pulse to represent 5p or 5c we add this to the coinsValue


coinsChange = 1;
unsigned long currentMillis = millis();
int difference = currentMillis - oldMillis;
//lcd.print("Millis: ");
//lcd.println(difference);
oldMillis = currentMillis;
if (difference < 120 && difference > 90) {
coinsValue = coinsValue + 1;
coinsChange = 1;
}

//Flag that there has been a coin inserted


}

void displayEnergyScreen()
{

lcd.setCursor(0, 1);
lcd.print(watt);
lcd.print("W");

lcd.setCursor ( 10, 1 ); //set cursor after "credit:"


lcd.print(coinsValue); //show credit
lcd.print("P");
lcd.setCursor(0, 0); // set the cursor at 1st col and 2nd row
//lcd.print("ENERGY :");
lcd.print((AMP)/2);
lcd.print("WH ");
lcd.print((emon1.Vrms)*6.428571428571429);
lcd.print("E");

You might also like