• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Newbie – Have put together a 4 wheeled robot car – With utltrasonic ping sensor – Using the Adafruit V2 motor shield

Q&A Forum › Category: Arduino › Newbie – Have put together a 4 wheeled robot car – With utltrasonic ping sensor – Using the Adafruit V2 motor shield
0 Vote Up Vote Down
Bob Jones asked 9 years ago

I am building a CPP library (class) to manage obstacle detection using the HC-SR02 sensor. I want to have all the methods that manage this device inside a class, but this proves challenging because the  attachInterrupt function cannot call outside the class.  What I need is a simple example of how to do this. My goal is that I be able to easily replicate this solution into lots of robots.

Question Tags: HC-SR02 Interrupts Class
3 Answers
0 Vote Up Vote Down
Bob Jones answered 9 years ago

Some additional information In sketch (before setup): BJMotionDetector myDetector; In Setup: attachInterrupt(0, myDetector.echoInterrupt,0);  // Attach interrupt to the sensor echo input In Class: void * BJMotionDetector::echoInterrupt() Compiler output: error: cannot convert ‘BJMotionDetector::echoInterrupt’ from type ‘void* (BJMotionDetector::)()’ to type ‘void (*)():attachInterrupt(ECHO_INTERRUPT, myDetector.echoInterrupt, CHANGE)Error compiling .ino source  

0 Vote Up Vote Down
Rui Santos Staff answered 9 years ago

Do you mean the HC-SR04 sensor? Which library are you using with that sensor? The NewPing? http://playground.arduino.cc/Code/NewPing

0 Vote Up Vote Down
Bob Jones answered 9 years ago

I am writing my own library. My goal is to use as much of my own code as possible (learning objective). I want to see an example of a hardware interrupt used within a class library. 

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.