Hello everyone
Since a view days I have a problem I really can't solve. I wanted to creat an interrupt subroutine, which is only executed if the the signal on pin 8 is changin. But I regonized that it doesn't work with the libary "SoftwareSerial.h", which I need for my project (because of the GPS-Module). Does anyone know why it doesn't work, or has even a solution to my problem ?
Thanks already, and sorry because of my english, It's not my mother toungh
#include "SoftwareSerial.h"
#include <Servo.h>
byte ch_pitch; // Needed for Reciver, servo communication
int receiver_pitch; // Needed for storing value of reciver signal-lenght
unsigned long timer_1; // Needed for Reciver, Servo communication
Servo pitch;
void setup(){
pitch.attach(8);
//Arduino (Atmega) pins default to inputs, so they don't need to be explicitly declared as inputs
PCICR |= (1 << PCIE0); // set PCIE0 to enable PCMSK0 scan
PCMSK0 |= (1 << PCINT0); // set PCINT0 (digital input 8) to trigger an interrupt on state change
PCMSK0 |= (1 << PCINT1); // set PCINT1 (digital input 9)to trigger an interrupt on state change
PCMSK0 |= (1 << PCINT2); // set PCINT2 (digital input 10)to trigger an interrupt on state change
PCMSK0 |= (1 << PCINT3); // set PCINT3 (digital input 11)to trigger an interrupt on state change
}
void loop(){
}
ISR(PCINT0_vect){
//Channel 1=========================================
if(ch_pitch == 0 && PINB & B00000001 ){ //Input 8 changed from 0 to 1
ch_pitch= 1; //Remember current input state
timer_1 = micros(); //Set timer_1 to micros()
pitch.write(receiver_pitch);
}
else if(ch_pitch == 1 && !(PINB & B00000001)){ //Input 8 changed from 1 to 0
ch_pitch = 0; //Remember current input state
receiver_pitch = micros() - timer_1; //Channel 1 is micros() - timer_1
}
}
test.ino (1.45 KB)