Skip to main content
ksale.1
Senior II
November 21, 2025
Solved

counter will not increment beyond 9 and does not show negative numbers. Designer 4.26.0

  • November 21, 2025
  • 2 replies
  • 172 views

I was following the tutorial in the link:  

https://www.youtube.com/watch?v=vy1c1LbypuM&list=PLfIJKC1ud8giOsk-C4BCOwSHtbXqTNb1W&index=3 

I couldn't gett the upclick to count greater than 9 and below 0. the screenView.hpp and cpp as follows:                       

hpp:

#ifndef SCREEN1VIEW_HPP
#define SCREEN1VIEW_HPP

#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>
#include <gui/screen1_screen/Screen1Presenter.hpp>

class Screen1View : public Screen1ViewBase
{
public:
 Screen1View();
 virtual ~Screen1View() {}
 virtual void setupScreen();
 virtual void tearDownScreen();

 virtual void downclicked();
 virtual void upclicked();

 

protected:

 uint16_t counter = 0;
};

#endif // SCREEN1VIEW_HPP


cpp:


#include <gui/screen1_screen/Screen1View.hpp>

Screen1View::Screen1View()
{

}

void Screen1View::setupScreen()
{
 Screen1ViewBase::setupScreen();
}

void Screen1View::tearDownScreen()
{
 Screen1ViewBase::tearDownScreen();
}

void downclicked(){
	counter--;
	Unicode::snprintf(textArea1Buffer, TEXTAREA1_SIZE, "%u", counter);
	textArea1.invalidate();
}

void upclicked(){
	counter++;
	Unicode::snprintf(textArea1Buffer, TEXTAREA1_SIZE, "%u", counter);
	textArea1.invalidate();
}
Thank you in advance for your help
    Best answer by Peter BENSCH

    Well, what is the value of TEXTAREA1_SIZE?
    Because if it only covers one digit, you will inevitably only see the ones digit.

    And how do you intend to obtain negative numbers if you define the counter as uint16_t?

    Regards
    /Peter

     

    2 replies

    Peter BENSCH
    Peter BENSCHBest answer
    ST Technical Moderator
    November 21, 2025

    Well, what is the value of TEXTAREA1_SIZE?
    Because if it only covers one digit, you will inevitably only see the ones digit.

    And how do you intend to obtain negative numbers if you define the counter as uint16_t?

    Regards
    /Peter

     

    In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
    ksale.1
    ksale.1Author
    Senior II
    November 22, 2025

    Thank you Peter, unchecking AutoSize does the trick, and of course the unsigned is a mistake.