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

CDCosma

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?

johnwasser

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


johnwasser

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
  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);
}
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e


PaulS

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.

johnwasser


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: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e


Go Up