myasir786
Newbie level 6
The following is my Program in Dev C++ for Parallel Port Interfacing to operate the Remote of the Car. Their is an Problem that once i press the button, Car Runs continuously although i leave the button and i have to stop the car by pressing another button. Please tell me how can i alter my Program so that it stops automatically as i leave the button.
//////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include<iostream>
using namespace std;
typedef void _stdcall (*oupfuncPtr)(short portaddr, short datum);
int main()
{
HINSTANCE hLib;
oupfuncPtr out32;
// Load the library
hLib = LoadLibrary("inpout32.dll");
//get the address of the function
out32 = (oupfuncPtr) GetProcAddress(hLib, "Out32");
//code goes here
cout<<"Parallel Port Interfacing"<<endl;
cout<<"Press 8 to forw, 2 to reverse,4 to left,6 to right,1 to forw&left and 3 to forw&right:"<<endl;
int inp;
do
{
inp=getch();
out32(0x378,0x00);
if(inp=='8')//D0 forward
{
cout<<"forward";
out32(0x378,0x01);
}
else if(inp=='2')//D1 reverse
{
cout<<"reverse";
out32(0x378,0x02);
}
else if(inp=='4')//D2 left
{
cout<<"left";
out32(0x378,0x04);
}
else if(inp=='6')//D3 right
{
cout<<"right";
out32(0x378,0x08);
}
else if(inp=='1')//D0&D2 forward&left
{
cout<<"forward and left";
out32(0x378,0x05);
}
else if(inp=='3')//D0&D3 forward&right
{
cout<<"forward and right";
out32(0x378,0x09);
}
}
while(inp=='1'||inp=='2'||inp=='3'||inp=='4'||inp=='6'||inp=='8');
system("pause");
return 0;
}
//////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include<iostream>
using namespace std;
typedef void _stdcall (*oupfuncPtr)(short portaddr, short datum);
int main()
{
HINSTANCE hLib;
oupfuncPtr out32;
// Load the library
hLib = LoadLibrary("inpout32.dll");
//get the address of the function
out32 = (oupfuncPtr) GetProcAddress(hLib, "Out32");
//code goes here
cout<<"Parallel Port Interfacing"<<endl;
cout<<"Press 8 to forw, 2 to reverse,4 to left,6 to right,1 to forw&left and 3 to forw&right:"<<endl;
int inp;
do
{
inp=getch();
out32(0x378,0x00);
if(inp=='8')//D0 forward
{
cout<<"forward";
out32(0x378,0x01);
}
else if(inp=='2')//D1 reverse
{
cout<<"reverse";
out32(0x378,0x02);
}
else if(inp=='4')//D2 left
{
cout<<"left";
out32(0x378,0x04);
}
else if(inp=='6')//D3 right
{
cout<<"right";
out32(0x378,0x08);
}
else if(inp=='1')//D0&D2 forward&left
{
cout<<"forward and left";
out32(0x378,0x05);
}
else if(inp=='3')//D0&D3 forward&right
{
cout<<"forward and right";
out32(0x378,0x09);
}
}
while(inp=='1'||inp=='2'||inp=='3'||inp=='4'||inp=='6'||inp=='8');
system("pause");
return 0;
}