| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| Charles Linquist 
 
 
 Joined: 07 May 2005
 Posts: 28
 Location: Campbell, CA
 
 
			    
 
 | 
			
				| Another newbie question |  
				|  Posted: Mon May 16, 2005 4:26 pm |   |  
				| 
 |  
				| In the code below 
 
  	  | Code: |  	  | IF (ToggleCounter1 ^ ToggleCounter2 ^ ToggleCounter3 ^ ToggleCounter4 ^ ToggleCounter5 ^ ToggleCounter6 ^ ToggleCounter7 ^ ToggleCounter8);
 {Output_bit(PIN_A0,0);
 
 ELSE
 Output_bit(PIN_A0,1)};
 
 | 
 
 On the ELSE statement, I get an error message "A numeric expression must appear here".
 
 What I'm tring to do is to test if any of the 8 ToggleCounters is TRUE, then set or reset Pin A0.
 All of the ToggleCounters are  INT1.
 
 I can't figure out what is wrong.  Can somebody help me?
 |  | 
	
		|  | 
	
		| dyeatman 
 
 
 Joined: 06 Sep 2003
 Posts: 1968
 Location: Norman, OK
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Mon May 16, 2005 5:27 pm |   |  
				| 
 |  
				| Syntax problem. 
 Remove the semi-colon after your expression then remove the curly braces before and after the else.... all you need are the two semicolons, one after each action statement.
 
 
  	  | Code: |  	  | IF (ToggleCounter1 ^ ToggleCounter2 ^ ToggleCounter3 ^ ToggleCounter4 ^ ToggleCounter5 ^ ToggleCounter6 ^ ToggleCounter7 ^ ToggleCounter8)
 Output_bit(PIN_A0,0);
 
 ELSE
 Output_bit(PIN_A0,1);
 
 
 | 
 That should work... although I think you might want the logical OR rather than the bitwise OR...
 |  | 
	
		|  | 
	
		| iso 9001 Guest
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Tue May 17, 2005 2:25 am |   |  
				| 
 |  
				| Thats XOR there. 
 And you could use bitwise OR I think, it should be the same as  evaluating out to a bool anyway.
 
 Either way, you probably don't want XOR.
 |  | 
	
		|  | 
	
		| Charles Linquist 
 
 
 Joined: 07 May 2005
 Posts: 28
 Location: Campbell, CA
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue May 17, 2005 6:40 am |   |  
				| 
 |  
				| Thanks! The program compiles now, and I'll switch my operators - which brings up another question, when I have an  int1 variable, and I want to AND or OR it, should I use the bitwise operator, or the regular operator, or does it matter? |  | 
	
		|  | 
	
		| newguy 
 
 
 Joined: 24 Jun 2004
 Posts: 1924
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue May 17, 2005 9:42 am |   |  
				| 
 |  
				| Whenever you want to see if something evaluates to "true" - i.e. in an if() or while() loop, you use the double and or double or:  && or ||. 
 && or || means "see if this is true" - & or | means "do a bitwise and/or".  Probably not what you want in an if() or while() loop.
 |  | 
	
		|  | 
	
		|  |