I have 2 sketches one is pixel clock with RTC ds 1307 and the other is 7 Segment with DHT 11, I want to merge the two into one but it is giving errors for rtc. sketch for pixel clock

#include <Wire.h>
#include <RTClib.h>
#include <Adafruit_NeoPixel.h>

#define PIN 6
#define PIXEL 60

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL, PIN, NEO_GRB + NEO_KHZ800);

RTC_DS1307 RTC; // Establish clock object
DateTime Clock; // Holds current clock time

byte hourval, minuteval, secondval;

void setup() {
  Wire.begin();          // Begin I2C
  RTC.begin();   // begin clock
    if (! RTC.isrunning()) {
//  Serial.println("RTC is NOT running!");
  // following line sets the RTC to the date & time this sketch was compiled

//  RTC.adjust(DateTime(__DATE__, __TIME__));
  strip.show(); // Initialize all pixels to 'off'


sketch for 7 segment
#include <Time.h>        //Time Library
#include <TimeLib.h>
#include <DS1307RTC.h>   //Real Time Clock Library
#include <Wire.h>        //Auxiliary Library for DS1307RTC (Real-Time Clock) - Pins to Arduino UNO: A4 (SDA), A5 (SCL)
#include <DHT.h>         //Temperature and Humidity Library

#define DHTPIN 8         //Sensor DHT11  conected to the pin 8 on Arduino

// Definition of what DHT sensor type you are using
#define DHTTYPE DHT11   // DHT 11
//#define DHTTYPE DHT22   // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)


int clockPin = 13; // Pin 13 of Arduino connected in the pin 11 of 74HC595 (Clock)
int latchPin = 10; // Pin 10 of Arduino connected in the pin 12 of 74HC595 (Latch)
int dataPin = 11; // Pin 11 of Arduino connected in the pin 14 of 74HC595 (Data)

int hora, minuto, temp, umid;
int unidadeHora, unidadeMinuto, dezenaHora, dezenaMinuto;
int unidadeTemp, dezenaTemp, unidadeUmid, dezenaUmid;
unsigned long ti;
int brightness; // Brightness of display (Min=1 / Max=20)
int k;

//Digits Matrix - 0 a 9
byte num[] = {
  B01111110, // Zero
  B00110000, // One
  B01101101, // Two
  B01111001, // Three
  B00110011, // Four
  B01011011, // Five
  B01011111, // Six
  B01110000, // Seven
  B01111111, // Eight
  B01111011, // Nine

void setup() {

  pinMode(latchPin, OUTPUT); // Define the 3 digital pins as output
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);


  setSyncProvider(RTC.get);   // Update the time with data of RTC (Real Time Clock)
  setSyncInterval(300);       // Set the number of seconds between re-sync

  //setTime(hours, minutes, seconds, days, months, years);
  //setTime(15, 05, 00, 13, 02, 2016);
  //RTC.set(now());           // Set the RTC time

  brightness = 15; // Set the brightness of display (Min=1 / Max=20)


error in the

void loop{
a function-definition is not allowed here before '{' token

E:\pixel_clock_with_7_segment\pixel_clock_with_7_segment.ino: In function 'void setup()':

pixel_clock_with_7_segment:86:15: error: a function-definition is not allowed here before '{' token

   void loop() {

E:\pixel_clock_with_7_segment\pixel_clock_with_7_segment.ino: At global scope:

pixel_clock_with_7_segment:257:1: error: expected declaration before '}' token


Can anybody help me in merging the two sketches as I am new to Arduino programming?

  • 2
    you cannot have multiple functions with the same name ... you have two functions named setup() ... change the name of one, or merge them
    – jsotola
    Apr 26 at 4:58
  • 4
    Does this answer your question? How do you combine 2 different sketches together It describes the general principles to follow for combining 2 sketches (which isn't as easy as just copy&pasting everything in one sketch).
    – chrisl
    Apr 26 at 10:23

Browse other questions tagged or ask your own question.