interrupt - trouble compiling!

Hi, If anyone has a moment could they cast their eye over this code? I am getting the compiling error "a function-definition is not allowed here before '{' token" in the 'void sensor' loop. Any help appreciated. :slight_smile:

int sensorpin = 2;
int relaypin = 13;
int sensorval;
int softswitch;
int incomingByte;      // a variable to read incoming serial data into


void setup(){
  Serial.begin(9600);
  pinMode(relaypin,OUTPUT);

 attachInterrupt(0,sensor, RISING);
}
void loop() {
  
  
  
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = Serial.read();
    // if it's a capital H (ASCII 72), turn on the LED:
    if (incomingByte == 'H') {
      digitalWrite(relaypin, HIGH);
      delay(500);
      digitalWrite(relaypin,LOW);

    } 
    // if it's an L (ASCII 76) turn off the LED:
    if (incomingByte == 'L') {

      
    
}
  
  void sensor()
  
  {
    Serial.println ('A');
  }
    // if it's an L (ASCII 76) turn off the LED:
    if (incomingByte == 'L') {

[glow]  }  [/glow]
    
}

I just got rid of that section and it still gives the same error!

current code

int sensorpin = 2;
int relaypin = 13;
int sensorval;
int softswitch;
int incomingByte;      // a variable to read incoming serial data into


void setup(){
  Serial.begin(9600);
  pinMode(relaypin,OUTPUT);

 attachInterrupt(0,sensor, RISING);
}
void loop() {
  
  
  
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = Serial.read();
    // if it's a capital H (ASCII 72), turn on the LED:
    if (incomingByte == 'H') {
      digitalWrite(relaypin, HIGH);
      delay(500);
      digitalWrite(relaypin,LOW);

    } 
  }
  
  void sensor()
  
  {
    Serial.println ('A');
  }

You need another } before void sensor() to complete the void loop() section.

cheers. :slight_smile:

Gotta watch those brackets.
If you click the cursor just to the right of a ) or }, the IDE will show you where it thinks the mating ( or { is. If you can't see it on the portion of screen you are viewing, leave the cursor next to the ) or } and use the vertical scroll bar to look back thru your code.