Programming Problems on tank mode 2 and tank mode 4

Hi,currently i am doing a programming. When i using “23mode”, the motor runs in 4-wheel drive mode instead of 2-wheel drive mode.And when i put a jumper to “Digital/Input port 15” , the motor can still run in 4-wheel drive mode.

Problems: How can i program the robot in order when using “23 mode”, the motors will run in 2-wheel drive mode and when i put a jumper to “port 15”, it will automatically change to 4-wheel drive mode?

Please kindly help… Thanks alot…
tank.txt (265 Bytes)

Try moving the “GetDigitalInput” from outside the main loop to inside it. Right now it looks like the program checks the port and then goes into a steady loop that doesn’t check it anymore.

In other words, change it FROM THIS:

#include “Main.h”
void main (void)
{
	int input;
	
	input=GetDigitalInput(15);
	while(1==1)
	{
		if (input ==1)
		{
			Tank2(0,3,2,3,2,0,0);
		}
		else if (input == 0)
		{
			input = GetDigitalInput(15);
			Tank4 (0,3,2,3,2,7,8,0,0,0,0)
		}
	}
}

TO THIS:


#include “Main.h”
void main (void)
{
	int input;
	
	while(1==1)
	{
	        input=GetDigitalInput(15);
		if (input ==1)
		{
			Tank2(0,3,2,3,2,0,0);
		}
		else if (input == 0)
		{
			input = GetDigitalInput(15);
			Tank4 (0,3,2,3,2,7,8,0,0,0,0)
		}
	}
}

And just for ‘Clean Code’s’ sake, try this.


#include “Main.h”
void main (void)
{
	int input ;
	
	while( 1 ) //Same as 1 == 1
	{
	        input = GetDigitalInput( 15 ) ;
		if ( input == 1 )
		{
			Tank2( 0,3,2,3,2,0,0 ) ;
		}
		else if ( input != 1 ) // != means, not equal. You could even remove the else if and make it an else
		{
			input = GetDigitalInput( 15 ) ;
			Tank4 (0,3,2,3,2,7,8,0,0,0,0) **;** //was missing a ; before
		}
	}
}

Hi, regarding for yr programming, i have give it a try. But the problem still the same. The problem is when using “23 mode” , the motor will automatically change to 4-wheel drive mode without putting any jumper on it.

How can i do a program when using “23 mode”, the motors will run in “2-wheel drive”, and when i put a jumper on Port 15, it will auotmatically change to 4-wheel drive mode?

This is the problem that i have done:

#include “Main.h”

void main(void)
{
int input;
while (1==1)
{
input=GetDigitalInput(15);
if (input==1)
{
Tank2(0,3,2,3,2,0,0);
}
else if (input !=1)
{
input=GetDigitalInput(15);
Tank4 (0,3,2,3,2,7,8,0,0,0,0,);
}

Kindly Please give me some advise… Thank You…

This code can be made more effecent, but it should work correctly…

Can you tell us how you are testing your code and what you consider a pass and what is a fail??

This is EasyC 2.x??? What happens if you place the Jumper on Input 15?? Does it change to Tank2???

In your controller configuration, is digital/analog port 15 set to be a digital input or not?

Good Catch!!

I wonder if shimin1986 can include their Whole EasyC Project…

Hi, i have already solve this problem… Thanks for the advise you have given me… mainly the problem is that i did not set controller configuration to digital 15.
Thanks alot