Thread: Light mayhem, could anyone help.

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    15

    Light mayhem, could anyone help.

    Hi, Basically i have built an electronic project, it is a set of trafic lights using a Darlington Driver and a D25 connector, i built that no problems and it works, i know this because in college my programming lecturer helped my right a program in C to control these lights and sequence them.

    Ok they worked fine at college and i was quite happy.

    BUT......

    When i got home i thought i would try and re create the scene, by writing the program in Turbo C. so i wrote the program, of which the code i shall show in a moment, but i noticed when i pluged the D25 into the back of the computer, all the lights stayed on, they did not do this at college, i tried it on another of my computers, and the same. how can i get them to turn off?

    My code:

    #include <stdio.h>
    #include <dos.h>
    #include <conio.h>

    void main(void){
    int Led[4]={33,19,12,26};
    int i=0;
    int Time;

    while(!kbhit()){
    outportb(0x378,Led[i]);

    switch (Led[i]){

    case 33: Time = 2000;
    break;
    case 19: Time = 500;
    break;
    case 12: Time = 1500;
    break;
    case 26: Time = 500;
    break;
    }

    Delay(Time);
    i++;
    if (i>2);
    i=0;;
    }
    }
    outportb(0x378,0);

    With this code i get a number of Declaration Sytax errors, and "i is assigned a value that is never used in function main"

    This is not my code, it was mostly written by my programming lecturer, so i do not understand it all, i understand most of it and the idea of it, as i am still learning C.

    If anyone could help me out id appreciate it, i cant imagine that there is anything wrong with the code because it was working in college, unless i have written it down wrong. But i think that the main problem is all the leds staying on, im sure the errors are easily fixable.

    Any help would be appreciated.

    Thanx

    Jon

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Your code has multiple problems.
    Code:
     void main(void){
    main never returns void. It always returns an int. Always.

    Code:
    i++;
    if (i>2);
    i=0;;
    Multiple problems:

    This if check actually does nothing, because you have a ; at the end of it.
    This will always set i to zero because of the if check.
    Assuming this did actually work, you still will never get 'Led[3]', because once it reaches 3, it is immediately set back to zero, without ever running 3 through the switch.

    On a side note, you have a pointless double ;; at the end of your assignment, when you only need one.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    15
    i must apologise, some of those errors, were typos on my part!! it was late!!

    in my code there is no double ;; at the end, and on the if statement instead of a ; there is a {.

    oh and i wrote down, if (i>2){ i=0;}

    it was suposed to read:

    if (i>3){
    i=0;
    }

    is this correct,as thats what my code actually says,

    but the lights all still turn on when they are plugged into the back of the computer, regardless of whether or not Turbo C is even open!!!

    do you know how i can stop it from doing this, because i think,that maybe when/if the code does work, its not going to be able to do the light sequance becasue they are permenantly on.

    Thanks

    Jon

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    15
    yes sorry for that, i use a different computer for that kind of work.

    i am running .NET Server 2003 on the computer at home, and Windows 95 at college.

    Thanx

    jon

  5. #5
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    When you post a code here, use code-tags this will make your code more readable, don't forget.

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    15
    Hmm, im lost, i thought i would run a little test, so i set up another machine, this time an exact replica, an old p1, running Win 95, the same as college.


    But the same problem occurred, but this time, on side of the lights stayed on and the other side went crazy flashing on and off!!

    Any ideas,

  7. #7
    Registered User
    Join Date
    Mar 2003
    Posts
    15
    tried all the settings mate, makes no difference, all the lights still stay on.

    I cant understand this,

    all the lights stay on whether or not any program is open, they just stay on as long as they are plugged into the parralell port and the battery is plugged into them.

  8. #8
    Registered User
    Join Date
    Mar 2003
    Posts
    15
    does anybody know if i can force the lights to turn off and respond the the program, is there soem code i can use to force the lights to turn off

  9. #9
    Registered User
    Join Date
    Mar 2003
    Posts
    15
    Code:
    #include <stdio.h>
    #include <dos.h>
    #include <conio.h>
    
    void main(){
    
    	int Led[4]={33,19,12,26};
    	int i=0;
    	int Seq
    		while(!kbhit){
    
    		outportb(0x378, Led[i];
    
    		switch(Led[i]){
    
    		case 33: Seq = 3000;
    			break;
    		case 19: Seq = 500;
    			break;
    		case 12: Seq = 1500
    			break;
    		case 26:Seq = 500;
    			break;
    
    		}
    		delay(Seq);
    		i++
    		if (i>3){
    		i=0 }
    
    
    		}
    
    }
    		outportb(0x378,0);
    This is an EXACT copy of my code, i am still coming up with numerous errors..

    -Declaration Syntax error in function main.
    -declaration missing ; in function main.
    -i is assigned a value that is never used in function main.
    -Led is assigned a value that is never used in function main.
    -Declaration syntax error
    -declaration syntax error

  10. #10
    Registered User
    Join Date
    Mar 2003
    Posts
    15
    I wrote the code, but i had some help with parts of it from my tutor, he dident put any errors in it, cuz i wrote it and i had it workign at college, but i can figure out where ive gone wrong at home.

    ive fixed the missing semicolons, but still errors

    cant figure it out.

  11. #11
    Registered User
    Join Date
    Mar 2003
    Posts
    15
    Code:
    #include <stdio.h>
    #include <dos.h>
    #include <conio.h>
    
    void main(){
    
    	int Led[4]={33,19,12,26};
    	int i=0;
    	int Seq;
    		while(!kbhit){
    
    		outportb(0x378, Led[i]);
    
    		switch(Led[i]){
    
    		case 33: Seq = 3000;
    			break;
    		case 19: Seq = 500;
    			break;
    		case 12: Seq = 1500;
    			break;
    		case 26:Seq = 500;
    			break;
    
    		}
    		delay(Seq);
    		i++;
    		if (i>3){
    		i=0;
    
    
    		}
    
    }
    		outportb(0x378,0);
    
    }
    Wahoo, i think i got rid of all the errors, it compiles but doesent run, just stays on the blue coding screen.

    Strange

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Critique my lighting model.
    By psychopath in forum Game Programming
    Replies: 4
    Last Post: 08-12-2006, 06:23 PM
  2. geometry won't display!?
    By psychopath in forum Game Programming
    Replies: 17
    Last Post: 09-21-2004, 10:10 AM
  3. How many forums members to change a lightbulb.
    By adrianxw in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 01-01-2004, 08:31 PM
  4. Easy way to light an orthogonal display
    By frenchfry164 in forum Game Programming
    Replies: 0
    Last Post: 05-05-2003, 05:19 PM
  5. A Common Scientific Belief
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 03-29-2002, 05:54 PM