//This example code shows how to switch a LED on/off in Visual C++.
//We use two variables N and L explained below.
//I am assuming you have some knowledge in C++. Instruction to connect the LED is given in the Tutorial.
#include <iostream.h> //The most important include to display data on screen.
#include <conio.h> //Include for outp and inp functions for the printer port.
#include <windows.h> //For _sleep functions for our time delay.
#define addr 0x3BC //IMPORTANT: Normaly 378 is the most common address,
//if not then insert your address instead of 378
int main()
{
int freq; //Variable for time delay.
int L; //Variable for counts of Blinking LED.
cout<<"\t\t XheavenlyX WELCOMES YOU!!! \n\n"; //How can I forget this
cout<<"How many times to blink?? Enter 0 to exit: "; //Ask user how many times to blink the LED
cin>>L; //And exit if zero is entered.
if (L==0)
{
cout<<endl<<"Exiting application..."<<endl; //Code to exit if L = 0.
for (int i=0;i<=5;i++) {_sleep(500);} //A lame pause before exit!
exit(0);
}
cout<<"Frequency (in mS): "; //Ask user to enter the frequency at which the LED will blink.
cin>>freq; //Store that value in freq.
//Bottom code is the Juice! This will blink your LED the number of times you put in L.
//The speed of blinks will depend on freq. As an example if you entered 500milliseconds. The LED
//will blink twice every second since 500ms is half of 1000ms (1000millisecondss = 1sec)
for (int i=1;i<=L;i++) //The loop. L times to blink.
{
_outp(addr,1); //Output is high in the first 'Data bit' of port(*), i.e Pin number 2 where you have connected the LED.
_sleep(freq); //freq mS delay between the high and low of LED.
_outp(addr,0); //Output is low now
_sleep(freq); //Pause again between the high,
}
return 0; //main returns nothing to you.

} // For an indepth look at
//(*)NOTE: There are some simple calculations to turn on/off the other PINs on the printer port.
//links
//
http://msdn2.microsoft.com/en-us/library/733szwah.aspx _outp, _inp etc.
This post has been edited by mese2000: 31 May, 2008 - 10:34 PM