Bonsoir
J'ai acheté des capteurs tactiles
http://www.gotronic.fr/art-capteurs-tactiles-i2c-grove-sen51153p-18977.htm
et j'ai récupéré le code mais voilà je ne comprend rien pour la programmation, pourriez vous m'aider à programmer les capteurs tactiles svp ?
en fait j'aimerai que lorsque j'appuie sur un capteur mon servo se mette en route
merci pour votre aide
je vous met le code que j'ai récupéré mais je ne sais pas comment programmer les capteurs
/*
I2C Touch Sensor Demo v1.0
By:http://www.seeedstudio.com
Connect the I2C touch Sensor to I2C Grove connector to use
this demo use the software I2C to communicate.
*/
#include <mpr121.h>
#include <i2c.h>
//#include <Wire.h>
#define MPR121_R 0xB5 // ADD pin is grounded
#define MPR121_W 0xB4 // So address is 0x5A
#define MPR121addr 0x5a
int StateOfTouch1 =0;
int StateOfTouch2 =0;
int StateOfTouch3 =0;
int StateOfTouch4 =0;
int StateOfTouch5 =0;
int StateOfTouch6 =0;
int StateOfTouch7 =0;
int StateOfTouch8 =0;
int StateOfTouch9 =0;
int StateOfTouch10 =0;
int StateOfTouch11 =0;
int StateOfTouch12 =0;
int irqpin = 2; // D2
uint16_t touchstatus;
volatile int GetTouchSignal = 0;
unsigned char reg = 0;
//int TouchedSensor = 0;
unsigned char status1 =0;
unsigned char status2 =0;
long previousMillis = 0;
long interval = 100;
/*void Write_MPR121(unsigned char address,unsigned char data)
{
Wire.beginTransmission(MPR121addr);
Wire.send(address);
Wire.send(data);
Wire.endTransmission();
}*/
void setup()
{
// pinMode(irqpin, INPUT);
// digitalWrite(irqpin, HIGH);
// Wire.begin();
Serial.begin(9600);
DDRC |= 0b00010011;
PORTC = 0b00110000; // Pull-ups on I2C Bus
i2cInit();
Serial.println("setting device up..");
delay(100);
mpr121QuickConfig();
// mpr121Write(0x5e,0x00);
// mpr121Write(0x5d,0x23);
// Write_MPR121(0x5e, 0x41);
}
void loop()
{
//Serial.println(" in loop..");
unsigned char MPR_Query=0;
// checkInterrupt();
unsigned long currentMillis = millis();
// if(GetTouchSignal == 1)
if(currentMillis - previousMillis > interval)
{
previousMillis = currentMillis;
// GetTouchSignal = 0 ;
// Serial.println("get a ISR in loop..");
// TouchedSensor = Read_MPR121();
Read_MPR121();
}
//getPhoneNumber();
if (Serial.available()>0)
{
Serial.println("Get a command form PC..");
reg = Serial.read();
Serial.print("Quiry the Reg of ");
Serial.println(reg,BIN);
// Serial.print("\nDialing... ");
//for (int i=0; i<PHONE_DIGITS; i++)
//Serial.print(phoneNumber[i]);
MPR_Query = mpr121Read(reg);
Serial.print("the reg is = 0x");
Serial.println(MPR_Query,HEX);
//while(1);
// delay(1000);
}
delayMicroseconds(1000);
}
void Read_MPR121()
{
// Serial.println("INTR deteced in main.,begin to read reg 00 and 01");
// Wire.beginTransmission( MPR121addr);
// Wire.send(MPR121_touchstatus1);
// Wire.send(0x8f);
// Wire.requestFrom(MPR121addr,2);
// while(Wire.available() == 2)
// {
// Serial.println("receive the two reg 00 and 01");
// status1 = Wire.receive();
// status2 = Wire.receive();
// }
// Wire.endTransmission();
status1=mpr121Read(0x00);
status2=mpr121Read(0x01);
//Serial.print("status 1 is ");
// Serial.println(status1);
// Serial.print("status 2 is ");
//Serial.println(status2);
CheckStatus();
}
void CheckStatus()
{
if ((status1&0x01)==0x01)
{
StateOfTouch1 =1;
}
else
{
if (StateOfTouch1 ==1)
{
Serial.println("channel 0 has pressed..");
StateOfTouch1 =0;
}
}
if ((status1&0x02)==0x02)
{
StateOfTouch2 =1;
}
else
{
if (StateOfTouch2 ==1)
{
Serial.println("channel 1 has pressed..");
StateOfTouch2 =0;
}
}
if ((status1&0x04)==0x04)
{
StateOfTouch3 =1;
}
else
{
if (StateOfTouch3 ==1)
{
Serial.println("channel 2 has pressed..");
StateOfTouch3 =0;
}
}
if ((status1&0x08)==0x08)
{
StateOfTouch4 =1;
}
else
{
if (StateOfTouch4 ==1)
{
Serial.println("channel 3 has pressed..");
StateOfTouch4 =0;
}
}
if ((status1&0x10)==0x10)
{
StateOfTouch5 =1;
// Serial.println("channel 2 has pressed..");
}
else
{