Old Code Example (Help needed)

I am currently learning about hysteresis controllers, or as it was called last year “Bang Bang Code”. I’ve been searching on the Forums for awhile and I’ve been unable to find any direct code that people have used for Bang Bang Code. Can someone please give a copy of their code from last year that contains Bang Bang because I’m trying to understand how it works and how it is displayed in code.

In its simplest form, bang bang is one if statement.
If error >0, motor = 100%
Else, motor = 0

@TurboTech I’d generally represent it as 2


statements though…

if(current < target)
  motor = 127;
else if(current > target)
  motor = -127;
  motor = 0;




represent the current and targeted positions, respectively, of a mechanism (as measured by a potentiometer, encoder, etc.); the motor speeds do not necessarily have to be 100% (±127)

So It’s called bang bang because there are short bursts of power, effectively making each of the oscillations a “bang”?

Yes, of course, I was just speaking in terms of flywheel code where you would never switch motor directions…