Skip to main content
Removed a critique that was based on a misunderstanding
Source Link
InBedded16
  • 226
  • 1
  • 7

If you have a voltmeter, voltage readings on the pins you're trying to use would be very helpful. Use them to verify you're setting up PWM correctly. Make a new script and add in only very basic code, ie setup the pins and then try to drive the motor using PWM in a single direction for 5 seconds on 5 seconds off. Play around with the PWM values and pay attention to current draw, that could be your issue. Once you get the motor movement working, then you can start integrating it into your main program.

Separate from the motor movements, check the part of your main loop that deals with the limit switch. You keep assigning a new time to your initialMillis variable, so you will only hit that 500ms benchmark if the function you call takes 500ms, which it doesn't. A while loop would fix this. Its unclear what you want the limit switch to do, but right now it doesn't really do anything - momentarily stops the motor and prints out a statement after the delay, but otherwise doesn't prevent you from still moving in the same direction or anything. So take a look at that and figure out what functionality you want. You might have to switch towards watching for the states of the buttons to change rather than if they are currently pressed, that way you can pause and move the other way after a limit switch hit even if the user doesn't let go of the button, which I believe is your intended behavior.

You have "!fastState" in your logic evaluation for the upState move, which means if you try to move UP and FAST you won't move at all. You correctly implemented this for the downState logic so I assume this is a relic from a previous code iteration you forgot to change.

This is pretty small, but why do you subtract zero from your millis() in your if loops? Probably has no adverse effects but adds code density.

If you have a voltmeter, voltage readings on the pins you're trying to use would be very helpful. Use them to verify you're setting up PWM correctly. Make a new script and add in only very basic code, ie setup the pins and then try to drive the motor using PWM in a single direction for 5 seconds on 5 seconds off. Play around with the PWM values and pay attention to current draw, that could be your issue. Once you get the motor movement working, then you can start integrating it into your main program.

Separate from the motor movements, check the part of your main loop that deals with the limit switch. You keep assigning a new time to your initialMillis variable, so you will only hit that 500ms benchmark if the function you call takes 500ms, which it doesn't. A while loop would fix this. Its unclear what you want the limit switch to do, but right now it doesn't really do anything - momentarily stops the motor and prints out a statement after the delay, but otherwise doesn't prevent you from still moving in the same direction or anything. So take a look at that and figure out what functionality you want. You might have to switch towards watching for the states of the buttons to change rather than if they are currently pressed, that way you can pause and move the other way after a limit switch hit even if the user doesn't let go of the button, which I believe is your intended behavior.

You have "!fastState" in your logic evaluation for the upState move, which means if you try to move UP and FAST you won't move at all. You correctly implemented this for the downState logic so I assume this is a relic from a previous code iteration you forgot to change.

This is pretty small, but why do you subtract zero from your millis() in your if loops? Probably has no adverse effects but adds code density.

If you have a voltmeter, voltage readings on the pins you're trying to use would be very helpful. Use them to verify you're setting up PWM correctly. Make a new script and add in only very basic code, ie setup the pins and then try to drive the motor using PWM in a single direction for 5 seconds on 5 seconds off. Play around with the PWM values and pay attention to current draw, that could be your issue. Once you get the motor movement working, then you can start integrating it into your main program.

Separate from the motor movements, check the part of your main loop that deals with the limit switch. You keep assigning a new time to your initialMillis variable, so you will only hit that 500ms benchmark if the function you call takes 500ms, which it doesn't. A while loop would fix this. Its unclear what you want the limit switch to do, but right now it doesn't really do anything - momentarily stops the motor and prints out a statement after the delay, but otherwise doesn't prevent you from still moving in the same direction or anything. So take a look at that and figure out what functionality you want. You might have to switch towards watching for the states of the buttons to change rather than if they are currently pressed, that way you can pause and move the other way after a limit switch hit even if the user doesn't let go of the button, which I believe is your intended behavior.

You have "!fastState" in your logic evaluation for the upState move, which means if you try to move UP and FAST you won't move at all. You correctly implemented this for the downState logic so I assume this is a relic from a previous code iteration you forgot to change.

added 434 characters in body
Source Link
InBedded16
  • 226
  • 1
  • 7

If you have a voltmeter, voltage readings on the pins you're trying to use would be very helpful. Use them to verify you're setting up PWM correctly. Make a new script and add in only very basic code, ie setup the pins and then try to drive the motor using PWM in a single direction for 5 seconds on 5 seconds off. Play around with the PWM values and pay attention to current draw, that could be your issue. Once you get the motor movement working, then you can start integrating it into your main program.

Separate from the motor movements, check the part of your main loop that deals with the limit switch. You keep assigning a new time to your initialMillis variable, so you will only hit that 500ms benchmark if the function you call takes 500ms, which it doesn't. A while loop would fix this. Its unclear what you want the limit switch to do, but right now it doesn't really do anything - momentarily stops the motor and prints out a statement after the delay, but otherwise doesn't prevent you from still moving in the same direction or anything. So take a look at that and figure out what functionality you want. You might have to switch towards watching for the states of the buttons to change rather than if they are currently pressed, that way you can pause and move the other way after a limit switch hit even if the user doesn't let go of the button, which I believe is your intended behavior.

You have "!fastState" in your logic evaluation for the upState move, which means if you try to move UP and FAST you won't move at all. You correctly implemented this for the downState logic so I assume this is a relic from a previous code iteration you forgot to change.

