--
You received this message because you are subscribed to the Google Groups "arduino-pinchangeint-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to arduino-pinchangeint...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
#include <PinChangeInt.h>
#define PIN1 2
#define PIN2 3
volatile uint8_t latest_interrupted_pin;
volatile uint8_t interrupt_count[20]={0}; // 20 possible arduino pins
void quicfunc() {
latest_interrupted_pin=PCintPort::arduinoPin;
interrupt_count[latest_interrupted_pin]++;
};
void setup() {
pinMode(PIN1, INPUT); digitalWrite(PIN1, LOW);
PCintPort::attachInterrupt(PIN1, &quicfunc, CHANGE);
pinMode(PIN2, INPUT); digitalWrite(PIN2, LOW);
PCintPort::attachInterrupt(PIN2, &quicfunc, CHANGE);
Serial.begin(115200);
Serial.println(LOW);
}
uint8_t i;
void loop() {
unsigned long startTime[20]={0}; // signal rising time array
unsigned long onTime; // period the signal stays on
boolean edge = false; // goes true when a rising edge is detected
Serial.print("> ");
delay(1000);
for (i=0; i < 20; i++) { // for each available pin
onTime = 0;
boolean sig = digitalRead(i);
if((sig == HIGH) && (edge == false)) { // rising edge detected and start time goes to array
startTime[i] = millis();
edge = true;
} else {
if(sig == LOW){
onTime = micros() - startTime[i];
startTime[i] = 0;
edge = false;
}
}
Serial.print(i);
Serial.print(":");
Serial.print(onTime);
Serial.print(" ");
}
Serial.println();
}
#include <PinChangeInt.h>
// Detecting PWM signal's in arduino
struct sig {
volatile boolean isOn; // signal LOW->HIGH detected
volatile unsigned long start; // time in microseconds when "isOn" was detected
volatile int len; // the length of the signal on HIGH (NOW-start)
};
typedef struct sig Sig;
Sig signals[20] = {0};
void setup() {
Serial.begin(9600);
PCintPort::attachInterrupt(3, &calcInput, CHANGE); // throttle (1ms)->2ms
PCintPort::attachInterrupt(4, &calcInput, CHANGE); // ailerons 1ms<-(1.5ms)->2ms
PCintPort::attachInterrupt(5, &calcInput, CHANGE); // elevator 1ms<-(1.5ms)->2ms
PCintPort::attachInterrupt(6, &calcInput, CHANGE); // rudder 1ms<-(1.5ms)->2ms
}
void loop(){
delay(1000);
for(uint8_t pin=0; pin<20; pin++){
if(signals[pin].isOn){
printStruct(pin);
signals[pin].isOn = false;
}
}
Serial.println();
}
void calcInput(){
int pin = PCintPort::arduinoPin;
if(digitalRead(pin) == HIGH){
signals[pin].start = micros();
}else{
if(signals[pin].start && (signals[pin].isOn == false)){
signals[pin].len = (int)(micros() - signals[pin].start);
signals[pin].start = 0;
signals[pin].isOn = true;
}
}
}
void printStruct(int pin){
Serial.print(pin);
Serial.print(":");
Serial.print(signals[pin].isOn);
Serial.print(":");
Serial.print(signals[pin].start);
Serial.print(":");
Serial.print(signals[pin].len);
Serial.print(" ");
}
>> >> email to arduino-pinchangeint-discuss+unsub...@googlegroups.com.
>> >>
>> >> For more options, visit https://groups.google.com/d/optout.
>> >
>> >
>> >
>> >
>> > --
>> > -Mike Schwager
>> >
>> > --
>> > You received this message because you are subscribed to a topic in the
>> > Google Groups "arduino-pinchangeint-discuss" group.
>> > To unsubscribe from this topic, visit
>> >
>> > https://groups.google.com/d/topic/arduino-pinchangeint-discuss/spgI67zCTms/unsubscribe.
>> > To unsubscribe from this group and all its topics, send an email to
>> > For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> --
>> Marcelo Veras Correa
>> --
>> You received this message because you are subscribed to the Google Groups
>> "arduino-pinchangeint-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> For more options, visit https://groups.google.com/d/optout.
>
>
>
>
> --
> -Mike Schwager
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "arduino-pinchangeint-discuss" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/arduino-pinchangeint-discuss/spgI67zCTms/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
--
You received this message because you are subscribed to the Google Groups "arduino-pinchangeint-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to arduino-pinchangeint-discuss+unsub...@googlegroups.com.
--
-Mike Schwager
To unsubscribe from this group and stop receiving emails from it, send an email to arduino-pinchangeint...@googlegroups.com.