this code used to work fine on older IDEs (simple RC PWM pass through). pin 8 wasread for pwm and servo pwm out is on pin 9.
i recently upgraded to IDE 1.8.19 and it no longer runs or prints at all. it uploads fine to the board but nothing runs.
any idea why? the problem seems to be with attach interrupt as when i remove it the code runs and prints.
///////////////////////////////////////////////////////////////////////////////////////////////////////
/* PWM pass through controller
*/////////////////////////////////////////////////////////////////////////////////////////////////////
#include <Servo.h>
#include <PinChangeInt.h>
Servo gearservo;
// pins definition
#define rxPin 8
#define servoPin 9
long led_cycle;
int ledState = HIGH;// the current state of the output pin
int currentrc = 0;
volatile int pwm_value = 0;
volatile int prev_time = 0;
int count = 0;
int pwm_corrupted = 0;
int valid_pwm_flag = 0;
uint8_t latest_interrupted_pin;
uint32_t current_rc_counter = 0;
int filtered_rc = 1000;
void setup()
{
pinMode(rxPin, INPUT);
PCintPort::attachInterrupt(rxPin, &rising, RISING);
pinMode(3, OUTPUT);
digitalWrite(3, LOW);
Serial.begin(115200);
delay(100);
gearservo.attach(servoPin);
}
void loop()
{
gearservo.write (pwm_value);
Serial.println(pwm_value);
} // END MAIN LOOP
void rising()
{
PCintPort::attachInterrupt(rxPin, &falling, FALLING);
prev_time = micros();
}
void falling()
{
PCintPort::attachInterrupt(rxPin, &rising, RISING);
pwm_value = micros() - prev_time;
}
pro mini nano (328) can only attach interrupts on pins 2 and 3, but this worked for years before with pin 8.
besides, if Rxpin = 2, the same code which used to run fine, doesnt run at all.
im puzzled at this.