2 wire smart ports

I have been playing around all morning and I hope someone can help. I have been using easy c for a few months now and I am fairly competent at programming.
I have a 2 wire motor connected to motor port one and a digital bumper connected to digital port 1.
I cannot get the bumper to stop the motor. The bumper is working as I confirmed it in the terminal window but it will not stop the motor.
I have made an assumption here; motor port 1 and 10 are controlled with an analog input and as such I cannot control them with the digital input; is this correct.
What is the difference between the 2 wire motor ports and the 3 wire motor ports?

I’m not positive about easy c, but robotc allows you to control the motors on ports 1 and 10 the same as the other ports. Here is some Sudo-code


if (Button is Pressed)
{
  turn motors on
}
else
{
  turn motors off
}

You will have to make sure the motor is getting turned off when the button isn’t pressed or else it will never stop.

Could you post your code?

In EasyC, Go to the View Menu, and make sure Project Explorer Panel is ‘checked’. Then find that panel, look under Block Diagram, find the function that has the error you were talking about, right click it, click Open C File then copy and paste the text from the resulting tab into a reply on this thread.

Thanks!

#include “Main.h”

void main ( void )
{
unsigned char Bumper;

  Bumper = GetDigitalInput ( 1 ) ;
  if ( Bumper == 1 )
  {
        SetMotor ( 1 , 13 ) ; // Forward
  }
  else
  {
        SetMotor ( 1 , 0 ) ; // Stop
  }

}

Need a while loop around that, the code will execute once and then main will exit. You need to keep checking and acting on the switch all the time.

#include “Main.h”

void main ( void )
{
unsigned char Bumper;

  Bumper = GetDigitalInput ( 1 ) ;
  while ( Bumper == 1 )
  {
        if ( Bumper == 1 )
        {
              SetMotor ( 1 , 13 ) ; // Forward
        }
        else
        {
              SetMotor ( 1 , 0 ) ; // Stop
        }
  }

}

I tried that earlier today and again now and still no luck the motor runs non stop and I cannot get it to shut off.

Now I don;t know much about EasyC, but it looks like you only update Bumper once outside of the while loop. You set it equal to the digital input, and then check to see if it is equal to 1. If it is 1 when you enter the while loop, it will always be 1, because you never set it to anything different.

Good catch magicode. It should be:

void main ( void )
{
  unsigned char Bumper; 

  while ( true )
  {
    Bumper = GetDigitalInput ( 1 ) ;
    if ( Bumper == 1 )
    {
      SetMotor ( 1 , 13 ) ; // Forward
    }
    else
    {
      SetMotor ( 1 , 0 ) ; // Stop
    }
  }
}

I figured it out, I was calling for the button to start running but I did not call for it in the while loop, also a second mistake I made after was that I had the while loop (bumper ==1) when it should have been (1)

#include “Main.h”

void main ( void )
{
unsigned int Bumper;

  Bumper = GetDigitalInput ( 1 ) ;
  while ( 1 )
  {
        Bumper = GetDigitalInput ( 1 ) ;
        if ( Bumper == 1 )
        {
              SetMotor ( 1 , 13 ) ; // Forward
        }
        else
        {
              SetMotor ( 1 , 0 ) ; // Stop
        }
  }

}