I'm building a real-time map of the solar system (an "orrery") using 500 strip LEDs (APA102), a DS 3231 RTC, and a capacitive touch sensor (the MPR121 or CAP1188 breakout boards). I need some help understanding whether I need to use the IRQ function from the cap boards given how I want the code structured. Frankly, I just don't really understand interrupts despite a lot of reading.
I have just a few functions of interest inside the loop():
Code: Select all
void loop(){
float t = readRTC();
int n = readCap();
if (n_touched>0) doFunctions(n);
updatePlanets(t);
// delay(10); // put a small pause?
}
I have successfully coded the MRP121 reader with the board's IRQ, so that it only reads the actual touch once the board's IRQ fires:
Code: Select all
#define irqpin 4 // attach Arduino pin 4 to MPR121 IRQ out
boolean checkInterrupt(void){
return digitalRead(irqpin);
}
int readTouchInputs() {
if(!checkInterrupt()){ // did IRQ fire?
// Get the currently touched pads
n_touched = cap.touched();
//do a bunch of stuff
...
}
So questions.
1. Is this even possible?
2. If so, what would a skeleton code in the loop() function look like to do this?
Thanks a ton.