problème avec capteur tactiles
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
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
code: [select]
/*
i2c touch sensor demo v1.0
by:http://www.seeedstudio.com
connect i2c touch sensor i2c grove connector use
this demo use software i2c communicate.
*/
#include <mpr121.h>
#include <i2c.h>
//#include <wire.h>
#define mpr121_r 0xb5 // add pin grounded
#define mpr121_w 0xb4 // address 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 isr in loop..");
// touchedsensor = read_mpr121();
read_mpr121();
}
//getphonenumber();
if (serial.available()>0)
{
serial.println("get command form pc..");
reg = serial.read();
serial.print("quiry 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 = 0x");
serial.println(mpr_query,hex);
//while(1);
// delay(1000);
}
delaymicroseconds(1000);
}
void read_mpr121()
{
// serial.println("intr deteced in main.,begin read reg 00 , 01");
// wire.begintransmission( mpr121addr);
// wire.send(mpr121_touchstatus1);
// wire.send(0x8f);
// wire.requestfrom(mpr121addr,2);
// while(wire.available() == 2)
// {
// serial.println("receive 2 reg 00 , 01");
// status1 = wire.receive();
// status2 = wire.receive();
// }
// wire.endtransmission();
status1=mpr121read(0x00);
status2=mpr121read(0x01);
//serial.print("status 1 ");
// serial.println(status1);
// serial.print("status 2 ");
//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
{
code: [select]
deuxième partie du code
if (stateoftouch5 ==1)
{
serial.println("channel 4 has pressed..");
stateoftouch5 =0;
}
}
if ((status1&0x20)==0x20)
{
stateoftouch6 =1;
// serial.println("channel 2 has pressed..");
}
else
{
if (stateoftouch6 ==1)
{
serial.println("channel 5 has pressed..");
stateoftouch6 =0;
}
}
if ((status1&0x40)==0x40)
{
stateoftouch7 =1;
// serial.println("channel 2 has pressed..");
}
else
{
if (stateoftouch7 ==1)
{
serial.println("channel 6 has pressed..");
stateoftouch7 =0;
}
}
if ((status1&0x80)==0x80)
{
stateoftouch8 =1;
// serial.println("channel 2 has pressed..");
}
else
{
if (stateoftouch8 ==1)
{
serial.println("channel 7 has pressed..");
stateoftouch8 =0;
}
}
// else if ((status1&0x04)==0x04)
// {
// serial.println("channel 3 has pressed..");
// }
// else if ((status1&0x08)==0x08)
// {
// serial.println("channel 4 has pressed..");
// }
// else if ((status1&0x10)==0x10)
// {
// serial.println("channel 5 has pressed..");
/// }
// else if ((status1&0x20)==0x20)
// {
// serial.println("channel 6 has pressed..");
// }
// else if ((status1&0x40)==0x40)
// {
// serial.println("channel 7 has pressed..");
// }
// else if ((status1&0x80)==0x80)
// {
// serial.println("channel 8 has pressed..");
// }
if ((status2&0x01)==0x01)
{
stateoftouch9 =1;
// serial.println("channel 2 has pressed..");
}
else
{
if (stateoftouch9 ==1)
{
serial.println("channel 8 has pressed..");
stateoftouch9 =0;
}
}
if ((status2&0x02)==0x02)
{
stateoftouch10 =1;
// serial.println("channel 2 has pressed..");
}
else
{
if (stateoftouch10 ==1)
{
serial.println("channel 9 has pressed..");
stateoftouch10 =0;
}
}
if ((status2&0x04)==0x04)
{
stateoftouch11 =1;
// serial.println("channel 2 has pressed..");
}
else
{
if (stateoftouch11 ==1)
{
serial.println("channel 10 has pressed..");
stateoftouch11 =0;
}
}
if ((status2&0x08)==0x08)
{
stateoftouch12 =1;
// serial.println("channel 2 has pressed..");
}
else
{
if (stateoftouch12 ==1)
{
serial.println("channel 11 has pressed..");
stateoftouch12 =0;
}
}
// else if ((status2&0x02)==0x02)
// {
// serial.println("channel 10 has pressed..");
// }
// else if ((status2&0x04)==0x04)
// {
// serial.println("channel 11 has pressed..");
// }
// else if ((status2&0x08)==0x08)
// {
// serial.println("channel 12 has pressed..");
// }
// end if ;
}
byte mpr121read(uint8_t address)
{
byte data;
i2csendstart();
i2cwaitforcomplete();
i2csendbyte(mpr121_w); // write 0xb4
i2cwaitforcomplete();
i2csendbyte(address); // write register address
i2cwaitforcomplete();
i2csendstart();
i2csendbyte(mpr121_r); // write 0xb5
i2cwaitforcomplete();
i2creceivebyte(true);
i2cwaitforcomplete();
data = i2cgetreceivedbyte(); // msb result
i2cwaitforcomplete();
i2csendstop();
cbi(twcr, twen); // disable twi
sbi(twcr, twen); // enable twi
return data;
}
void mpr121write(unsigned char address, unsigned char data)
//void mpr121write(uint8_t address, uint8_t data)
{
i2csendstart();
i2cwaitforcomplete();
i2csendbyte(mpr121_w);// write 0xb4
i2cwaitforcomplete();
i2csendbyte(address); // write register address
i2cwaitforcomplete();
i2csendbyte(data);
i2cwaitforcomplete();
i2csendstop();
//cbi(twcr, twen); // disable twi
// sbi(twcr, twen); // enable twi
}
void mpr121quickconfig(void)
{
serial.println("config mpr121..");
// section a
// group controls filtering when data > baseline.
mpr121write(mhd_r, 0x01);
mpr121write(nhd_r, 0x01);
mpr121write(ncl_r, 0x00);
mpr121write(fdl_r, 0x00);
// section b
// group controls filtering when data < baseline.
mpr121write(mhd_f, 0x01);
mpr121write(nhd_f, 0x01);
mpr121write(ncl_f, 0xff);
mpr121write(fdl_f, 0x02);
// section c
// group sets touch , release thresholds each electrode
mpr121write(ele0_t, tou_thresh);
mpr121write(ele0_r, rel_thresh);
mpr121write(ele1_t, tou_thresh);
mpr121write(ele1_r, rel_thresh);
//mpr121write(ele1_t, 0x06);
//mpr121write(ele1_r, 0x03);
mpr121write(ele2_t, tou_thresh);
mpr121write(ele2_r, rel_thresh);
mpr121write(ele3_t, tou_thresh);
mpr121write(ele3_r, rel_thresh);
mpr121write(ele4_t, tou_thresh);
mpr121write(ele4_r, rel_thresh);
mpr121write(ele5_t, tou_thresh);
mpr121write(ele5_r, rel_thresh);
mpr121write(ele6_t, tou_thresh);
mpr121write(ele6_r, rel_thresh);
mpr121write(ele7_t, tou_thresh);
mpr121write(ele7_r, rel_thresh);
mpr121write(ele8_t, tou_thresh);
mpr121write(ele8_r, rel_thresh);
// mpr121write(ele8_t, 0x06);
// mpr121write(ele8_r, 0x03);
mpr121write(ele9_t, tou_thresh);
mpr121write(ele9_r, rel_thresh);
mpr121write(ele10_t, tou_thresh);
mpr121write(ele10_r, rel_thresh);
mpr121write(ele11_t, tou_thresh);
mpr121write(ele11_r, rel_thresh);
//mpr121write(0x7d,0xc9);
//mpr121write(0x7e,0x82);
//mpr121write(0x7f,0xb5);
// mpr121write(0x7b,0x0b);
// section d
// set filter configuration
// set esi2
//mpr121write(fil_cfg, 0x24);
mpr121write(ato_cfgu, 0xc9); // usl = (vdd-0.7)/vdd*256 = 0xc9 @3.3v mpr121write(ato_cfgl, 0x82); // lsl = 0.65*usl = 0x82 @3.3v
mpr121write(ato_cfgl, 0x82); // target = 0.9*usl = 0xb5 @3.3v
mpr121write(ato_cfgt,0xb5);
mpr121write(ato_cfg0, 0x1b);
// section e
// electrode configuration
// enable 6 electrodes , set run mode
// set ele_cfg 0x00 return standby mode
//mpr121write(ele_cfg, 0x0c); // enables 12 electrodes
mpr121write(ele_cfg, 0x8c);
//mpr121write(ele_cfg, 0x06); // enable first 6 electrodes
// section f
// enable auto config , auto reconfig
/*mpr121write(ato_cfg0, 0x0b);
mpr121write(ato_cfgu, 0xc9); // usl = (vdd-0.7)/vdd*256 = 0xc9 @3.3v mpr121write(ato_cfgl, 0x82); // lsl = 0.65*usl = 0x82 @3.3v
mpr121write(ato_cfgt, 0xb5);*/ // target = 0.9*usl = 0xb5 @3.3v
serial.println("config mpr121 done!");
}
void checkinterrupt(void)
{
//serial.println("checking interrupt..");
int irq =0;
irq = digitalread(irqpin);
if(irq == 0)
{
gettouchsignal=1;
}
// return 0;
else
{
gettouchsignal=0;
}
// serial.print("gettouchsignal ");
// serial.println(gettouchsignal);
}
Arduino Forum > International > Français (Moderators: jfs, Snootlab) > problème avec capteur tactiles
arduino
Comments
Post a Comment