/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / STM32 PRIMER 2. LEDS AND BUTTONS. WITHOUT CIRCLE OS.

Username:     
Password:     
             

Forum

# 1   2012-01-23 18:41:51 STM32 PRIMER 2. LEDS AND BUTTONS. WITHOUT CIRCLE OS.

Gediminas
New member
Registered: 2011-12-15
Posts: 1

STM32 PRIMER 2. LEDS AND BUTTONS. WITHOUT CIRCLE OS.

Hello, I am modifying Ride 7 ''Toggle" example program which works without circle OS. I want that this program should work like this:
When no buttons pressed: LEDs just blinking.
When button pressed (main or one of joystick): Stop blinking. LEDs are ON.

Now I have a situation then LEDs stops blinking only then main buttton is pressed. When I  press joystick button (left for example) - LED's still blinking.

Any suggestions?

Main part of code:


while ( 1 )
    {
       
        do
        {
            bpinput = (( GPIO_ReadInputData( BP_GPIO ) ) & ( BP_PIN ) );
            if ( bpinput )
                GPIO_Write( LEDS_GPIO, ( 1 & LEDS_BOTH_PINS ) );
        }
        while ( bpinput );

   
        jstkinput = ( (GPIO_ReadInputData(JSTK_GPIO)) & ( JSTK_ALL_PINS ) );
        jstkinput = (( u16 )JSTK_GPIO->IDR ) & ( JSTK_ALL_PINS );

        switch ( jstkinput & ( JSTK_ALL_PINS ) )
        {
        case GPIO_Pin_3:
               GPIO_Write( LEDS_GPIO, ( 1 & LEDS_BOTH_PINS ) );
            break;

        case GPIO_Pin_4:
           GPIO_Write( LEDS_GPIO, ( 1 & LEDS_BOTH_PINS ) );
            break;

        case GPIO_Pin_5:
           GPIO_Write( LEDS_GPIO, ( 1 & LEDS_BOTH_PINS ) );
            break;

        case GPIO_Pin_6:
          GPIO_Write( LEDS_GPIO, ( 1 & LEDS_BOTH_PINS ) );
            break;

        default :
            //no buttons are pressed
            //just go on toggling
            break;
        }

        // Toggle LEDs
        GPIO_Write( LEDS_GPIO, ( toggle & LEDS_BOTH_PINS ) );

        // increment Toggle variable
        toggle++;

        // Insert delay
        Delay( delayvar );

    }
}

Offline

 

# 2   2012-01-25 07:13:57 STM32 PRIMER 2. LEDS AND BUTTONS. WITHOUT CIRCLE OS.

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: STM32 PRIMER 2. LEDS AND BUTTONS. WITHOUT CIRCLE OS.

The instruction :
      // Toggle LEDs
        GPIO_Write( LEDS_GPIO, ( toggle & LEDS_BOTH_PINS ) );

is always called, whatever the joystick is pushed or not.
It should be better to move this code in the default section of your switch.

Offline

 

Board footer