M. Mahdi K. Kanan
Published © GPL3+

Control Your Robot With Your Phone

This article is about building a WiFi controllable robot. To making this robot, I've used the discarded stuff, old parts and a "WiCard."

BeginnerProtip1 hour358

Things used in this project

Hardware components

DC motor (generic)
×1
Li-Ion Battery 1000mAh
Li-Ion Battery 1000mAh
×1
WiCard WiFi Module
×1

Story

Read more

Code

WiFi Controllable Code

C/C++
Here's the code
mucSlider_0_Off = 255;
mucSlider_0_On = 0;
mbToggle_4 = 0;
mbToggle_3 = 0;
mbToggle_2 = 0;
mbToggle_1 = 0;
mbToggle_0 = 0;

main()
{
	//22: Left motor
	//11: Right motor
	//13,15: Reverse battery polarity
	SetPinsAsOutput(0x40a800);
	ControlBoxHandler();
}

ControlBoxHandler()
{
	//Acceleration time
	uiI = 1000000; //uS
	uiI *= mucSlider_0_On;
	uiI += 1000000;
	
	if(mbToggle_4 == 0)
	{
		//Forward
		if(mbToggle_0)
		{
			//Accelerate
			ClearPortLatch(0xA000);
			SetPortLatch(0x400800);
			SetTimerCounter(uiI);
		}
		else if(mbToggle_1)
		{
			//Right
			ClearPortLatch(0xA800);
			SetPortLatch(0x400000);
			SetTimerCounter(uiI);
		}
		else if(mbToggle_2)
		{
			//Left
			ClearPortLatch(0x40A000);
			SetPortLatch(0x800);
			SetTimerCounter(uiI);
		}
		else if(mbToggle_3)
		{
			//Reverse for 1 second
			SetPortLatch(0x40A800);
			SetTimerCounter(1000000);
		}
		else
		{
			//Turning off
			ClearPortLatch(0x40A800);
		}
	}
	else
	{
		//Reverse
		if(mbToggle_0)
		{
			//Accelerate
			SetPortLatch(0x40A800);
			SetTimerCounter(uiI);
		}
		else if(mbToggle_1)
		{
			//Right
			ClearPortLatch(0x800);
			SetPortLatch(0x40A000);
			SetTimerCounter(uiI);
		}
		else if(mbToggle_2)
		{
			//Left
			ClearPortLatch(0x400000);
			SetPortLatch(0xA800);
			SetTimerCounter(uiI);
		}
		else if(mbToggle_3)
		{
			//Forward for 1 second
			ClearPortLatch(0xA000);
			SetPortLatch(0x400800);
			SetTimerCounter(1000000);
		}
		else
		{
			//Turning off
			ClearPortLatch(0x40A800);
		}
	}

	IgnoreSave();
}

TimerIntHandler()
{
	//Turning off
	ClearPortLatch(0x40A800);
}

PCIntHandler()
{
	ClearPCIntRaisingFlag(0xFFFFFFFF);
	ClearPCIntFallingFlag(0xFFFFFFFF);
}

SSMIntHandler()
{
}

Credits

M. Mahdi K. Kanan

M. Mahdi K. Kanan

12 projects • 4 followers
M. Mahdi K. Kanan is the manager of WiCardTech design group.

Comments