Page 1 of 1
Temperature Sensor 4 Channel output loop
Posted: Tue Jul 30, 2019 8:44 am
by JEarley12
Hey everyone,
Currently attempting to code on codeblocks a program that allows all four 4 channels to be displayed. I was able to create a loop that allows the program to loop four times but you have to enter the channel number every time. I was unable to get the program to switch from channel to channel automatically. I'm a newbie to Phidget so any help is appreciated. I attached my current attempt on it using the example code.
Re: Temperature Sensor 4 Channel output loop
Posted: Tue Jul 30, 2019 9:01 am
by mparadis
Instead of looping through the example four times, you should create four different
PhidgetTemperatureSensorHandle variables, one for each channel. Instead of using the
AskForDeviceParameters function, you can hard-code the values for
setDeviceSerialNumber and
setChannel. If you want to see an example of how to do this cleanly, check the "Similar Phidgets" section on
this page.
Re: Temperature Sensor 4 Channel output loop
Posted: Tue Jul 30, 2019 11:25 am
by JEarley12
Thank you for the help, your suggestion worked. The only issues is the output for the channels are staggered. I attached the output and my new code. I'm trying to create a table format.
Re: Temperature Sensor 4 Channel output loop
Posted: Tue Jul 30, 2019 11:48 am
by mparadis
This is because each event happens at a slightly different time and you're printing a new line each time the event comes in.
There are a couple ways around this:
- You could have all four channels share the same change handler. You could store the most recent value for each channel and then only print a line once you have a new value for all four channels. In order to do this method you'll need to be able to differentiate which channel called the handler, which you can find in the "Distinguishing Events" section of the page I linked earlier.
- You could have four global variables which your four change handlers constantly update with the latest temperature value for each channel. Then, in your main function, you can have a loop that prints the most recent value for each channel all in one line and then waits a certain amount of time each iteration.