Using a Captivate Touch Sensor as a button to control a servo motor.

Hi, I'm trying to us an MPR121 Arduino shield like a button to where if you push it sends power to a servo motor. I want the servo motor to go back and forth (Sweep Preset). I've tried using "if" and "then" statements. It's not working, the shield is reading my fingers and showing the output on the serial monitor, but it's not moving the servo motor. Thanks for your help! Here's my code:

#include <Wire.h>
#include "Adafruit_MPR121.h>

Adafruit_MPR121 cap = Adafruit_MPR121();

uint16_t lasttouched = 0;
uint16_t currtouched = 0;

void setup() {
pinMode(LED_BUILTIN, OUTPUT);
while (!Serial);
Serial.begin(9600);
Serial.println("Adafruit MPR121 Capacitive Touch sensor test");

if (!cap.begin(0x5A)) {
Serial.println("MPR121 not found, check wiring?");
while (1);
}
Serial.println("MPR121 found!");
}

void loop() {

currtouched = cap.touched();

for (uint8_t i=0; i<12; i++) {

if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
Serial.print(i); Serial.println(" touched");
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000);
}

if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
Serial.print(i); Serial.println(" released");
}
}

lasttouched = currtouched;

return;

Serial.print("\t\t\t\t\t\t\t\t\t\t\t\t\t 0x"); Serial.println(cap.touched(), HEX);
Serial.print("Filt: ");
for (uint8_t i=0; i<12; i++) {
Serial.print(cap.filteredData(i)); Serial.print("\t");
}
Serial.println();
Serial.print("Base: ");
for (uint8_t i=0; i<12; i++) {
Serial.print(cap.baselineData(i)); Serial.print("\t");
}
Serial.println();

delay(100);
}

Code in tags:

#include <Wire.h>
#include "Adafruit_MPR121.h>



Adafruit_MPR121 cap = Adafruit_MPR121();


uint16_t lasttouched = 0;
uint16_t currtouched = 0;

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  while (!Serial);
  Serial.begin(9600);
  Serial.println("Adafruit MPR121 Capacitive Touch sensor test");


  if (!cap.begin(0x5A))
  {
    Serial.println("MPR121 not found, check wiring ? ");
    while (1);
  }
  Serial.println("MPR121 found!");
}

void loop()
{

  currtouched = cap.touched();

  for (uint8_t i=0; i<12; i++)
  {

    if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) )
    {
      Serial.print(i); Serial.println(" touched");
      digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(1000);                       // wait for a second
      digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
      delay(1000);
    }

    if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) )
    {
      Serial.print(i); Serial.println(" released");
    }
  }


  lasttouched = currtouched;


  return;


  Serial.print("\t\t\t\t\t\t\t\t\t\t\t\t\t 0x"); Serial.println(cap.touched(), HEX);
  Serial.print("Filt : ");
  for (uint8_t i=0; i<12; i++)
  {
    Serial.print(cap.filteredData(i)); Serial.print("\t");
  }
  Serial.println();
  Serial.print("Base : ");
  for (uint8_t i=0; i<12; i++)
  {
    Serial.print(cap.baselineData(i)); Serial.print("\t");
  }
  Serial.println();


  delay(100);
}

Tips:
1.) get rid of "while(!Serial);"
2.) get rid of "return;"

More to come.

I just noticed something. Nowhere in your code do you even mention a servo, much less control one. Where is your servo code?

Sorry, I was trying to test it out on a built-in sensor... before I advanced toward a servo motor.

125338:
Sorry, I was trying to test it out on a built-in sensor... before I advanced toward a servo motor.

Ok, so what's the problem now? Do you have new code to post?