Help!!

Hello! My name is Adam, and I have some problems with my coding project for school, any help would be greatly appreciated!! So I have attached what I have so far for clarification. Overall the goal is to have our program be able to heat up a volume of space, and then keep it at that temperature. We then have a potentiometer set to adjust the desired temperature. So far, I believe I have correctly set our two integers, “temp” and “thermistor” to be roughly close to the right numbers. (Don’t worry about the equations following them.)
From there, I have a general If-else statement, saying that if the “thermistorr” integer, what the actual temperature is, reads less than the “temp” integer, what the desired heat is based on the potentiometer, then the lights turn on. (Using lights as our Heat source) Leaving the else statement to turn the lights off if the “if” statement isn’t true.
For the most part, everything works correctly, the problem is that as our lights continue to heat up the volume, once it reaches our set temperature, the lights do not turn off. We know this by 1.) If we do math as the program runs, we know when it should be turning off. And 2.) If I end the program, and then immediately restart it, the lights will not come on. Telling us that the program is being read correctly but it’s almost as if the code doesn’t “update” as it runs? Any help would be greatly appreciated!!

**also note, we are using the Natural language PLTW platform type
vex formum help.png

For those of us with old, tired eyes, it would be helpful for you to past the code into the message window. place it between code tags, the selector for which looks like “</>” in the format bar of the post message window.

@aahodge38, I think the problem is that you are reading value of thermistor only once outside of the while() loop. If you bring it inside the loop then everything should work.

#pragma config(Sensor, in1,    POTENTIOMETER,  sensorPotentiometer)
#pragma config(Sensor, in2,    THERMISTOR,     sensorAnalog)
#pragma config(Motor,  port2,           Light2,        tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port3,           Light3,        tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port4,           Light1,        tmotorVex393_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
	int temp;
	temp = (SensorValue[POTENTIOMETER])*0.034; //works, but is giving a reading of .034 when the potentometer is at 1, allowing us to really only use half the turn to adujust the temp
	int thermistorr;
	thermistorr = (SensorValue[THERMISTOR])*-0.955+140;		// fairly accurate  *-0.91+140




	while(1==1)
	{
		if(thermistorr <= temp)
		{
			startMotor(Light1,127); 			//Lights/heat turned on
			startMotor(Light2,127);
			startMotor(Light3,127);
			wait(10);
		}
		else // was  if(thermistorr >= temp) try when insulation is finished, ran on step-mode instead of continuous.
		{

			startMotor(Light1,0);		//Lights/heat turned off
			startMotor(Light2,0);
			startMotor(Light3,0);


		}

	}
}
/code]


Here is our code.

Close

Put it within the while:

#pragma config(Sensor, in1, POTENTIOMETER, sensorPotentiometer)
#pragma config(Sensor, in2, THERMISTOR, sensorAnalog)
#pragma config(Motor, port2, Light2, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port3, Light3, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4, Light1, tmotorVex393_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
int temp;
int thermistorr;


while(1==1)
{
temp = (SensorValue[POTENTIOMETER])*0.034; 
thermistorr = (SensorValue[THERMISTOR])*-0.955+140;	// fairly accurate *-0.91+140

if(thermistorr <= temp)
{
startMotor(Light1,127); //Lights/heat turned on
startMotor(Light2,127);
startMotor(Light3,127);
wait(10);
}
else // was if(thermistorr >= temp) try when insulation is finished, ran on step-mode instead of continuous.
{

startMotor(Light1,0);	//Lights/heat turned off
startMotor(Light2,0);
startMotor(Light3,0);

}

}
}

thank you!! it worked as soon as we tried it!!!

I have a similar issue with my code, but it is just for driving, please help!
P.s I will post pics on Thursday.