(SKU:ELB030639)AD Keyboard 模拟键盘模块

来自YwRobot Studio Wiki
跳转至: 导航搜索
AD Keyboard 模拟键盘模块
AD Keyboard5位按键模拟键盘模块



产品参数

  • 尺寸:69*34mm
  • 电压:5V
  • 颜色:五色键帽,红黄绿蓝白各一个
  • 输出:模拟量电压
  • 接口:Arduino 3P接口 S V G
  • 平台:Arduino

产品特性

  • 5个按键仅占用一个模拟量接口,节省资源
  • 模拟量输出,按下不同的按键会有不同的电压值输出,可通过Arduino转换识别
  • 采用欧姆龙按键,可以方便更换其它样式的键帽
  • 兼容Arduino接口,可直接配合传感器扩展板使用

使用教程

AD Keyboard 模拟键盘模块LINE.jpg AD Keyboard 模拟键盘模块2LINE.jpg

样例代码

#define LEDR 9
#define LEDG 10
#define LEDB 11

int  adc_key_val[5] = {30, 150, 360, 535, 760 };
int NUM_KEYS = 5;
int adc_key_in;
int key = -1;
int oldkey = -1;

void setup()
{
  pinMode(LEDG, OUTPUT);
  pinMode(LEDB, OUTPUT);
  pinMode(LEDR, OUTPUT);
}
void loop() {
  adc_key_in = analogRead(0);      // read the value from the sensor
  key = get_key(adc_key_in);       // convert into key press
  if (key != oldkey) {		  // if keypress is detected
    delay(50);		           // wait for debounce time
    adc_key_in = analogRead(0);    // read the value from the sensor
    key = get_key(adc_key_in);	   // convert into key press
    if (key != oldkey) {
      oldkey = key;
      if (key >= 0) {
        analogWrite(LEDR, 0); analogWrite(LEDG, 0); analogWrite(LEDB, 0);
        switch (key)
        {
          case 0: {
              analogWrite(LEDR, 100);analogWrite(LEDG, 100);
            }
            break;
          case 1: {
              analogWrite(LEDR, 100);
            }
            break;
          case 2: {
              analogWrite(LEDB, 100);
            }
            break;
          case 3: {
              analogWrite(LEDG, 100);
            }
            break;
          case 4: {
              analogWrite(LEDR, 100); analogWrite(LEDG, 100);analogWrite(LEDB, 100);
            }
            break;
        }
      }
    }
  }
  delay(10);
}
// Convert ADC value to key number
int get_key(unsigned int input) {
  int k;
  for (k = 0; k < NUM_KEYS; k++) {
    if (input < adc_key_val[k]) {
      return k;
    }
  }
  if (k >= NUM_KEYS)k = -1;  // No valid key pressed
  return k;
}

更多

[YWRobot产品资料下载]

购买 YWRobot商城购买链接 AD Keyboard 模拟键盘模块

    YWRobot商城购买链接AD Keyboard5位按键模拟键盘模块