chipKIT® Development Platform

Inspired by Arduino™

chipKIT Videos

Fubarino Mini 2.0 attachInterrupt() Code Example


Majenko
volatile uint32_t isr_count[] = { 0, 0, 0, 0, 0 };
void isrA()
{ 
  isr_count[0]++;
  Serial.println("ISR A");
}
void isrB()
{ 
  isr_count[1]++;
  Serial.println("ISR B");
}
void isrC() 
{ 
  isr_count[2]++;
  Serial.println("ISR C");
}
void isrD() 
{ 
  isr_count[3]++;
  Serial.println("ISR D");
}
void isrE() 
{ 
  isr_count[4]++;
  Serial.println("ISR E");
}

void setup() 
{ 
  // Fubraino Mini 2.0 Pins that work with attachInterrupt: 0, 3, 4, 6, 24
  pinMode(0, INPUT);    // Interrupt pin must be an input
  pinMode(3, INPUT);    // Interrupt pin must be an input
  pinMode(4, INPUT);    // Interrupt pin must be an input
  pinMode(6, INPUT);    // Interrupt pin must be an input
  pinMode(24, INPUT);   // Interrupt pin must be an input

  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
  
  Serial.begin(115200);  // Open the Serial Port
  while(!Serial);
  delay(100);  // Give the serial terminal chance to open

  attachInterrupt(digitalPinToInterrupt(0),  isrA, FALLING);
  attachInterrupt(digitalPinToInterrupt(3),  isrB, FALLING);
  attachInterrupt(digitalPinToInterrupt(4),  isrC, RISING);
  attachInterrupt(digitalPinToInterrupt(6),  isrD, RISING);
  attachInterrupt(digitalPinToInterrupt(24), isrE, RISING);

  Serial.println("Fubarino attachInterrupt...");
}

void loop() 
{
  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // toggle pin LED_BUILTIN
  // original code uses lessthan but change to not equal for YouTube
  for(int i = 0; i != sizeof(isr_count)/sizeof(uint32_t); i++){
    Serial.print((char)('A' + i));
    Serial.print("=");
    Serial.print(isr_count[i], DEC);
    Serial.print(", ");
    isr_count[i] = 0;
  }
  Serial.println();
  delay(1000);
}

chipKIT Interview with Rick Anderson


Majenko

chipKIT Interview with Rick Anderson, Director of Virtual Worlds at Rutgers University, Spring 2021