Compiling error?

Hi, no idea why it doesn’t wanna compile. Code and error are below.

const float k=1.0;
const byte stophour=20;
const byte starthour=8;
const unsigned int umbrellaposition=1000;
const byte synchour=12;

bool dir=0;
bool homing=0;
bool limitswitch=0;
bool raining=0;
bool reverse_motor=0;
bool run_motor=0;
bool umbrelladone=0;

unsigned long currentseconds=0;
unsigned int timer1=0;

volatile unsigned int slot = 0;

void setup()
{
  pinMode(1, INPUT_PULLUP); //Limit switch at the home (morning) position + sync signal
  pinMode(2, INPUT_PULLUP); //Gap sensor
  pinMode(3, OUTPUT); //Motor reverse
  pinMode(4, OUTPUT); //Motor enable
  pinMode(5, INPUT); //Rain sensor
  
  attachInterrupt(0, gapsensor, FALLING);
  Serial.begin(9600);
}

void loop()
{
  //Pin readings
  if(digitalRead(1)==LOW)
  limitswitch=1;
  else
  limitswitch=0;

  if(digitalRead(5)==HIGH)
  raining=1;
  else
  raining=0;

  //Homing
  if(homing==1)
  {
    //Homing sequence
    Serial.println("Homing...");
    dir=0;
    reverse_motor=1;
    run_motor=1;
    if(limitswitch==1)
    {
      dir=1;
      reverse_motor=0;
      run_motor=0;
      slot=0;
      homing=0;
      Serial.println("Homing done!");
    }
  }

  //sync signal
  if(homing==0 && limitswitch==1 && slot>100)
  currentseconds=synchour*60*60;
      
  if(raining==0) //if its not raining, act normal, else get to umbrella position.
  {
    //moving the mirror
    if(currentseconds-(starthour*60*60) >= slot*k && currentseconds < stophour*60*60) //if the time is right to move AND its not night
    {
      dir=1;
      reverse_motor=0;
      run_motor=1;
    }
    else
      run_motor=0;
    
    //moving the mirror to the morning position
    if(currentseconds>=stophour*60*60)
      homing=1;
  }
  else if(umbrelladone==0) //if its raining AND not yet in the umbrella position
  {
    if(slot==umbrellaposition)
    {
      reverse_motor=0;
      run_motor=0;
      umbrelladone=1;
    }
    if(slot>umbrellaposition)
    {
      dir=0;
      reverse_motor=1;
      run_motor=1;
    }
    if(slot<umbrellaposition)
    {
      dir=1;
      reverse_motor=0;
      run_motor=1;
    }
  }

  //Timer advancing
  if(millis()>=timer1+1000)
  {
    currentseconds++;
    timer1=millis();
  }
  if(currentseconds>=24*60*60) //currentseconds overflow when the day is done
  currentseconds=0;

  //Pin writings
  if(run_motor==1)
  digitalWrite(4, HIGH);
  else
  digitalWrite(4, LOW);

  if(reverse_motor==1)
  digitalWrite(3, HIGH);
  else
  digitalWrite(3, LOW);
}

void gapsensor()
{
  if(dir==1)
    slot++;
  else
    slot--;
}

This is the error:
sketch\clock_timer.ino.cpp.o (symbol from plugin): In function `count()’:

(.text+0x0): multiple definition of `setup’

sketch\Heliostat2.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

sketch\clock_timer.ino.cpp.o (symbol from plugin): In function `count()’:

(.text+0x0): multiple definition of `loop’

sketch\Heliostat2.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino Uno.

Compiles fine for me

-jim lee

I found in the end a solution. I uninstalled and reinstalled the Arduino IDE. Now it works.

My bet would be that you has 2 tabs in the IDE, each with a sketch in them, hence 2 setup() functions

There was only one tab open, yet the IDE glitched somehow... anyway, its fixed now.

You could edit the thread title to indicate that the issue is solved so members don't open the thread hoping to help only to find the problem solved.