Arduino Module Combined with User Code
Carl Hoffman from United States  [1 posts]
5 years

The Arduino module works great for my project.  I just have one problem with it.  I am using an ultrasonic sensor that needs special code on the Arduino Mega to output the distance.  This code is:
const int pingPin = 8;//output cable
const int inputPin = 31;//input cable

void setup() {
  // initialize serial communication:

void loop()
  long duration, inches, cm;
  pinMode(inputPin, OUTPUT);
  digitalWrite(inputPin, LOW);
  digitalWrite(inputPin, HIGH);
  digitalWrite(inputPin, LOW);

  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);

  // convert the time into a distance
  inches = microsecondsToInches(duration);


long microsecondsToInches(long microseconds)
    return microseconds / 74 / 2;

I am unsure how to combine this code with the RoboRealm Mega Sketch.

Or to be more broad, is there any way a user can add their own custom code to the Mega Sketch and have it implemented in the Mega Module? i.e. combining the MCU Communicator and Arduino Mega modules?

Thanks a lot,

-Carl H.
Anonymous 5 years
If I understand your question/comment, you desire to integrate your Ultrasonic range finder code to the Mega module. You can add an additional array of range data to the existing Mega data stream. Perhaps 2 more bytes representing the sensor bearing and range. The receiving software must parse out the data for display in addition to any collision avoidance scheme you may plan if incorporating the sensor in a robot. I have done a similar concept with a range sensor, Arduino, and Visual Basic. You can view this on my YouTube Channel.

If I missed your point, please provide clarification.

Good luck!

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index