Pages: [1]   Go Down
Author Topic: How do i use the Sparkfun Touch Shield to control pin 6 on the Arduino?  (Read 1030 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 202
Posts: 8711
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you remember pinMode(6, OUTPUT) in setup()?
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Jr. Member
**
Karma: 0
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, I did.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 202
Posts: 8711
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try this simplified example:

Code:

// 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
  Serial.begin(9600);
 
  //output on ADC4 (PC4, SDA)
  DDRC |= 0b00010011;
  // Pull-ups on I2C Bus
  PORTC = 0b00110000;
  // initalize I2C bus. Wiring lib not used.
  i2cInit();
 
  delay(100);
  // initialize mpr121
  mpr121QuickConfig();
 
  // prints 'Ready...' when you can start hitting numbers
  Serial.println("Ready...");
}

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);
}
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Jr. Member
**
Karma: 0
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's not working.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 202
Posts: 8711
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's not working.

Oops...  I forgot to put pinMode(6, OUTPUT) in setup().  Does it 'work' if you add that?
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Jr. Member
**
Karma: 0
Posts: 60
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, thank you very much.
Logged

Pages: [1]   Go Up
Jump to: