Hello, I am turning to you in view of the fact that I need your help since I am developing a practice to count the ice creams that a machine dispenses, taking into account the duration that the lever lasts down. For this I use a button. So far so good, but when I try to put the EEPROM in it, it throws me the following error: "no matching function for call to ‘EEPROMClass::begin(int)’"
Here I attach the code:
[code]
#include <EEPROM.h>
#define EEPROM_SIZE 12
#define nieves 7 // Entrada palanca 1
int valor;
long tiempobase = 0; //El tiempo de inicio tiene un valor inicial de 0
long resta = 0;
long segundos = 0;
int chica = 7;
int mediana = 9;
int grande = 11;
int exgrand = 13;
int contadorchica = 0;
int contadormediana = 0;
int contadorgrande =0;
int contadorexgrand = 0;
int LDRSensor = 7;
int LedPin = 13;
int Valorsensor = 0;
int contadormantenimiento = 0;
int nosiguecontando = 0; //Variable para que al hacer la iteración no siga
//contando mantenimiento al seguir el foco encendido
void setup() {
Serial.begin(9600);
EEPROM.begin(EEPROM_SIZE);
pinMode(nieves, INPUT);
pinMode(LDRSensor, INPUT);
nieves = EEPROM.read(1);
LDRSensor = EEPROM.read(6);
}
void loop() {
valor = digitalRead(nieves);
//Saber tiempo inicial
if (valor == 1) {
if (tiempobase == 0) {
tiempobase = millis();
Serial.print("Inicial:");
Serial.println(tiempobase);
}
}
//Saber duración
if(tiempobase > 0) {
resta = millis() - tiempobase;
Serial.print("Duración:");
Serial.println(resta);
}
//Llevar a segundos
if(resta > 1000) {
segundos = resta/1000;
Serial.print("Tiempo en segundos:");
Serial.println(segundos);
}
//Contar nieves chicas vencicas
if(segundos >= chica && segundos < 9) {
contadorchica++;
Serial.print("Nieves chicas:");
Serial.println(contadorchica);
}
//Contar nieves medianas
if(segundos >= mediana && segundos < 11) {
contadormediana++;
Serial.print("Nieves medianas:");
Serial.println(contadormediana);
}
//Contar nieves grandes
if(segundos >= grande && segundos < 13) {
contadorgrande++;
Serial.print("Nieves grandes:");
Serial.println(contadorgrande);
}
//Contar extragrandes
if(segundos >= exgrand) {
contadorexgrand++;
Serial.print("Nieves extragrandes:");
Serial.println(contadorexgrand);
}
tiempobase = 0;
segundos = 0;
//Lectura y conteo de mantenimiento del sensor LDR
Valorsensor = digitalRead(LDRSensor);
//Serial.print("Valor del sensor:");
//Serial.println(Valorsensor);
if (Valorsensor == 0) { //Activado, encendido el foco
if(nosiguecontando == 0) { //Para contar una sola vez, un solo mantenimiento cada vez, aunque el foco siga encendido
nosiguecontando = 1;
contadormantenimiento++;
Serial.print("Mantenimientos:");
Serial.print(contadormantenimiento);
}else {
nosiguecontando = 0;
}
}
}
[/code]
Hi cattledog, I've already rectified some things in my code, or so I think. I leave it at your disposal in case you could suggest any corrections that I have overlooked. This is the code:
[code]
#include <EEPROM.h>
#define EEPROM_SIZE 12
#define nieves 7 // Entrada palanca 1
int valor;
long tiempobase = 0; //El tiempo de inicio tiene un valor inicial de 0
long resta = 0;
long segundos = 0;
int chica = 7;
int mediana = 9;
int grande = 11;
int exgrand = 13;
int contadorchica = 0;
int contadormediana = 0;
int contadorgrande =0;
int contadorexgrand = 0;
int LDRSensor = 8;
//int LedPin = 13;
int Valorsensor = 0;
int contadormantenimiento = 0;
int nosiguecontando = 0; //Variable para que al hacer la iteración no siga
//contando mantenimiento al seguir el foco encendido
void setup() {
Serial.begin(9600);
//EEPROM.begin(EEPROM_SIZE);
pinMode(nieves, INPUT);
pinMode(LDRSensor, INPUT);
contadorchica = EEPROM.read(1);
contadormediana = EEPROM.read(6);
contadorgrande = EEPROM.read(11);
contadorexgrand = EEPROM.read(16);
contadormantenimiento = EEPROM.read(21);
}
void loop() {
valor = digitalRead(nieves);
//Saber tiempo inicial
if (valor == 1) {
if (tiempobase == 0) {
tiempobase = millis();
Serial.print("Inicial:");
Serial.println(tiempobase);
}
}
//Saber duración
if(tiempobase > 0) {
resta = millis() - tiempobase;
Serial.print("Duración:");
Serial.println(resta);
}
//Llevar a segundos
if(resta > 1000) {
segundos = resta/1000;
Serial.print("Tiempo en segundos:");
Serial.println(segundos);
}
//Contar nieves chicas vencicas
if(segundos >= chica && segundos < 9) {
contadorchica++;
Serial.print("Nieves chicas:");
Serial.println(contadorchica);
EEPROM.write(1, contadorchica);
//EEPROM.commit();
}
//Contar nieves medianas
if(segundos >= mediana && segundos < 11) {
contadormediana++;
Serial.print("Nieves medianas:");
Serial.println(contadormediana);
EEPROM.write(6, contadormediana);
//EEPROM.commit();
}
//Contar nieves grandes
if(segundos >= grande && segundos < 13) {
contadorgrande++;
Serial.print("Nieves grandes:");
Serial.println(contadorgrande);
EEPROM.write(11, contadorgrande);
//EEPROM.commit();
}
//Contar extragrandes
if(segundos >= exgrand) {
contadorexgrand++;
Serial.print("Nieves extragrandes:");
Serial.println(contadorexgrand);
EEPROM.write(16, contadorexgrand);
//EEPROM.commit();
}
tiempobase = 0;
segundos = 0;
//Lectura y conteo de mantenimiento del sensor LDR
Valorsensor = digitalRead(LDRSensor);
//Serial.print("Valor del sensor:");
//Serial.println(Valorsensor);
if (Valorsensor == 0) { //Activado, encendido el foco
if(nosiguecontando == 0) { //Para contar una sola vez, un solo mantenimiento cada vez, aunque el foco siga encendido
nosiguecontando = 1;
contadormantenimiento++;
Serial.print("Mantenimientos:");
Serial.print(contadormantenimiento);
EEPROM.write(21, contadormantenimiento);
}else {
nosiguecontando = 0;
}
}
}
[/code]
I'm not certain I follow the flow of the code, and what gets written to eeprom when, but you want to make certain that you are not writing too frequently to any cell. I would recommend that you comment out any writing and just verify your code with Serial output until your are certain you are not writing any cell in a very fast loop.
int contadorchica = 0;
int contadormediana = 0;
int contadorgrande =0;
int contadorexgrand = 0;
int contadormantenimiento = 0;
I'm not clear about these values you are storing in eeprom and if they are bytes(numbers less than 255) or larger numbers. An eeprom cell can only hold a value up to 255, and if your numbers are larger, they need to be stored in more than one cell, and you should use EEPROM.put() and EEPROM.get() for the larger values.
What are the 5 values you are storing to eeprom?
There may be better ways to store time values.
Hi cattledog, the purpose of the program is to keep track of the amount of small, medium, large and extra large ice cream dispensed from an ice cream machine. On the lever there is a button, through which the pulse is counted each time the lever is lowered so that an ice cream comes out. On the other hand, when maintenance is going to be carried out on the machine, the operator lowers all the levers and a light comes on in the machine (here we add a light sensor); at this moment we do not want this to count as ice cream dispensed, that is why the variable "contadormantenimiento" was created, so that it counts every time the machine is given maintenance.
I hope I have been eloquent with the summary of the objective of this practice, and I remain very attentive to your wise suggestions. Thank you very much in advance.
Thank you so much for the explanation of your program.
the purpose of the program is to keep track of the amount of small, medium, large and extra large ice cream dispensed from an ice cream machine.
You have not answered my previous question about whether the amounts are numbers greater than 255. If so, you will need to store 2 byte integers (or 4 byte longs) in the eeprom and you will need to uses .put() and.get() instead of .write() and .read().
I think there is a fundamental problem with the structure of your program, in that the loop repeats very fast, and, in the several second period where a condition is true, you will be incrementing the value and writing it to eeprom when it is really only a single dispense.
Do you see this in your testing?
My thoughts are to separate the time measurements from the eeprom logging actions taken dependent upon the measurement. You don't need to use seconds, but can just keep track of millis() after the button press. When the button is released and the duration is known, and thus the size of the dispense, then write to the eeprom only once.
Does this redesign make sense to you?
Can you write the code to calculate the duration of a button press?
You may need to add hardware or software debounce to the button, or perhaps use a button library like Bounce2.