/* Some C code to make patterns on LEDs on a PC parallel port using Linux. FYI: This was done YEARS ago. Take, use, make, give credit. Copyright 2008: myBitBox.com, geeksinside.com */ #include #include #include void running(); void blinking(); void pauseit(); void bounce(); void choose(); void cool(); void snake(); void main(){ int x,num,endloop=0; ioperm(0x378,3,1); while (endloop==0){ cout<<"\n\n\n========================\n"; cout<<"Parallel Port Light Menu\n"; cout<<"========================\n"; cout<<"1) Running Lights\n"; cout<<"2) Blinking Lights\n"; cout<<"3) Bouncing Lights\n"; cout<<"4) Open & Close\n"; cout<<"5) Snake Lights\n"; cout<<"6) Output Binary Number\n\n"; cout<<"7) Quit\n\n"; cout<<"========================\n"; cout<<"Please make a selection:"; cin>>num; if(num<7) cout<<"\n\nRunning...\n\n"; if(num==1) running(); else if(num==2) blinking(); else if(num==3) bounce(); else if(num==4) for(x=1;x<=4;x++) cool(); else if(num==5) snake(); else if(num==6) choose(); else{ cout<<"\n\nThank you! Drink Coke, Play Again!\n\n"; endloop=1; } if(num<7) cout<<"\n\nDone!\n\n"; outb(0, 0x378); } void snake(){ int x,y,z; for(z=1;z<=2;z++){ y=0; for (x=1;x<=128;x=x*2){ y=y+x; outb(y,0x378); pauseit(); } for (x=1;x<=128;x=x*2){ y=y-x; outb(y,0x378); pauseit(); } outb(0,0x378); y=0; for (x=128;x>=1;x=x/2){ y=y+x; outb(y,0x378); pauseit(); } for (x=128;x>=1;x=x/2){ y=y-x; outb(y,0x378); pauseit(); } outb(0,0x378); } } void cool(){ int x,y,z,w; y=1,z=128,w=0; for(x=1;x<=4;x++){ w=(y+z+w); outb(w, 0x378); pauseit(); y=y*2; z=z/2; } outb(255,0x378); pauseit(); y=16,z=8,w=255; for(x=1;x<=4;x++){ w=(w-(y+z)); outb(w, 0x378); pauseit(); y=y*2; z=z/2; } } void choose(){ int x; do { x=0; cout<<"Please input the number you would like to see in lights(-1 to exit):"; cin>>x; if(x!=-1) outb(x, 0x378); } while (x!=-1); } void bounce(){ int x,y,z; for(z=1;z<=3;z++){ for (x=1;x<=128;x=x*2){ outb(x,0x378); pauseit(); } for (x=128;x>=1;x=x/2){ outb(x,0x378); pauseit(); } } } void blinking(){ int x; for(x=1;x<=10;x++){ if(x%2==1) outb((1+4+16+64), 0x378); else outb((2+8+32+128), 0x378); pauseit(); } } void running(){ int x,y,z; for(z=1;z<=5;z++){ for (x=1;x<=128;x=x*2){ outb(x,0x378); pauseit(); } } } void pauseit(){ int y; for(y=1;y<4000000;y++); //usleep(1); }