PulseInput.h Did anyone got it to work?

I am using the basic read example and Im getting zeros...
I chose pin 19 because is an interrupt on Mega. Maybe the syntax changed and the library did not keep up?

#include <PulseInput.h>   
volatile unsigned int input;    /* each signal requires a variable */

void setup() {
  Serial.begin(115200);         // Speed must stay at 115200 Not lower or higher to work with the USB shield

  
  // 2. assign variables to receive signal 
  attachPulseInput(19, input);  // pin 8 as INPUT_PULLUP

  /* Generate pwm signal */
  constexpr int   PIN        = 3;            // PWM capable pin
  constexpr int   ON_TIME    = 1000;         // Pulse width in microseconds
  constexpr float DUTY_CYCLE = ON_TIME * 255.0 / 2024.0;
  
  analogWrite(PIN, DUTY_CYCLE); 

  /* To stop reading an already specified input, use this function: */
  //detachPulseInput(19);        // Stop reading input at pin 8
}

void loop() {  
  // read signal [microseconds]
  Serial.println(input);
}

Then I use pulseIn and I get nice values such as 1455,

void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);
}

void loop() {
   int thro = pulseIn(19, HIGH ); // Thro Port- 1093 to 1885 Triple servo wire
    Serial.print("THRO ="); // Print the value of 
   Serial.println(thro); 

}

Thanks
Mitch

I moved your topic to an appropriate forum category @laptophead.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Thanks for the classification. I will pay attention.
Is my post visible? No one came to help.
First time it happens,
Mitch

What is the

library?
Please insert it source code to the message, using the code tags.
Why do you need it, if you using just a pulseIn() code?

#include <PulseInput.h>

That library uses pin change interrupts and the Nico Hood Library.

Pin 19 is not a valid pin change interrupt pin on the Mega.

Use one of these pins

Arduino Mega: 10, 11, 12, 13, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64),
           A11 (65), A12 (66), A13 (67), A14 (68), A15 (69)

Thanks a lot, That was correct. How would I have known.

Next I will have to generate PWM for my robot motors. I wonder if I can do that at the same time as I read the remote levels on 7 channels,.

Tried it with PulseIn and it was horrible.
Any further guidance is appreciated.
Mitch

I read the ReadMe for the library and followed the link for dependencies
https://github.com/RCmags/pulseInput#readme

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.