Mindstorms 3rd Party ROBOTC Drivers RobotC
[Home] [Download] [Submit a bug/suggestion] [ROBOTC Forums] [Blog] [Support this project]

hitechnic-superpro-exp8.c

#pragma config(Sensor, S1,     HTSPB,                sensorI2CCustom9V)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/*   HiTechnic Experimenter's Kit Program

Experiment - 8 Temperature Sensor

This program reads the temperature sensor and displays the value.

*/

#include "drivers/hitechnic-superpro.h"

// This is the temperature at which we switch on the LED
#define THRESHOLD 23

long temperatureC;
long inputdata;

task main() {
  HTSPBsetupIO(HTSPB, 0x10);

  while(true) {
    // Read the value from the temp sensor
    inputdata = HTSPBreadADC(HTSPB, 0, 10);

    // Convert to an actual temperature
    temperatureC = ((inputdata*3300)/1023-600)/10.0;

    nxtDisplayTextLine(1, "Temp: %d C", temperatureC);

    // If we're above 28 degrees, switch on the LED
    if(temperatureC > THRESHOLD) {
      HTSPBwriteIO(HTSPB, 0x10);
    } else {
      HTSPBwriteIO(HTSPB, 0x00);
    }
    wait1Msec(50);
  }
}