ROBOTC.net forums
http://robotc.net/forums/

Help with hitechnic superpro prototype sensor
http://robotc.net/forums/viewtopic.php?f=41&t=8315
Page 1 of 1

Author:  logan_en [ Sun Mar 23, 2014 1:17 pm ]
Post subject:  Help with hitechnic superpro prototype sensor

Hi,

How do I read from digital inputs correctly? I tried to extend the code from example7 in Xander's drivers and was not able to get any decent results.

Here is my code: http://pastebin.com/LKGm9EPX

I get a lot of very odd readings. Is there anything wrong with my code that I should be doing differently? Sorry if it is something very simple, I am new to programming robots / with robot-c and managing I/O.

Thanks,

Logan

Author:  mightor [ Mon Mar 24, 2014 2:26 am ]
Post subject:  Re: Help with hitechnic superpro prototype sensor

You'll need a call to HTSPBsetupIO() to configure the pins as either input or output, I am not seeing that in your code. You are also not really saying what you're trying to read or write. Be as precise as you can.

Another word of advice, remove any comments from the file that are NOT pertinent to the experiment you're trying to do, it's confusing. Make comments that are relevant to the task at hand.

= Xander

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

/*   HiTechnic Experimenter's Kit for the SuperPro

Experiment - 7 Magnetic Switch Sensor

This program measures reads the status of the magnetic sensor and outputs the status.

*/

#include "drivers/hitechnic-superpro.h"

int returnSensor(int sensor) {
  if (HTSPBreadIO(HTSPB, sensor) == 0) {
    return 0;
  }
  return 1;
}

task main() {
  // The data to be written: 0x10 = 010000 binary,
  // makes B4 digital port an output.

  // XS: here is where you'd call HTSPBsetupIO()
  //
 
  while(true) {
    eraseDisplay();
    nxtDisplayTextLine(1, "B0: %d", returnSensor(0x01));
    nxtDisplayTextLine(2, "B1: %d", returnSensor(0x02));
    nxtDisplayTextLine(3, "B2: %d", returnSensor(0x03));
    nxtDisplayTextLine(4, "B3: %d", returnSensor(0x04));
    nxtDisplayTextLine(5, "B4: %d", returnSensor(0x05));
    wait1Msec(100);
  }
}

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/