Undefined reference to 'loop error - URGENT!!

Guys i really need some help here. Im actually a newbie programming, and i’ve got stuck at this error. If someone could help would be great. (Sorry for bad english, not my native language)

//Error:C:\DOCUME~1\ALUNO2~1\CONFIG~1\Temp\build1e5bb35abec021de725b24d345a61130.tmp/core\core.a(main.cpp.o): In function `main’:

C:\Arquivos de programas\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:47: undefined reference to `loop’//

Here is my code (It’s in portuguese but hopefully you understand it):

//Carrega bibliotecas
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#include “EmonLib.h”
#include <SPI.h>

// Referênia a biblioteca emonl
EnergyMonitor emon1;

// Pinagem e configuração do display
Adafruit_PCD8544 display = Adafruit_PCD8544(8, 9, 10, 11, 12);

//Tensao da rede eletrica
int rede = 110;

//Pino do sensor SCT
int pino_sct = A1;

//Calcula a corrente
double Irms = emon1.calcIrms(1480);

//Variáveis globais
double potencia = Irmsrede/10003600;
double valor = potencia*0.75;
double valotT = valor;

void setup()
{
Serial.begin(9600);
//Pino, calibracao - Cur Const= Ratio/BurdenR. 2000/33 = 60
emon1.current(pino_sct, 60);
//Ajuste iniciais display
display.begin();
//Ajusta o contraste do display
display.setContrast(40);
//Apaga o buffer e o display
display.clearDisplay();
//Define tamanho do texto e cor
display.setTextSize(1);
display.setTextColor(BLACK);

//Retangulo principal
display.drawRect(0, 0, 84, 48, 2);
//Retangulo menor
display.fillRect(0, 0, 84, 15, 2);
display.setTextColor(WHITE, BLACK);
display.setCursor(15, 4);
display.println(“TCC SENAI”);
display.setTextColor(BLACK, WHITE);
display.setTextSize(1);
}

void loop(double Irms, double valorT, double potencia, double valor)
{
//Mostra o valor da corrente no serial monitor e display
Serial.print("Corrente : ");
Serial.print(Irms); // Irms
display.setCursor(8, 18);
display.print(“Corr:”);
display.print(Irms, 2);
display.display();
display.setCursor(67, 18);
display.println(“A”);

//Calcula e mostra o valor da potencia
Serial.print(“Potencia :”);
Serial.print(Irmsrede/10003600);
display.setCursor(8, 28);
display.println(“Pot:”);
display.setCursor(30, 28);
display.print(Irmsrede/10003600);
display.setCursor(67, 28);
display.println(“kW”);

//Calcula o valor do preço
for (double x=0;x<10;x++){
valorT= valorT+valor;
display.setCursor(8, 40);
display.print(valorT);
delay(1000);
}
}

Why are you using a loop function that takes parameters. The linker will look for a loop function that doesn't use arguments.

Not only that but you you've written it so that it shadows out a bunch of global variables. If you are going to write a function that takes arguments don't give those arguments the same names as your global variables. Having two variables in the same scope with the same name is almost always a very very bad idea.

As i've said i'm newbie, i know what is wrong i just don't know how to fix it.

void loop(double Irms, double valorT, double potencia, double valor)What is going to call this function and supply the values for the parameters do you suppose ?

felipebf147:
As i've said i'm newbie, i know what is wrong i just don't know how to fix it.

The first thing would be to read the how to use this forum post.

The second thing would be to take all that stuff out of the parenthesis behind loop

Rename loop to ‘myfunction’ or something that makes more sense

[s]void loop(double Irms, double valorT, double potencia, double valor)[/s]
void myfunction(double Irms, double valorT, double potencia, double valor)

And next write a normal loop that calls that function.

void loop()
{
  // setup the variables
  ...
  ...

  // call myfunction
  myfunction(someDouble, someValorT, somePotencia, someValor);
}

void myfunction(double Irms, double valorT, double potencia, double valor)
{
  ...
  ...
}

The variables that you pass to myfunction need to get values from somewhere; that you need to do before you call myfunction.

PS
You should post code using code tags as mentioned before
Type
** **[code]** **

Paste your code after that
Type
** **[/code]** **
after that

If you'll notice, those are all names of his global variables. I'm betting those global are what he wants in the function in which case he doesn't need to pass anything. Just empty those parenthesis and it will work.

Delta_G:
If you'll notice, those are all names of his global variables. I'm betting those global are what he wants in the function in which case he doesn't need to pass anything. Just empty those parenthesis and it will work.

I could not find all of them, but only at my first coffee of the day when I posted is a valid excuse :smiley: