![]() |
Simple problem with variables
I'm trying not to be a total idiot here by checking all over the forums first, and reading all of the documentation, but I CANNOT figure out how to initilize a simple integer variable 'pressure' that equals the value from the pressure reader on analog input 1.
static unsigned int pressure = Get_Analog_Value(rc_ana_in01); No matter where I put that, I can't get it to compile. It will compile fine in a few certain places in user_routines.c if it's just pressure = 0, but not this line. EVen if I split it up, it still doesn't work. All I get is syntax errors. Does anyone else wish this compiler was a tiny bit more descriptive in its error debugging? I've been learning Java this year using the NetBeans IDE, and this MPLAB IDE makes me want to hurl my laptop across the room. All of my coding depends on being able to initialize variables (well, duh) so this is really a stopping point for me. My entire team is getting sort of pissed off, becuase I just sit there looking angry every meeting trying to get the code to work. Thanks in advance for any replies I recieve...I must be doing some simple thing wrong. -Chris |
Re: Simple problem with variables
Quote:
Code:
pressure = Get_Analog_Value(rc_ana_in01);Hope that helps. |
Re: Simple problem with variables
Quote:
static unsigned int pressure; at the top of the function and then pressure = Get_Analog_Value(rc_ana_in01); where ever it is more appropiate. If this isn't the problem, could you post the message and some code snippets? |
Re: Simple problem with variables
Well either one, or the combination of both, fixed the problem. I'm not quite sure what I ended up doing, so I'll grab some code samples when I get home and explain how I fixed it.
Thanks for the help, now I can finally get started on my code! |
Re: Simple problem with variables
Initializing a variable is something you normally do with a predetermined value at powerup - like setting it to zero, or 127, or 255
I dont think that going out and reading an input register would technically be considered initializing it - because to get that analog input register value, the code has to be running maybe you are confused a little between initializing it (at powerup) and reading the input for the first time when your code runs? If you want to read the initial value of the pressure sensor when the robot is first turned on, you should have a separate variable for that, and some way to make sure you only read the sensor input once after the code first turns on. for example, initialize the variable to a value that it could not possible get from the sensor at power on, like maybe 254 then somewhere in your code have something like if initial_pressure = 254 then initial_presssure = pressure_sensor |
| All times are GMT -5. The time now is 04:21. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi