Skip to content

Commit

Permalink
Example for PB10 and PB11 as buttons.
Browse files Browse the repository at this point in the history
by Rok Rodic, www.rodic.si
  • Loading branch information
rokrodic authored Jun 6, 2018
1 parent ff1578b commit f28a717
Showing 1 changed file with 36 additions and 12 deletions.
48 changes: 36 additions & 12 deletions Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ int cmd2;
int cmd3;

uint8_t button1, button2;
#ifdef RIGHT_BUTTONS
uint8_t button3, button4;
#endif

int steer; // global variable for steering. -1000 to 1000
int speed; // global variable for speed. -1000 to 1000
Expand Down Expand Up @@ -187,7 +190,6 @@ int main(void) {
speedR = CLAMP(speed * SPEED_COEFFICIENT - steer * STEER_COEFFICIENT, -1000, 1000);
speedL = CLAMP(speed * SPEED_COEFFICIENT + steer * STEER_COEFFICIENT, -1000, 1000);


// ####### DEBUG SERIAL OUT #######
#ifdef CONTROL_ADC
setScopeChannel(0, (int)adc_buffer.l_tx2); // ADC1
Expand All @@ -200,19 +202,41 @@ int main(void) {
ADDITIONAL_CODE;
#endif

// ####### SET OUTPUTS #######
if ((speedL < lastSpeedL + 50 && speedL > lastSpeedL - 50) && (speedR < lastSpeedR + 50 && speedR > lastSpeedR - 50) && timeout < TIMEOUT) {
#ifdef INVERT_R_DIRECTION
pwmr = speedR;
#else
pwmr = -speedR;
// ####### EXAMPLE CASE FOR BUTTONS ON PB10 & PB11 #######
#ifdef RIGHT_BUTTONS
if (button3) {
} else {
}
if ((speedL < lastSpeedL + 50 && speedL > lastSpeedL - 50) && (speedR < lastSpeedR + 50 && speedR > lastSpeedR - 50) && timeout < TIMEOUT) {
if (button4) {
LEFT_TIM->BDTR &= ~TIM_BDTR_MOE; //disable left
RIGHT_TIM->BDTR |= TIM_BDTR_MOE; //enable right
pwml = 0; //pwml = -speedL;
pwmr = speedR;
} else {
LEFT_TIM->BDTR |= TIM_BDTR_MOE; //enable left
RIGHT_TIM->BDTR |= TIM_BDTR_MOE; //enable right
pwml = -speedL;
pwmr = speedR;
}
}
#endif
#ifdef INVERT_L_DIRECTION
pwml = -speedL;
#else
pwml = speedL;

// ####### SET OUTPUTS #######
#ifndef RIGHT_BUTTONS
if ((speedL < lastSpeedL + 50 && speedL > lastSpeedL - 50) && (speedR < lastSpeedR + 50 && speedR > lastSpeedR - 50) && timeout < TIMEOUT) {
#ifdef INVERT_R_DIRECTION
pwmr = speedR;
#else
pwmr = -speedR;
#endif
#ifdef INVERT_L_DIRECTION
pwml = -speedL;
#else
pwml = speedL;
#endif
}
#endif
}

lastSpeedL = speedL;
lastSpeedR = speedR;
Expand Down

3 comments on commit f28a717

@linkmaker24
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi rocrodik can you help me on how to connect analog joystick directly to the mainboard? At the left sensor?

@linkmaker24
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to connect analog joystick to mainboad to control forward, backwards and tank mode. Thanks

@floyd1010
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sir ..pb10 and pb11 ...that pin are scl and scda...but this cose doesnt work ..i dont why.

Please sign in to comment.