Using a Captivate Touch Sensor as a button to control a servo motor.
hi, i'm trying mpr121 arduino shield button if push sends power servo motor. want servo motor go , forth (sweep preset). i've tried using "if" , "then" statements. it's not working, shield reading fingers , showing output on serial monitor, it's not moving servo motor. help! here's 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();
(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 led on (high voltage level)
delay(1000); // wait second
digitalwrite(led_builtin, low); // turn led off making 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: ");
(uint8_t i=0; i<12; i++) {
serial.print(cap.filtereddata(i)); serial.print("\t");
}
serial.println();
serial.print("base: ");
(uint8_t i=0; i<12; i++) {
serial.print(cap.baselinedata(i)); serial.print("\t");
}
serial.println();
delay(100);
}
#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();
(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 led on (high voltage level)
delay(1000); // wait second
digitalwrite(led_builtin, low); // turn led off making 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: ");
(uint8_t i=0; i<12; i++) {
serial.print(cap.filtereddata(i)); serial.print("\t");
}
serial.println();
serial.print("base: ");
(uint8_t i=0; i<12; i++) {
serial.print(cap.baselinedata(i)); serial.print("\t");
}
serial.println();
delay(100);
}
code in tags:
tips:
1.) rid of "while(!serial);"
2.) rid of "return;"
more come.
code: [select]
#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();
(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 led on (high voltage level)
delay(1000); // wait second
digitalwrite(led_builtin, low); // turn led off making 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 : ");
(uint8_t i=0; i<12; i++)
{
serial.print(cap.filtereddata(i)); serial.print("\t");
}
serial.println();
serial.print("base : ");
(uint8_t i=0; i<12; i++)
{
serial.print(cap.baselinedata(i)); serial.print("\t");
}
serial.println();
delay(100);
}
tips:
1.) rid of "while(!serial);"
2.) rid of "return;"
more come.
Arduino Forum > Using Arduino > Programming Questions > Using a Captivate Touch Sensor as a button to control a servo motor.
arduino
Comments
Post a Comment