View unanswered posts | View active topics It is currently Fri Aug 22, 2014 10:03 am






Reply to topic  [ 1 post ] 
NXT4YOU.COM + MD8 
Author Message
Expert

Joined: Sun Sep 09, 2007 10:12 am
Posts: 116
Post NXT4YOU.COM + MD8
Hi alll,

my first product it's for sale (only on Portugal now), but in order to make official the code to robotc, i would need that this sensor could appear on sensors list.

The address of this sensor could change (between 0x40 to 0x7E), so I would need to know if it's possible that my multiplexer becames availlable on RobotC.

I add the example code and i could have more info on this site soon.

So, it's possible to choose on Sensors this Multiplexer ?

I would need something like: #pragma config(Sensor, S1, MD8, 0x70, sensorNxtgSONARCm)

Is that possible?

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

byte MD8Read[] = {0x01, 0x70};

byte outbuf[1];
byte count = 1;
int d[4],e[4];



//  This function allows conversion of an unsigned byte to a signed int
//  This is a workaround for RobotC
int ubyteToInt(ubyte _byte) {
    int _ret = 0;
    _ret = (_byte & 0x80) ? (_byte & 0x7F) + 0x80 : _byte;
    return _ret;
}

int MD8_Read(tSensors port)
{
   int out;
  while (nI2CStatus[port] == STAT_COMM_PENDING); // Wait for I2C bus to be ready
  sendI2CMsg(port, MD8Read[0], count);

  while (nI2CStatus[port] == STAT_COMM_PENDING); // Wait for I2C bus to be ready
  if(nI2CBytesReady[port] == count)
  {
     readI2CReply(port, outbuf[0], 1);
    out=ubyteToInt(outbuf[0]);
  }
  else {
      memset(outbuf, 0, 0);       //RobotC
  }
  return out;
}

void number2bool(int out)
{
    d[3]=(out&0x80)/128;
    d[0]=(out&0x40)/64;
    d[1]=(out&0x20)/32;
    d[2]=(out&0x10)/16;

    e[3]=(out&0x01);
    e[0]=(out&0x02)/2;
    e[1]=(out&0x04)/4;
    e[2]=(out&0x08)/8;
}

task main()
{
  while (true)
  {
    number2bool( MD8_Read(MD8) );     //Get value

    nxtDisplayTextLine(2,"E1:%d,E2:%d",e[0],e[1]);
    nxtDisplayTextLine(3,"E3:%d,E4:%d",e[2],e[3]);

    nxtDisplayTextLine(5,"D1:%d,D2:%d",d[0],d[1]);
    nxtDisplayTextLine(6,"D3:%d,D4:%d",d[2],d[3]);

    wait1Msec(100);

  }
}

_________________
http://www.apcsguarda.com
My Project: http://www.robotc.net/forums/viewtopic.php?f=15&t=712


Fri Mar 06, 2009 10:59 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

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:  



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