View unanswered posts | View active topics It is currently Mon Dec 22, 2014 3:58 am






Reply to topic  [ 2 posts ] 
Help with hitechnic superpro prototype sensor 
Author Message
Rookie

Joined: Sun Mar 23, 2014 1:09 pm
Posts: 1
Post 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


Sun Mar 23, 2014 1:17 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3297
Location: Rotterdam, The Netherlands
Post 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);
  }
}

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Mar 24, 2014 2:26 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.