Hello there,
please would someone be able to explain if possible if there is a solution to what I am trying to achieve.
I am creating a 10us on/off pulse from D13 and am trying to read it on pin A0 and output identical signal on pins A2 and A3. I have the code below however the attach interrupt isnt being called is this due to my loop?
The pulse functions works as expected however nothing else does
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#define SETBIT(ADDRESS, BIT) (ADDRESS |= (1 << BIT))
#define CLEARBIT(ADDRESS, BIT) (ADDRESS &= ~(1 << BIT))
#define RX_BLANK_OUT PORTC2
#define TX_BLANK_OUT PORTC3
int sensorPin = A0;
int sensorValue = 0;
void setup() {
DDRC |= _BV (2); // pinMode (A2, OUTPUT);
DDRC &= ~_BV (0); // pinMode (A0, INPUT);
DDRB |= _BV (5); // pinMode (13, OUTPUT);
attachInterrupt(digitalPinToInterrupt(sensorPin), rise, RISING);
// attachInterrupt(digitalPinToInterrupt(sensorPin), fall, FALLING);
}
void loop() {
PULSE();
}
void PULSE()
{
PORTB |= _BV (5); // digitalWrite (13, HIGH);
delayMicroseconds(10);
PORTB &= ~_BV (5); // digitalWrite (13, LOW);
delayMicroseconds(10);
}
void rise ()
{
sensorValue = (PINC & _BV (0)) == 0; // digitalRead (A0);
if (sensorValue == HIGH){
PORTC |= _BV (2); // digitalWrite (A2, HIGH);
PORTC |= _BV (3);} // digitalWrite (A3, HIGH);
else{
PORTC &= ~_BV (3); // digitalWrite (A3, LOW);
PORTC &= ~_BV (2);} // digitalWrite (A2, LOW);
sensorValue = (PINC & _BV (0)) == 0; // digitalRead (A0);
if (sensorValue == LOW){
PORTC &= ~_BV (3); // digitalWrite (A3, LOW);
PORTC &= ~_BV (2);} // digitalWrite (A2, LOW);
else{
PORTC |= _BV (2); // digitalWrite (A2, HIGH);
PORTC |= _BV (3);} // digitalWrite (A3, HIGH);
}
Any help would be massively appreciated.
Many Thanks, Jake
sketch_jan28b.ino (1.99 KB)