Hi all,
I would like to know how can i use interrupt when a data is being fed into the AnalogRead?
I have written some code but it doesnt even go to the void loop function.
Instead, it went straight to the interrupt function. I have attached the result from the Serial monitor below.
Following is my code:
//set the baudrate
int baudRate = 115200;
//set the LEDs
int greenLED = 3;
int blueLED = 4;
//defining variables
int pdlimit = 1020; //1032 is the value of 5V
int interruptSignal = A1;
//defining variables used by the interrupt function
volatile int flag; //to see if the PD receiver '1' or '0'
volatile int i;
volatile int delayTime = 500; //delay time for LED to blink
volatile int j = 0; //receiver counter for the bits
volatile int pd = A0; //setting the input pin for analog signal
volatile int value = 0; //initiate the store variable of PD to be zero
volatile char outChar; //output data back
void setup() {
// put your setup code here, to run once:
pinMode(greenLED,OUTPUT);
pinMode(pd,INPUT); //set the pin to input to collect data from photodiode
Serial.begin(baudRate); //set the rate for serial monitor
startLED();
//Attach the interrupt
attachInterrupt(interruptSignal, startreceiving, RISING);
//Falling edge because Photodiode is 5v at 'off state', thus
//when PD detects light, voltage will drop.
}
void loop() {
// put your main code here, to run repeatedly:
j = 0; //reset the counter back to 0
clearchar(); //clear the storage variable
Serial.println("Program Start");
int connectionEstablish = analogRead(interruptSignal);
}
//end of main program
//sub function
void startreceiving() //the interrupt function
{
Serial.println("interrupt start");
for (int i =0; i<8; i++)
{
Serial.println("for loop start");
pdvalue(); //get value from photodiode
receiver(); //decode the data and output
}
Serial.print("\n");
Serial.print("The character entered is ");
Serial.println(outChar);
}
