cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, Iam making my project and I have problem with one operating step. i have tm1637 controlled display and rotary controller with button. I have problem with enabling and disnebaling rotary encoder rotations where I need . STM32F446RE

TPoup.1
Associate II

I have as simple MENU where I am switching with rotating of rotary encoder between items. If I choose item which I want I can press the button and it open subitem for the item. in open subitem I have stopped rotating of encoder. Because if I was in subitem and rotate with encoder it goes to antoher subitem and than I dont want. But I have firt subitem where I need to control dac output with rotating of encoder so in this subitem I must have to start rotary encoder rotation but if I rotate there is swap me to another subitem and this I dont want.

can someine please help me how to enable encoder rotation but it will just control my dac and it dont swap to other supitems?

there is my code:

void (*menuFunc[NUM_MENU_ITEMS])(void) = {MOTR, TEP1, TEP2, TEP3, FLTR};

void (*openMenuFunc[NUM_MENU_ITEMS])(void) = {openMOTR, openTEP1, openTEP2, openTEP3, openFLTR};

uint8_t selectedItem = 0;

int16_t prevEncoderValue = 0;

int16_t encoderSteps = 0;

uint8_t countPress = 0;

uint8_t statePress = 0;

uint8_t EncBlock = 1;

void RotaryEncoder_Read(void)

{

int16_t encoderValue = __HAL_TIM_GET_COUNTER(&htim2);

if (encoderValue != prevEncoderValue)

{

if (encoderValue > prevEncoderValue)

encoderSteps++;

else

encoderSteps--;

if (encoderSteps == ENCODER_STEPS_PER_ITEM)

{

selectedItem = (selectedItem + 1) % NUM_MENU_ITEMS;

encoderSteps = 0;

} else if (encoderSteps == -ENCODER_STEPS_PER_ITEM)

{

selectedItem = (selectedItem + NUM_MENU_ITEMS - 1) % NUM_MENU_ITEMS;

encoderSteps = 0;

}

prevEncoderValue = encoderValue;

}

if(!(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_8) == 1))

{

HAL_Delay(100);

if(!(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_8) == 1))

{

BZZZ();

statePress = !statePress;

}

}

countPress = (countPress + statePress)%2;

if (statePress == 0)

{

HAL_TIM_Encoder_Start(&htim2, TIM_CHANNEL_ALL);

HAL_Delay(25);

menuFunc[selectedItem]();

}

else

{

if (selectedItem > 0)

{

HAL_TIM_Encoder_Stop(&htim2, TIM_CHANNEL_ALL);

HAL_Delay(25);

openMenuFunc[selectedItem]();

} else

{

HAL_Delay(25);

openMenuFunc[selectedItem]();

}

}

}

2 REPLIES 2
AScha.3
Chief III

my opinion: wrong question. 

the better question would be: how do i create a menu structure with submenu items?

my suggestion: a variable for the menu level

so: start : menulevel=0 ; when selecting a menu item , set menulevel=1;

now rotation can +/- change other value or go to next level of menu items +set menulevel=2 ;

If you feel a post has answered your question, please click "Accept as Solution".
TPoup.1
Associate II

this is not solution for me bcs I need to use encoder rotating eg in sub_Item_1, but in sub_Item_2 a dont need to use encoder.