View Single Post
  #1   Spotlight this post!  
Unread 05-01-2007, 01:12
Generalx5's Avatar
Generalx5 Generalx5 is offline
Hard Core Inventor
AKA: Jun(John) Zheng
FRC #1346 (Trobotics)
Team Role: Student
 
Join Date: Nov 2005
Rookie Year: 2004
Location: CANADA
Posts: 94
Generalx5 will become famous soon enough
Talking Why it works with an underscore?

I have a code written up for my own custom encoder involving optical sensors, yes its a optical encoder, using quadrature.

My question is why the compiler will find a syntax error if I didn't use an underscore in my variables.

For instance, I have this before:

-------------------------------------------------------------
/*** DEFINE USER VARIABLES AND INITIALIZE THEM HERE ***/

unsigned char Sen1;
unsigned char Sen2;
unsigned char Sen3;
unsigned char Sen4;
unsigned char Sen5;


-------------------------------------------------------------
along with

-------------------------------------------------------------
void Process_Data_From_Local_IO(void)
{

Sen1 = rc_dig_in05;
Sen2 = rc_dig_in06;
Sen3 = rc_dig_in07;
Sen4 = rc_dig_in08;
Sen5 = rc_dig_in09;


after I changed it to:

-------------------------------------------------------------
/*** DEFINE USER VARIABLES AND INITIALIZE THEM HERE ***/

unsigned char Sen_1;
unsigned char Sen_2;
unsigned char Sen_3;
unsigned char Sen_4;
unsigned char Sen_5;

-------------------------------------------------------------
void Process_Data_From_Local_IO(void)
{

Sen_1 = rc_dig_in05;
Sen_2 = rc_dig_in06;
Sen_3 = rc_dig_in07;
Sen_4 = rc_dig_in08;
Sen_5 = rc_dig_in09;


-------------------------------------------------------------
Im new at programming so im open to harassment.

************************************************** ***************
Another question is how do you set a value under certan conditions in programming?

For instance, I have 5 sensors like the above. When all 5 sensors reads a certain encoding for example all 0's how do I set this reading to a specific digit, so I can later call up on again. This makes it easier for changing later due to so many sensor reading combinations.

The idea im getting at is something like:

if (rc_dig_in01 = 0,rc_dig_in02 = 0,rc_dig_in03 = 0,rc_dig_in04 = 0,rc_dig_in05 = 0) == 10
if (rc_dig_in01 = 0,rc_dig_in02 = 0,rc_dig_in03 = 0,rc_dig_in14 = 0,rc_dig_in15 = 1) == 20

and after all these are set, I can have another routine that can use those numbers:

if (20) turn on solenoid 3 etc etc.

Last edited by Generalx5 : 05-01-2007 at 01:37. Reason: Added the second part under the * line