Skip to main content
TVan.4
Associate
August 14, 2018
Question

How do I program a button to increase counter?

  • August 14, 2018
  • 2 replies
  • 1356 views

This is my first project using STM32 and one of my first coding in general. I'm attempting to make a user interface GUI using a STT7735 shield LCD. I've been able to get the menus to function properly; however I'm attempting to use the left and right functions of the joystick to increase a counter from 1-22. I'm having no luck with it whatsoever.

 /* Wait for JOY_DOWN or JOY_UP is pressed */
 tmp = JOY_RIGHT;
 while ((tmp != JOY_DOWN) && (tmp != JOY_UP))
 {
 tmp = BSP_JOY_GetState();
 }
 
 /* LCD Clear */
 BSP_LCD_Clear(LCD_COLOR_WHITE);
 
 /* JOY_UP is pressed: Display Manual mode menu #############################*/
 if(tmp == JOY_UP)
 {
 /* Set Text color */
 BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
 /* Display message */
 BSP_LCD_DisplayStringAtLine(3, (uint8_t*)" Channel ");
 BSP_LCD_DisplayStringAtLine(5, (uint8_t*)" Select:");
 sprintf(channel, "%d", x);
 BSP_LCD_DisplayStringAtLine(6, (uint8_t*) &channel);
 
 
 /* Set Text color */
 BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
 /* Display message */
 BSP_LCD_DisplayStringAtLine(8, (uint8_t*)" RIGHT: Next");
 BSP_LCD_DisplayStringAtLine(9, (uint8_t*)" LEFT : Previous ");
 BSP_LCD_DisplayStringAtLine(10, (uint8_t*)" SEL : Select ");
 BSP_LCD_DisplayStringAtLine(11, (uint8_t*)" Down : Back");
 
 tmp = JOY_UP;
 	while ((tmp != JOY_DOWN) && (tmp !=JOY_RIGHT) && (tmp != JOY_SEL) && (tmp !=JOY_LEFT) ){
 		tmp= BSP_JOY_GetState();
 	}
 	if(tmp == JOY_DOWN){
 		TFT_DisplayMain();
 	}
 	if(tmp == JOY_RIGHT){
 		for(x=1;x<23;x++){
 			x=x+1;
 
 		}
 	}
 		if(tmp == JOY_LEFT){
 		// Opposite direction of Right code. Still need to figure that out.
 
 	}
 	if(tmp == JOY_SEL){
 		//Write selection to home page and register
 		TFT_DisplayMain();
 	}
 		}
int x=1;
int y=1;
 
char channel[7];
char code[5];

I'm attempting to use a for loop to use as an increase and I've tried with using pointers, but something tells me I'm missing a rather small detail.

    This topic has been closed for replies.

    2 replies

    Tesla DeLorean
    Guru
    August 14, 2018

    The for loops doesn't do anything useful.

    Consider

    if(tmp == JOY_RIGHT){

    x++;

    if (x > 22) x = 1;

    }

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    TVan.4
    TVan.4Author
    Associate
    August 14, 2018

    I'll give that a shot. Thanks!