Go Down

Topic: How do i use the Sparkfun Touch Shield to control pin 6 on the Arduino? (Read 1 time) previous topic - next topic


Hi, I have been trying to use Sparkfun's Touch Shield: http://http://www.sparkfun.com/products/10774 to control pin 6 on the Arduino. I want every time I press the 1 button to make pin 6 go low, and every time I press the 2 button to make pin 6 go high. I have tried the most simple approach by adding digitalWrite(6, HIGH); to the else if that runs when button 2 is pressed but it doesn't work. How do I solve this problem?


Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp


Try this simplified example:

Code: [Select]

// include the atmel I2C libs
#include "mpr121.h"
#include "i2c.h"

// Match key inputs with electrode numbers
#define ONE 8
#define TWO 5
#define THREE 2
#define FOUR 7
#define FIVE 4
#define SIX 1
#define SEVEN 6
#define EIGHT 3
#define NINE 0

//extras (not used)
#define ELE9 9
#define ELE10 10
#define ELE11 11

//interupt pin
int irqpin = 2;  // D2

void setup()
  //make sure the interrupt pin is an input and pulled high
  pinMode(irqpin, INPUT);
  digitalWrite(irqpin, HIGH);
  //configure serial out
  //output on ADC4 (PC4, SDA)
  DDRC |= 0b00010011;
  // Pull-ups on I2C Bus
  PORTC = 0b00110000;
  // initalize I2C bus. Wiring lib not used.
  // initialize mpr121
  // prints 'Ready...' when you can start hitting numbers

void loop()
  uint16_t touchstatus;
  touchstatus = mpr121Read(0x01) << 8;
  touchstatus |= mpr121Read(0x00);
  if (touchstatus & (1<<ONE))
      digitalWrite(6, LOW);
  if (touchstatus & (1<<TWO))
      digitalWrite(6, HIGH);
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp


t's not working.

Yes, it is. It just isn't doing what you want.

You need to tell us what it does, and what you want it to do, and how those two differ.
The art of getting good answers lies in asking good questions.


It's not working.

Oops...  I forgot to put pinMode(6, OUTPUT) in setup().  Does it 'work' if you add that?
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131