This is pretty small, but why do you subtract zero from your millis() in your if loops? Probably has no adverse effects but adds code density.

If you have a voltmeter, voltage readings on the pins you're trying to use would be very helpful. Use them to verify you're setting up PWM correctly. Make a new script and add in only very basic code, ie setup the pins and then try to drive the motor using PWM in a single direction for 5 seconds on 5 seconds off. Play around with the PWM values and pay attention to current draw, that could be your issue. Once you get the motor movement working, then you can start integrating it into your main program.

Separate from the motor movements, check the part of your main loop that deals with the limit switch. You keep assigning a new time to your initialMillis variable, so you will only hit that 500ms benchmark if the function you call takes 500ms, which it doesn't. A while loop would fix this. Its unclear what you want the limit switch to do, but right now it doesn't really do anything - momentarily stops the motor and prints out a statement after the delay, but otherwise doesn't prevent you from still moving in the same direction or anything. So take a look at that and figure out what functionality you want.

You have "!fastState" in your logic evaluation for the upState move, which means if you try to move UP and FAST you won't move at all. You correctly implemented this for the downState logic so I assume this is a relic from a previous code iteration you forgot to change.

If you have a voltmeter, voltage readings on the pins you're trying to use would be very helpful. Use them to verify you're setting up PWM correctly. Make a new script and add in only very basic code, ie setup the pins and then try to drive the motor using PWM in a single direction for 5 seconds on 5 seconds off. Play around with the PWM values and pay attention to current draw, that could be your issue. Once you get the motor movement working, then you can start integrating it into your main program.

Separate from the motor movements, check the part of your main loop that deals with the limit switch. You keep assigning a new time to your initialMillis variable, so you will only hit that 500ms benchmark if the function you call takes 500ms, which it doesn't. A while loop would fix this. Its unclear what you want the limit switch to do, but right now it doesn't really do anything - momentarily stops the motor and prints out a statement after the delay, but otherwise doesn't prevent you from still moving in the same direction or anything. So take a look at that and figure out what functionality you want. You might have to switch towards watching for the states of the buttons to change rather than if they are currently pressed, that way you can pause and move the other way after a limit switch hit even if the user doesn't let go of the button, which I believe is your intended behavior.

You have "!fastState" in your logic evaluation for the upState move, which means if you try to move UP and FAST you won't move at all. You correctly implemented this for the downState logic so I assume this is a relic from a previous code iteration you forgot to change.

This is pretty small, but why do you subtract zero from your millis() in your if loops? Probably has no adverse effects but adds code density.

added 596 characters in body
Source Link
InBedded16
  • 226
  • 1
  • 7

If you have a voltmeter, voltage readings on the pins you're trying to use would be very helpful. Use them to verify you're setting up PWM correctly. Make a new script and add in only very basic code, ie setup the pins and then try to drive the motor using PWM in a single direction for 5 seconds on 5 seconds off. Play around with the PWM values and pay attention to current draw, that could be your issue. Once you get the motor movement working, then you can start integrating it into your main program.

Separate from the motor movements, check the part of your main loop that deals with the limit switch. You keep assigning a new time to your initialMillis variable, so you will only hit that 500ms benchmark if the function you call takes 500ms, which it doesn't. A while loop would fix this. Its unclear what you want the limit switch to do, but right now it doesn't really do anything - momentarily stops the motor and prints out a statement after the delay, but otherwise doesn't prevent you from still moving in the same direction or anything. So take a look at that and figure out what functionality you want.

You have "!fastState" in your logic evaluation for the upState move, which means if you try to move UP and FAST you won't move at all. You correctly implemented this for the downState logic so I assume this is a relic from a previous code iteration you forgot to change.

If you have a voltmeter, voltage readings on the pins you're trying to use would be very helpful. Use them to verify you're setting up PWM correctly. Make a new script and add in only very basic code, ie setup the pins and then try to drive the motor using PWM in a single direction for 5 seconds on 5 seconds off. Play around with the PWM values and pay attention to current draw, that could be your issue. Once you get the motor movement working, then you can start integrating it into your main program.

Separate from the motor movements, check the part of your main loop that deals with the limit switch. You keep assigning a new time to your initialMillis variable, so you will only hit that 500ms benchmark if the function you call takes 500ms, which it doesn't. A while loop would fix this.

If you have a voltmeter, voltage readings on the pins you're trying to use would be very helpful. Use them to verify you're setting up PWM correctly. Make a new script and add in only very basic code, ie setup the pins and then try to drive the motor using PWM in a single direction for 5 seconds on 5 seconds off. Play around with the PWM values and pay attention to current draw, that could be your issue. Once you get the motor movement working, then you can start integrating it into your main program.

Separate from the motor movements, check the part of your main loop that deals with the limit switch. You keep assigning a new time to your initialMillis variable, so you will only hit that 500ms benchmark if the function you call takes 500ms, which it doesn't. A while loop would fix this. Its unclear what you want the limit switch to do, but right now it doesn't really do anything - momentarily stops the motor and prints out a statement after the delay, but otherwise doesn't prevent you from still moving in the same direction or anything. So take a look at that and figure out what functionality you want.

You have "!fastState" in your logic evaluation for the upState move, which means if you try to move UP and FAST you won't move at all. You correctly implemented this for the downState logic so I assume this is a relic from a previous code iteration you forgot to change.

Source Link
InBedded16
  • 226
  • 1
  • 7
Loading