// PROGRAM IN C++ TO CONTROL ELECTRICAL DEVICES AUTOMATICALLY VIA A COMPUTER // SAVE THIS PAGE AS PROJECT2.TXT AND CHANGE AS PROJECT2.CPP THEN COMPILE IN TURBO/BORLAND CPP // OR OPEN THE SOURCE OF THIS HTML PAGE AND DIRECTLY SAVE AS PROJECT2.CPP /* A MCMILLAN PRODUCT. YOU MAY RE-CODE THIS PRODUCT AS YOU WISH. IF YOU WANT TO USE THIS PROJECT IN YOUR COMPANY, PLEASE VISIT WWW.CPPONLINE.8M.NET/CPPPROJECT.HTML FOR IMPLEMENTATIONAL DETAILS OR CONTACT :mcmillan@vsnl.net*/ #include #include #include #include #include #include #include int a,b,c,d,e,i,f,g,m,x,y,u1,u2,u3,u4,u5,u6,u11,u21,u31,u41,u51,u61; int w1,w2,w3,w4,w5,w6,w11,w21,w31,w41,w51,w61,x1,y1; int n=0; int n1=0; int on(int x) { n=n+x; printf("%d",n); outportb(0x378,n); delay(50); return(n); } int off(int y) { n=n-y; printf("%d",n); outportb(0x378,n); delay(50); return(n); } void emergency(void) { outportb(0x378,0); delay(50); setfillstyle(1,0); floodfill(0,0,10); setcolor(12); outtextxy(25,200,"SHUTTING DOWN ALL SYSTEMS(All made OFF)"); sound(2000); delay(2000); nosound(); } void main() { outportb(0x378,0); int p; char k,l,y; int gd=DETECT,gm; initgraph(&gd,&gm," "); settextstyle(1,0,5); setcolor(11); outtextxy(100,100,"1:MANUAL"); outtextxy(100,150,"2:AUTO"); outtextxy(100,300,"Enter Your Choice:"); int n=4; while(!kbhit()) { delay(50); if(n==4) { settextstyle(1,0,3); setcolor(3); outtextxy(80,0,"AUTOMATIC DEVICE CONTROLLER SOFTWARE"); setcolor(9); outtextxy(200,40,"A MCMILLAN PRODUCT"); n=11; delay(100); } if(n==11) { setcolor(13); outtextxy(80,0,"AUTOMATIC DEVICE CONTROLLER SOFTWARE"); delay(100); n=4; } } y=getch(); switch(y) { case'1': goto x; case'2': goto u; } x: z: clrscr(); setfillstyle(1,0); floodfill(0,0,10); setcolor(9); settextstyle(1,0,3); outtextxy(10,10,"MANUAL CONTROL OF YOUR HOME/OFFICE ELECTRICITY"); setcolor(14); settextstyle(1,0,3); outtextxy(200,60,"Select the Device"); setcolor(15); outtextxy(100,100,"1:LAMP"); outtextxy(100,120,"2:FAN"); outtextxy(100,140,"3:FLOURESCENT TUBE"); outtextxy(100,160,"4:MIXI"); outtextxy(100,180,"5:WASHING MAHINE"); outtextxy(100,200,"6:TV SET"); outtextxy(100,220,"7:GRINDER"); setcolor(4); outtextxy(100,240,"8:EMERGENCY"); setcolor(11); outtextxy(100,260,"9:QUIT"); setcolor(10); outtextxy(100,390,"Enter your choice(no):"); settextstyle(3,0,2); setcolor(14); outtextxy(200,300,"BE SURE THAT:"); setcolor(17); outtextxy(150,320,"All DEVICES are connected to LPT1 via RELAY"); outtextxy(150,340,"Each RELAY in Every Devices switched ON"); setcolor(19); outtextxy(150,360,"FOR MORE INFORMATION: mcmillan@vsnl.net"); settextstyle(3,0,2); while(!kbhit()) { setcolor(random(14)); outtextxy(360,100,"Visit me @"); outtextxy(360,120,"www.fedora.s5.com"); outtextxy(360,140,"www.mcmillan.s5.com"); outtextxy(360,160,"www.mcmillan.8m.com"); outtextxy(360,180,"www.lovelyyours.8m.net"); delay(75); } k=getch(); clrscr(); switch(k) { case '1': setfillstyle(1,0); floodfill(0,0,10); settextstyle(1,0,3); setcolor(25); outtextxy(150,100,"LAMP"); setcolor(12); outtextxy(100,120,"1:On"); outtextxy(100,140,"2:Off"); outtextxy(100,160,"3:Status"); setcolor(15); outtextxy(100,180,"4:Main menu"); l=getch(); clrscr(); { if(l=='1') { on(1); setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"LAMP is made ON"); sound(2000); delay(1600); nosound(); goto z; } if(l=='2') { off(1); setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"LAMP is made OFF"); sound(2000); delay(1600); nosound(); goto z; } if(l=='3') { m=n&1; if(m==1) { setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"LAMP is ON "); sound(2000); delay(1600); nosound(); goto z; } if(m==0) { setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"LAMP is OFF"); sound(2000); delay(1600); nosound(); goto z; } } goto z; } case'2': setfillstyle(1,0); floodfill(0,0,10); settextstyle(1,0,3); outtextxy(150,100,"FAN"); setcolor(20); outtextxy(100,120,"1:On"); outtextxy(100,140,"2:Off"); outtextxy(100,160,"3:Status"); setcolor(15); outtextxy(100,180,"4:Main menu"); l=getch(); clrscr(); { if(l=='1') { on(2); setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"FAN is made ON"); sound(2000); delay(1600); nosound(); goto z; } if(l=='2') { off(2); setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"FAN is made OFF"); sound(2000); delay(1600); nosound(); goto z; } if(l=='3') { m=n&2; if(m==1) { setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"FAN is ON"); sound(2000); delay(1600); nosound(); goto z; } if(m==0) { setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"FAN is OFF"); sound(2000); delay(1600); nosound(); goto z; } } goto z; } case '3': setfillstyle(1,0); floodfill(0,0,10); setcolor(15); outtextxy(200,100,"FLOURESCENT TUBE"); setcolor(1); outtextxy(200,120,"1:On"); outtextxy(200,140,"2:Off"); outtextxy(200,160,"3:Status"); setcolor(12); outtextxy(200,180,"4:Main menu"); l=getch(); clrscr(); { if(l=='1') { setfillstyle(1,0); floodfill(0,0,10); on(4); setcolor(14); outtextxy(200,100,"TUBE LIGHT is made ON"); sound(2000); delay(1600); nosound(); goto z; } if(l=='2') { setfillstyle(1,0); floodfill(0,0,10); off(4); setcolor(14); outtextxy(200,100,"TUBE LIGHT is made OFF"); sound(2000); delay(1600); nosound(); goto z; } if(l=='3') { m=n&4; if(m==1) { setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"TUBE LIGHT is ON"); sound(2000); delay(1600); nosound(); goto z; } else { setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"TUBE LIGHT is OFF"); sound(2000); delay(1600); nosound(); goto z; } } goto z; } case'4': setfillstyle(1,0); floodfill(0,0,10); setcolor(9); settextstyle(1,0,3); outtextxy(150,100,"MIXI"); setcolor(12); outtextxy(100,120,"1:On"); outtextxy(100,140,"2:Off"); outtextxy(100,160,"3:Status"); setcolor(15); outtextxy(100,180,"4:Main menu"); l=getch(); clrscr(); { if(l=='1') { on(8); setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"MIXI is made ON"); sound(2000); delay(1600); nosound(); goto z; } if(l=='2') { off(8); setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"MIXI is made OFF"); sound(2000); delay(1600); nosound(); goto z; } if(l=='3') { m=n&8; if(m==1) { setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"MIXI is ON"); sound(2000); delay(1600); nosound(); goto z; } if(m==0) { setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"MIXI is OFF"); sound(2000); delay(1600); nosound(); goto z; } } goto z; } case'5': setfillstyle(1,0); floodfill(0,0,10); setcolor(11); settextstyle(1,0,3); outtextxy(150,100,"WASHING MAHINE"); setcolor(4); outtextxy(100,120,"1:On"); outtextxy(100,140,"2:Off"); outtextxy(100,160,"3:Status"); setcolor(15); outtextxy(100,180,"4:Main menu"); l=getch(); clrscr(); { if(l=='1') { on(16); setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"WASHING MAHINE is made ON"); sound(2000); delay(1600); nosound(); goto z; } if(l=='2') { off(16); setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"WASHING MAHINE is made OFF"); sound(2000); delay(1600); nosound(); goto z; } if(l=='3') { m=n&16; if(m==1) { setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"WASHING MAHINE is ON"); sound(2000); delay(1600); nosound(); goto z; } if(m==0) { setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"WASHING MAHINE is OFF"); sound(2000); delay(1600); nosound(); goto z; } } goto z; } case '6': setfillstyle(1,0); floodfill(0,0,10); settextstyle(1,0,3); setcolor(15); outtextxy(150,100,"TV SET"); setcolor(12); outtextxy(100,120,"1:On"); outtextxy(100,140,"2:Off"); outtextxy(100,160,"3:Status"); setcolor(13); outtextxy(100,180,"4:Main menu"); l=getch(); clrscr(); { if(l=='1') { on(32); setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"TV SET is made ON"); sound(2000); delay(1600); nosound(); goto z; } if(l=='2') { off(32); setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"TV SET is made OFF"); sound(2000); delay(1600); nosound(); goto z; } if(l=='3') { m=n&32; if(m==1) { setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"TV SET is ON"); sound(2000); delay(1600); nosound(); goto z; } if(m==0) { setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"TV SET is OFF"); sound(2000); delay(1600); nosound(); goto z; } } goto z; } case'7': setfillstyle(1,0); floodfill(0,0,10); setcolor(9); settextstyle(1,0,3); outtextxy(150,100,"GRINDER"); setcolor(12); outtextxy(100,120,"1:On"); outtextxy(100,140,"2:Off"); outtextxy(100,160,"3:Status"); setcolor(15); outtextxy(100,180,"4:Main menu"); l=getch(); clrscr(); { if(l=='1') { on(64); setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"GRINDER is made ON"); sound(2000); delay(1600); nosound(); goto z; } if(l=='2') { off(64); setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"GRINDER is made OFF"); sound(2000); delay(1600); nosound(); goto z; } if(l=='3') { m=n&64; if(m==1) { setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"GRINDER is ON"); sound(2000); delay(1600); nosound(); goto z; } if(m==0) { setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"GRINDER is OFF"); sound(2000); delay(1600); nosound(); goto z; } } goto z; } case '8': emergency(); case '9': exit(0); default: goto z; } u: clrscr(); setfillstyle(0,0); floodfill(10,10,10); struct time t; gettime(&t); printf("The current time is: %2d:%02d:%02d.%02d\n", t.ti_hour, t.ti_min,t.ti_sec, t.ti_hund); settextstyle(1,0,1); outtextxy(150,100,"set time for LAMP to on"); cout<<"Enter Hour:";cin>>u1;cout<<"Enter Minute:"; cin>>w1; outtextxy(150,120,"set time for FAN to on"); cout<<"Enter Hour:";cin>>u2;cout<<"Enter Minute:"; cin>>w2; outtextxy(150,140,"set time for floracent tube to on"); cout<<"Enter Hour:";cin>>u3;cout<<"Enter Minute:"; cin>>w3; outtextxy(150,160,"set time for MIXI to on"); cout<<"Enter Hour:";cin>>u4;cout<<"Enter Minute:"; cin>>w4; outtextxy(150,180,"set time for WASHING MAHINE to on"); cout<<"Enter Hour:";cin>>u5;cout<<"Enter Minute:"; cin>>w5; outtextxy(150,200,"set time for TV SET to on"); cout<<"Enter Hour:";cin>>u6;cout<<"Enter Minute:"; cin>>w6; outtextxy(150,220,"set time for LAMP to off"); cout<<"Enter Hour:";cin>>u11;cout<<"Enter Minute:"; cin>>w11; outtextxy(150,240,"set time for fan to off"); cout<<"Enter Hour:";cin>>u21;cout<<"Enter Minute:"; cin>>w21; outtextxy(150,260,"set time for floracent tube to off"); cout<<"Enter Hour:";cin>>u31;cout<<"Enter Minute:"; cin>>w31; outtextxy(150,280,"set time for MIXI to off"); cout<<"Enter Hour:";cin>>u41;cout<<"Enter Minute:"; cin>>w41; outtextxy(150,300,"set time for WASHING MAHINE to off"); cout<<"Enter Hour:";cin>>u51;cout<<"Enter Minute:"; cin>>w51; outtextxy(150,320,"set time for TV SET to off"); cout<<"Enter Hour:";cin>>u61;cout<<"Enter Minute:"; cin>>w61; h: floodfill(0,0,10); settextstyle(1,0,5); outtextxy(200,220,"IN PROCESS......."); gettime(&t); printf( "The current time is: %2d:%02d:%02d.%02d\n", t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund); if((t.ti_hour==u1)&&(t.ti_min==w1)) { m=n&1; if(m==0) { on(1); } setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,100,"LAMP is made ON"); sound(2000); delay(1600); nosound(); } if((t.ti_hour==u2)&&(t.ti_min==w2)) { m=n&2; if(m==0) { on(2); } setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,120,"FAN is made ON"); sound(2000); delay(1600); nosound(); } if((t.ti_hour==u3)&&(t.ti_min==w3)) { m=n&4; if (m==0) { on(4); } setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,140,"floracent tube is made ON"); sound(2000); delay(1600); nosound(); } if((t.ti_hour==u4)&&(t.ti_min==w4)) { m=n&8; if(m==0) on(8); if(m!=0) on(0); setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,160,"MIXI is made ON"); sound(2000); delay(1600); nosound(); } if((t.ti_hour==u5)&&(t.ti_min==w5)) { m=n&16; if (m==0) on(16); if(m!=0) on(0); setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,180,"WASHING MAHINE is made ON"); sound(2000); delay(1600); nosound(); } if((t.ti_hour==u6)&&(t.ti_min==w6)) { m=n&32; if (m==0) on(32); if(m!=0) on(0); setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,200,"TV SET is made ON"); sound(2000); delay(1600); nosound(); } if((t.ti_hour==u11)&&(t.ti_min==w11)) { m=n&1; if (m==0) off(0); if(m!=0) off(1); setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,110,"LAMP is made OFF"); sound(2000); delay(1600); nosound(); } if((t.ti_hour==u21)&&(t.ti_min==w21)) { m=n&2; if (m==0) off(0); if(m!=0) off(2); setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,130,"FAN is made OFF"); sound(2000); delay(1600); nosound(); } if((t.ti_hour==u31)&&(t.ti_min==w31)) { m=n&4; if (m==0) off(0); if(m!=0) off(4); setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,150,"Floracent tube is made OFF"); sound(2000); delay(1600); nosound(); } if((t.ti_hour==u41)&&(t.ti_min==w41)) { m=n&8; if (m==0) off(0); if(m!=0) off(8); setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,170,"MIXI is made OFF"); sound(2000); delay(1600); nosound(); } if((t.ti_hour==u51)&&(t.ti_min==w51)) { m=n&16; if (m==0) off(0); if(m!=0) off(16); setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,190,"WASHING MAHINE is made OFF"); sound(2000); delay(1600); nosound(); } if((t.ti_hour==u61)&&(t.ti_min==w61)) { m=n&32; if (m==0) off(0); if(m!=0) off(32); setfillstyle(1,0); floodfill(0,0,10); setcolor(14); outtextxy(200,210,"TV SET is made OFF"); sound(2000); delay(1600); nosound(); } if(!kbhit())goto h; closegraph(); }