您好,  [请登录]   [免费注册]   购物车 [0]

商品分类

    我们营业的时间
    9:00-18:00

    • 在线客服1:

    • 在线客服2:
    关闭在线客服

   
查看大图

Arduino 触摸板 Touch Shield

  • 商品编号:G50DAC43B8D24E
  • 货  号:G50DAC43B8D24E
  • 销售价: ¥50.00
购买数量:
  (库存34)

这是一款神奇的触摸键盘shield。你可以使用它来使得你的arduino工程有个既酷又方便的输入方式。此款shield 采用MPR121芯片构建。触摸键盘上共有9个电容式触摸按键。并且预留了3个可以分配的接口,可以扩充为其它输入。

板子上带有电平转换电路,适用于5V和3.3V系统。shield预焊有长脚排母,可以很方便的直接插在你的arduino控制板上。

示例代码:


#include "mpr121.h"
#include "i2c.h"

// 11 max digits used
#define DIGITS 11

// 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();
 
  // Create and interrupt to trigger when a button
  // is hit, the IRQ pin goes low, and the function getNumber is run.
  attachInterrupt(0,getNumber,LOW);
 
  // prints 'Ready...' when you can start hitting numbers
  Serial.println("Ready...");
}

void loop()
{
  //You can put additional code here. The interrupt will run in the backgound.
}

void getNumber()
{
  int i = 0;
  int touchNumber = 0;
  uint16_t touchstatus;
  char digits[DIGITS];
 
  touchstatus = mpr121Read(0x01) << 8;
  touchstatus |= mpr121Read(0x00);
 
  for (int j=0; j<12; j++)  // Check how many electrodes were pressed
  {
    if ((touchstatus & (1<<j)))
      touchNumber++;
  }
 
  if (touchNumber == 1)
  {
    if (touchstatus & (1<<SEVEN))
      digits[i] = '7';
    else if (touchstatus & (1<<FOUR))
      digits[i] = '4';
    else if (touchstatus & (1<<ONE))
      digits[i] = '1';
    else if (touchstatus & (1<<EIGHT))
      digits[i] = '8';
    else if (touchstatus & (1<<FIVE))
      digits[i] = '5';
    else if (touchstatus & (1<<TWO))
      digits[i] = '2';
    else if (touchstatus & (1<<NINE))
      digits[i] = '9';
    else if (touchstatus & (1<<SIX))
      digits[i] = '6';
    else if (touchstatus & (1<<THREE))
      digits[i] = '3';
     
    Serial.print(digits[i]);
    i++;
  }
  //do nothing if more than one button is pressed
  else if (touchNumber == 0)
    ;
  else
    ;
}

如果您对本商品有什么问题,请提问咨询!

发表咨询

标题:
*咨询内容:
联系方式: (可以是电话、email、qq等)
如果您对本商品有什么评价或经验,欢迎分享!
 

 
© 2001~2012 All rights reserved
本公司所有顾客个人信息将不会被泄漏给其他任何机构和个人
本商店logo和图片都已经申请保护,不经授权不得使用
有任何购物问题请联系我们在线客服 | 电话:0551-65365921-801 传真:0551-65365931 | 工作时间:周一至周五 9:00-17:30
Powered by ShopEx v4.8.5 |Gzip enabled 皖ICP备11003032号-2号

中科医院

中科白癜风

北京中科白癜风医院