I have a RF433 receiver connected to pin A0. The receiver receives signals from a proprietary thermo sensor. The connected sensor (XY-MK-5V) is powered by 3.3V from Arduino, since I get a lot of interference, if I connect it to 5V.
I first used this sketch to determine, that the receiver is receiving the sent signal. It works (the embedded led flickers when the signal is being received).
Now I want to measure the pulse widths of the incoming signal. I've read here, that this could be done in three ways:
- by using the pulseIn() method
- using the external interrupts on pin 2 or pin 3
- using the pin change interrupts
I decided to use the third option, since it works on all pins and I have to use an analog one.
When I run the sketch below I get nothing. Could someone explain to me why?
#include <PinChangeInt.h>
#define MY_PIN A0 // we could choose any pin
volatile int pwm_value = 0;
volatile int prev_time = 0;
uint8_t latest_interrupted_pin;
void rising()
{
latest_interrupted_pin=PCintPort::arduinoPin;
PCintPort::attachInterrupt(latest_interrupted_pin, &falling, FALLING);
prev_time = micros();
}
void falling() {
latest_interrupted_pin=PCintPort::arduinoPin;
PCintPort::attachInterrupt(latest_interrupted_pin, &rising, RISING);
pwm_value = micros()-prev_time;
Serial.println(pwm_value);
}
void setup() {
pinMode(MY_PIN, INPUT);
digitalWrite(MY_PIN, HIGH);
Serial.begin(9600);
PCintPort::attachInterrupt(MY_PIN, &rising, RISING);
}
void loop() { }