There is a problem with the modified part of the program, I don't know how to solve that part

C:\Users\USER\Documents\Arduino\4_digit\4_digit.ino: In function 'void setup()':

4_digit:32:13: error: a function-definition is not allowed here before '{' token

void loop() {

         ^

4_digit:99:1: error: expected '}' at end of input

}//loop

^

exit status 1

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

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I'm still a beginner and still learning, please help. thank you

#include <TM1637Display.h> // include TM163 library
 
#define CLK   2  // define TM1637 clock pin
#define DIO   3  // define TM1637 data pin
 
#define UP    4  // define up button pin
#define DN    5  // define down button pin
#define RST   6  // define reset button pin
 
// Create a display object of type TM1637Display
TM1637Display display = TM1637Display(CLK, DIO);

int num = 0, prev_num = 1;

byte
    last_up,last_dn, last_rst;
    
void setup() {
    // initialize the TM1637 display
    init();
    // set display brightness (from 0 to 7)
    (4);
 
    pinMode(UP, INPUT);
    last_up = digitalRead( UP );
    pinMode(DN, INPUT);
    last_dn = digitalRead( DN );
    pinMode(RST, INPUT);
    last_rst = digitalRead( RST );
 
//main loop
void loop() {
    static unsigned long
        timeButton=0;
    unsigned long
        timeNow;
    byte
        button;
         
    //read the buttons every 50mS
    timeNow = millis();
    if( timeNow - timeButton >= 50ul )
    {
        timeButton = timeNow;

        button = digitalRead( UP );
        if( button != last_up )
        {
            last_up = button;
            if( button == HIGH )
            {
                num++;         // increment 'num'
                if(num > 1000)
                    num = 0;
                
            }//if
            
        }//if
    
        button = digitalRead( DN );
        if( button != last_dn )
        {
            last_dn = button;
            if( button == HIGH )
            {
                num--;         // increment 'num'
                if(num < 0)
                    num = 1000;
                
            }//if
            
        }//if

        button = digitalRead( RST );
        if( button != last_rst )
        {
            last_rst = button;
            if( button == HIGH )
            {
                num = 0;
            }//if
        }//if

        if(num != prev_num)
        {  
            // if the displayed (current) number was changed
            prev_num = num;   // save current value of 'num'
            // print all data
            tm1637.display(0, num/1000);     // print thousands digit
            tm1637.display(1, num/100 % 10); // print hundreds digit
            tm1637.display(2, num/10 % 10);  // print tens digit
            tm1637.display(3, num% 10);      // print ones digit
     
            //delay(200);  // wait 200 milliseconds
        }//if

    }//if
         
}//loop

make sure you indented the code in the IDE, that's done by pressing ctrlT on a PC or cmdT on a Mac) and you'll see you are missing the closing } for the setup() function


what's this for ?


how do you think this will help initialize your display?

have you looked at examples from the TM1637Display class? (we don't really know which library you are using)

Looks like the '}' at the end of setup() is missing. To the compiler it looks like you are defining 'loop()' inside 'setup()' and that is not allowed.

thanks

you had that in answer #2

but I guess you did not care about indenting nor getting rid of useless code...

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