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

hitechnic-superpro-exp2.c

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

/*   HiTechnic Experimenter's Kit for the SuperPro

Experiment - 2 Six LEDs and a Potentiometer

This program reads the analog value of a potentiometer and outputs a
digital value to one of six LEDs.

*/

#include "drivers/hitechnic-superpro.h"

task main() {
  int inputdata;
  ubyte outputdata;
  int bit;

  // Set all digital IOs as outputs as output
  HTSPBsetupIO(HTSPB, 0xFF);

  while(true) {
    // Read a 10bit wide analogue value from A0
    inputdata = HTSPBreadADC(HTSPB, 0, 10);

    nxtDisplayTextLine(1, "A0: %d", inputdata);

    // Set the output bit based on the analogue input value
    bit = (inputdata/128);
    if (bit > 5) bit = 5;
    nxtDisplayTextLine(2, "Bit: %d", bit);
    outputdata = 1 << bit;
    HTSPBwriteIO(HTSPB, outputdata);
    wait1Msec(50);
  }
}