Capacitive touch sensor CAP1188
FunduinoLast updated on
Acht Berührungssensoren – vom Testaufbau zum Instrument
You need this
KY-012 Buzzer Modul - aktiv mit Oszillator, 3,3-5 V
1,39 € *Item no. F23106686About the product — KY-012 Buzzer Modul - aktiv mit Oszillator, 3,3-5 V
KY-006 Buzzer Modul - passiv, 3-5 V, PWM-gesteuert
1,30 € *Item no. F23106690About the product — KY-006 Buzzer Modul - passiv, 3-5 V, PWM-gesteuert
Lautsprecher 5 W - 8 Ohm, 30 x 70 mm
1,84 € *Item no. F23107409About the product — Lautsprecher 5 W - 8 Ohm, 30 x 70 mm
CAP1188 Touchsensor - kapazitiv, 8 Kanäle, I2C, 3,3-5 V
11,26 € *Item no. F23108527About the product — CAP1188 Touchsensor - kapazitiv, 8 Kanäle, I2C, 3,3-5 V
Funduino UNO R3 Mikrocontroller - ATmega328P, 16 MHz, für Arduino
13,90 € *Item no. F23107480About the product — Funduino UNO R3 Mikrocontroller - ATmega328P, 16 MHz, für Arduino
Krokodilklemmenkabel - 10 Stück, 22 cm, male Steckerstift
3,00 € *Item no. F23107468About the product — Krokodilklemmenkabel - 10 Stück, 22 cm, male Steckerstift
All 6 parts together 32,69 € *Ready to ship immediately · Delivery time: 1-3 business days
* All prices include statutory VAT, plus shipping costs.
What the CAP1188 can do
First test: toggle the internal LED
1 / 3
Switch the internal LED via C1 and C2
#include "Adafruit_CAP1188.h"
// Assign a name
Adafruit_CAP1188 cap = Adafruit_CAP1188();
void setup()
{
Serial.begin(9600);
delay(500);
pinMode(LED_BUILTIN, OUTPUT);
if (!cap.begin())
{
// Stop the program if the CAP1188 is not found
Serial.println("CAP1188 not found");
while (1);
}
Serial.println("CAP1188 found!");
delay(1000);
// Set sensitivity
// 10 = very sensitive -> responds even when approached
// up to 111, less sensitive -> object must be touched
// can be adjusted depending on the object
int Sensitivity = cap.readRegister(0x1f) & 0x0f;
cap.writeRegister(0x1f, Sensitivity | 111);
}
void loop()
{
int Touch = cap.touched();
if (Touch == 0)
{
// no touch detected
return;
}
// Check for touches
for (int i = 0; i < 8; i++)
{
if (Touch & (1 << i))
{
// start with the highest value
if (i + 1 == 2) digitalWrite(LED_BUILTIN, HIGH);
if (i + 1 == 1) digitalWrite(LED_BUILTIN, LOW);
}
}
}Expansion: Music from Everyday Objects
1 / 2
Assembly and wiring
1 / 4
The music program
Play eight tones using the touch pads
#include "Adafruit_CAP1188.h"
#define Speaker 7
#define ToneLength 100
// Assign a name
Adafruit_CAP1188 cap = Adafruit_CAP1188();
void setup()
{
Serial.begin(9600);
if (!cap.begin())
{
// Stop the program if the CAP1188 is not found
Serial.println("CAP1188 not found");
while (1);
}
Serial.println("CAP1188 found!");
delay(1000);
// Set sensitivity
// 10 = very sensitive -> reacts even when something is nearby
// up to 111, less sensitive -> object must be touched
// can be adjusted depending on the object
int Sensitivity = cap.readRegister(0x1f) & 0x0f;
cap.writeRegister(0x1f, Sensitivity | 111);
}
void loop()
{
int Touch = cap.touched();
if (Touch == 0)
{
// no touch detected
return;
}
// Check for touches
for (int i = 0; i < 8; i++)
{
if (Touch & (1 << i))
{
// start with the highest value
if (i + 1 == 8) tone(Speaker, 262, ToneLength); // C'
if (i + 1 == 7) tone(Speaker, 294, ToneLength); // D'
if (i + 1 == 6) tone(Speaker, 330, ToneLength); // E'
if (i + 1 == 5) tone(Speaker, 349, ToneLength); // F'
if (i + 1 == 4) tone(Speaker, 392, ToneLength); // G'
if (i + 1 == 3) tone(Speaker, 440, ToneLength); // A'
if (i + 1 == 2) tone(Speaker, 494, ToneLength); // H'
if (i + 1 == 1) tone(Speaker, 523, ToneLength); // C"
}
}
}Rate the instructions