Capacitive touch interrupt as toggle switch …

Dear makers, builders and hackers,

hoping this is not a dumb question, as it could be I misread or misunderstood that somehow, …

I want to connect a metallic foil/plate to an Arduino (interrupt) pin and when the metal foil/plate is touched, the touch should trigger the interrupt. Like these capacitive touch responsive lamps: one touch turns them on, the other touch turns them off. I’m trying to toggle a LED (DotStar) installation on/off.

Would this work just with the interrupt? Could anyone please point me to some code which does that?

Thank you in advance!

PS: There’s this code on native capacitive sensors, but it seems very complex to me.

This is momentary behavior iirc, adding in a little button state change code will make it toggle

Interrupts are not involved. Use the library function to determine the sensor state (touched/not touched), the result will be the same as if you use a mechanical switch. Then toggle your installation on/off whenever the sensor state changes from not-touched to touched.

DrDiettrich, I’m not going to use a sensor/breakout/whatever. Just some metal wired directly to the pin.

fooness:
DrDiettrich, I’m not going to use a sensor/breakout/whatever. Just some metal wired directly to the pin.

Interrupts do not break out of anything. They force the running of some very short code and return to exactly the same place where the code was when the interrupt occurred.

What about this post on adafruit?

void loop() {
  if (digitalRead(touchPin) == HIGH)
  {
    sleepNow();
  }
  //run your light animation here
}

void sleepNow() {
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    sleep_enable();
    sleep_mode();    //stop here while sleeping
    sleep_disable();  // resume here when woken
}

Yes that is fine. It is not what you said in the first post however, you are not using an interrupt as such you are just using those interrupt pins to remove the Arduino from sleep mode.

This is not a complete program and the detail of the wake up pins need sorting.

This code may or may not wake up the controller as expected. A single wire with some more metal at its end acts as an antenna, catching whatever ambient electric noise. The tutorial is misleading, should be corrected.

A true capacitive sensor consists of two plates, which are loaded and unloaded by the controller, and the measured time depends on some material brought near the plates. See the CapSense library for details.

The tutorial may be referring to the capacitave sense board AT42QT1070 which is stand alone.

You can not use the CapSense library functions when the processor is asleep.

If not CapSense, what can I use when the processor is asleep? Thank you so much!

what can I use when the processor is asleep?

Nothing, the processor is asleep, that means that no code is running so the processor can not do anything.

I said you could use a stand alone touch sensor but that still takes current to run it.

Why do you want to put the Arduino asleep, when you want to control a power LED installation?
Why a touch button, if a mechanical switch will do better what you want?

If it's for learning purposes, let a timer wake up the Arduino every now and then, make it look for a sensor touch, and if not touched put it back asleep. This is how e.g. a remote control or other circuits work, which only wait most of the time for some user action.

It’s for an interactive artwork (for my studies) and a mechanical switch is unfortunately not wanted.

So it’s just about turning the LEDs off and on via touch. The Arduino can be powered, I’m sure that won’t take that much current that you’re losing all your savings. I think I’m sure …