Help i cant fix the error

void setup() {
  // put your setup code here, to run once:#include <OneWire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <RTClib.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>
#include <DS1302.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET    -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define ONE_WIRE_BUS 2  
#define RELAY_PIN    3  

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

DS1302 rtc(7, 8, 9);

void controlPump(bool on) {
  digitalWrite(RELAY_PIN, on ? LOW : HIGH); 
}

void setup() {
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);

  sensors.begin();

  pinMode(RELAY_PIN, OUTPUT);
  controlPump(false); 

  rtc.halt(false);
  rtc.writeProtect(false);
  
  rtc.setDOW(SUNDAY);
  rtc.setTime(12, 0, 0);
  rtc.setDate(1, 1, 2024);
}

void loop() {
  sensors.requestTemperatures();
  float temperatureF = sensors.getTempFByIndex(0);

  DateTime now = rtc.now();

  display.clearDisplay();
  display.setCursor(0, 0);
  display.print("Time: ");
  display.print(now.hour());
  display.print(":");
  display.print(now.minute());
  display.print(":");
  display.print(now.second());
  display.print(" Temp: ");
  display.print(temperatureF);
  display.println(" F");
  display.display();

  if ((now.hour() == 6 || now.hour() == 12 || now.hour() == 18) && now.minute() == 0 && now.second() == 0) {
    controlPump(true);
    delay(600000); 
    controlPump(false);
  }

  if (temperatureF >= 90.0) {
    controlPump(true);
    delay(600000); 
    controlPump(false);
  }

  delay(1000); // Delay between loop iterations
}

}

ERROR TEXT:

In file included from C:\Users\User\Documents\Arduino\libraries\OneWire/OneWire.h:9:0,
                 from C:\Users\User\Documents\Arduino\aquaphonic\aquaphonic.ino:3:
c:\users\user\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\util\crc16.h: In function 'void setup()':
c:\users\user\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\util\crc16.h:114:1: error: a function-definition is not allowed here before '{' token
 {
 ^
c:\users\user\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\util\crc16.h:180:1: error: a function-definition is not allowed here before '{' token
 {
 ^
c:\users\user\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\util\crc16.h:254:1: error: a function-definition is not allowed here before '{' token
 {
 ^
c:\users\user\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\util\crc16.h:321:1: error: a function-definition is not allowed here before '{' token
 {
 ^
c:\users\user\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\util\crc16.h:387:1: error: a function-definition is not allowed here before '{' token
 {
 ^
C:\Users\User\Documents\Arduino\aquaphonic\aquaphonic.ino:24:27: error: a function-definition is not allowed here before '{' token
 void controlPump(bool on) {
                           ^
C:\Users\User\Documents\Arduino\aquaphonic\aquaphonic.ino:28:14: error: a function-definition is not allowed here before '{' token
 void setup() {
              ^
C:\Users\User\Documents\Arduino\aquaphonic\aquaphonic.ino:47:13: error: a function-definition is not allowed here before '{' token
 void loop() {
             ^

exit status 1

Compilation error: a function-definition is not allowed here before '{' token```

I'm guessing you have an extra { or } in your main sketch. Try auto formatting your sketch in the IDE and it will help you figure out where it is.

And, please use the code tags when posting code.

Sorry saying that, but your code is a complete mess, it is probably put together from pieces found on the net without any understanding of how programs are written.

Below are some problems:

  • you have a multiple setup() functions
  • you put the includes in setup() - it haven't be there:
  • you have a function declared inside the other function... the C language doesn't allowed that

Please start with the Arduino examples to understand how the sketch should be formatted

The tip:
It looks like you copied the entire sketch inside the setup procedure. If you remove the first line and the closing bracket at the end of the code, it is possible that there will be significantly fewer errors.

There are 2 void setup() {
Line 1 and line 28

Remove void setup() from line 1.

Should you be using Ds1302.h and not DS1302.h ? (big D small s)
disregard. this one is not correct.

I think you need to take a little break. And stop beating up the kids.

Your setup has no ending brace.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.