Flywheel Program

Although the season is over, I still have an assignment due dealing with programs. We use EasyC to program our robots, and I was assigned the task to have the flywheel bump up or down in increments of 5 with a push of a button. I’ve got a pretty solid program, but I’m lost when it comes to making the flywheel speed up with the equation statement. Any help would be appreciated. (60.3 KB)

What is happening? if the robot does nothing, I can’t help without learning easyC. But if the robot is doing what I think it is (shooting up at max acceleration when you hit one button and reversing at max power when you hit the other button) than your while loop needs to wait before doing the loop again, otherwise x will go down/up 5 every loop and each loop is about 1 nanosecond (extreme exaggeration) so x is massive if you even only hold the button down for 1 second… I would suggest a wait statement of at least 50ms or making the x increase/decrease only once per button press. If the flywheel is going absolutely crazy than try what I said and it should be fixed…

I’d also recommend using the change in state of each button. You need to create another variable for each button which stores the last state of that button. Then compare them, and if the button was pressed in the last iteration, don’t do anything. Here’s some pseudocode for that: (I can write it up in RobotC if you are familiar with it)

infinite loop {
  if topButton is pressed and topButtonLast is not pressed
    then do something

  set topButtonLast equal to topButton

Repeat this for each button, and it will work. Make sure that you always update the value of the last button state; I’ve screwed up the whole program by only updating the value if the button wasn’t pressed and is now.