Use the Touch Pads - masonandrewmann/MEAP GitHub Wiki
The M.E.A.P. board has a 8 capacitive touch pads on the touch breakout board.
They are numbered as follows.
_____ _____ _____ _____
/ \ / \ / \ / \
| 0 || 1 || 2 || 3 |
\_____/ \_____/ \_____/ \_____/
_____ _____ _____ _____
/ \ / \ / \ / \
| 4 || 5 || 6 || 7 |
\_____/ \_____/ \_____/ \_____/
If you want to use the DIP switches, first be sure that the DIP breakout board is connected to your main board as shown in the setup guide. Then be sure that the readTouch() function from MEAP_Hardware_Test is included at the bottom of your program and that it is called within updateControl() by including the following line:
readTouch();
Also be sure that the relevant variables are defined at the top of your code (shown below):
// variables for capacitive touch pads
int touchPins[] = {2, 13, 27, 32, 4, 15, 14, 33};
int touchAvgs[] = {100, 100, 100, 100, 100, 100, 100, 100};
int touchVals[] = {0, 0, 0, 0, 0, 0, 0, 0};
int prevTouchVals[] = {0, 0, 0, 0, 0, 0, 0, 0};
int touchThreshold = 20;
All of this is done in the MEAP_Hardware_Test example so it is usually best to just use that program as a template.
The readTouch() is designed to be edited by the user. If you want something to occur when a pad is pressed or released, you can simply add that code to the readTouch() function in the location corresponding to the pad you want to touch. The meat of the function consists of 8 blocks that look like the following, each corresponding to a single touch pad. The block surrounding the line containing "pad 0 pressed" will execute when touch pad #0 is pressed and the block surrounding the line containing "pad 0 released" will execute when touch pad #0 is released.
case 0:
if(touchVals[i]){ // pad 0 pressed
Serial.println("pad 0 pressed");
} else { // pad 0 released
Serial.println("pad 0 released");
}
break;
If you want something to occur when the pad is pressed, add that code after the Serial.println("pad 0 pressed"); line, while if you want something to occur when the pad is released, add that code after the Serial.println("pad 0 released"); line.
For example, maybe we want the a note to be on while the pad is pressed and off when the pad is released. We may have a variable called "gain" that controls our oscillator's amplitude. We can change the value of that variable when a pad (in this case, pad 0) is pressed or released.
case 0:
if(touchVals[i]){ // pad 0 pressed
Serial.println("pad 0 pressed");
gain = 0; // oscillator will be muted
} else { // pad 0 released
Serial.println("pad 0 released");
gain = 255; // oscillator will be at full volume
}
break;
There may be a rare case where you want to refer to the value of the pads directly (ie. not just do something on a transition). You can access the values of pads switches directly using the touchVals[] array and indexing between 0 and 7 for the pad numbers. To retrieve the value of Pad #0 use touchVals[0], touchVals[1] for Pad #1 etc. The value will be 1 when the pad is pressed and 0 when the pad is not pressed.