“SKU:RB-02S159 模擬鍵盤模塊”的版本間的差異
來自ALSROBOT WiKi
(→?相關(guān)資料) |
(→?資料下載) |
||
第362行: | 第362行: | ||
* 產(chǎn)品購買鏈接:http://lifestyle201.com/goods-873.html | * 產(chǎn)品購買鏈接:http://lifestyle201.com/goods-873.html | ||
+ | * 奧松機器人技術(shù)論壇:http://www.makerspace.cn |
2018年10月9日 (二) 15:47的版本
目錄 |
產(chǎn)品概述
奧松機器人新推出的模擬鍵盤模塊,我們在設(shè)計按鍵輸入電路時,采用獨立IO連接按鍵或者矩陣連接的方式,矩陣連接相對于獨立連接的方式來說占用IO相對較少,但有沒有一種更好的方式呢,模擬鍵盤模塊就很好的解決了這個問題,它能讓你用一個模擬IO口,實現(xiàn)五個按鍵狀態(tài)的讀取,真正實現(xiàn)了電路的簡化,并且在按下按鍵時,按鍵旁的LED會隨之亮起。
產(chǎn)品參數(shù)
基本參數(shù)
- 品名:模擬按鍵模塊
- 貨號:RB-02S159
- 尺寸:55*40mm
- 固定孔:M3*4
電氣性能
1.工作電壓:3.3V~5V
2.工作溫度限值:-20℃ ~ +70℃
3.信號類型:模擬信號
4.接口類型:3P 防插反接口
5.工作電流:小于等于20mA,5V 供電下
6.按鍵及指示燈:S1 ~ S5 五個按鍵旁分別配有指示燈,按下時亮起
7.按鍵模擬值:
- S1=380±40
- S2=470±40
- S3=560±40
- S4=680±40
- S5=840±40
8.引腳定義:
- +:電源正極
- -:電源負極
- S:信號
使用方法
example1_Arduino
- 主要硬件
- Arduino UNO 控制器
- 傳感器擴展板 V5.0
- 模擬按鍵模塊
- 單頭防插反 3P 傳感器連接線
- USB 數(shù)據(jù)線
- 硬件連接
- 示例程序
int adc_key_val[5] ={400,470,560,700,900 }; int NUM_KEYS = 5; int adc_key_in; int key=-1; int oldkey=-1; void setup() { pinMode(13, OUTPUT); //we'll use the debug LED to output a heartbeat Serial.begin(9600); // 9600 bps } void loop() { adc_key_in = analogRead(0); // read the value from the sensor digitalWrite(13,LOW); key = get_key(adc_key_in); // convert into key press //Serial.println(adc_key_in); 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){ digitalWrite(13,HIGH); switch(key) { case 0:Serial.println("S1 OK"); break; case 1:Serial.println("S2 OK"); break; case 2:Serial.println("S3 OK"); break; case 3:Serial.println("S4 OK"); break; case 4:Serial.println("S5 OK"); break; } } } } delay(100); } // 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; }
- 程序效果
example2_Arduino
- 主要硬件
- Arduino UNO 控制器
- 傳感器擴展板 V5.0
- 模擬按鍵模塊
- 單頭防插反 3P 傳感器連接線
- USB 數(shù)據(jù)線
- 全彩 LED 發(fā)光模塊
- 硬件連接
- 示例程序
#include <MeRGBLed.h> MeRGBLed led(PORT_3); int adc_key_val[5] ={400,470,560,700,900 }; int NUM_KEYS = 5; int adc_key_in; int key=-1; int oldkey=-1; 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; } void color_r() { led.setColor(255, 0, 0); led.show(); } void color_g() { led.setColor(0, 255, 0); led.show(); } void color_b() { led.setColor(0, 0, 255); led.show(); } void color_y() { led.setColor(255, 255, 0); led.show(); } void color_w() { led.setColor(255, 250, 250); led.show(); } void setup() { pinMode(13, OUTPUT); //we'll use the debug LED to output a heartbeat Serial.begin(9600); // 9600 bps } void loop() { adc_key_in = analogRead(0); // read the value from the sensor digitalWrite(13,LOW); 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) { if(key==0) { color_y(); } if(key==1) { color_b(); } if(key==2) { color_r(); } if(key==3) { color_g(); } if(key==4) { color_w(); } } } } delay(100); }
- 程序效果
按下相應(yīng)按鍵,全彩LED會顯示與按鍵帽相同的顏色。
example3_Arduino
- 主要硬件
- Arduino UNO 控制器
- 傳感器擴展板 V5.0
- 模擬按鍵模塊
- 單頭防插反 3P 傳感器連接線
- USB 數(shù)據(jù)線
- 4WD 移動平臺
- APC220 無線數(shù)傳模塊
- MotorDriver Shield 電機驅(qū)動板
- 示例程序
接收端
#define PWA 3 #define PWB 11 #define DIRA 12 #define DIRB 13 #define BRAKEA 9 #define BRAKEB 8 void setup(){ Serial.begin(9600); pinMode(PWA,OUTPUT); pinMode(PWB,OUTPUT); pinMode(DIRA,OUTPUT); pinMode(DIRB,OUTPUT); pinMode(BRAKEA,OUTPUT); pinMode(BRAKEB,OUTPUT); } void loop(){ if(Serial.available()>0) { char val = Serial.read(); Serial.println(val); if(val == 'r') right(); if(val == 'l') left(); if(val == 'h') head(); if(val == 'b') back(); if(val == 's') stopt(); } } void head(){ analogWrite(PWA,180); analogWrite(PWB,180); digitalWrite(DIRA,HIGH); digitalWrite(BRAKEA,LOW); digitalWrite(DIRB,HIGH); digitalWrite(BRAKEB,LOW); } void back(){ analogWrite(PWA,180); analogWrite(PWB,180); digitalWrite(DIRA,LOW); digitalWrite(BRAKEA,LOW); digitalWrite(DIRB,LOW); digitalWrite(BRAKEB,LOW); } void left(){ analogWrite(PWA,180); analogWrite(PWB,180); digitalWrite(DIRA,HIGH); digitalWrite(BRAKEA,LOW); digitalWrite(DIRB,LOW); digitalWrite(BRAKEB,LOW); } void right(){ analogWrite(PWA,180); analogWrite(PWB,180); digitalWrite(DIRA,LOW); digitalWrite(BRAKEA,LOW); digitalWrite(DIRB,HIGH); digitalWrite(BRAKEB,LOW); } void stopt(){ analogWrite(PWA,0); analogWrite(PWB,0); digitalWrite(DIRA,LOW); digitalWrite(BRAKEA,HIGH); digitalWrite(DIRB,LOW); digitalWrite(BRAKEB,HIGH); }
發(fā)射端
int adc_key_val[5] ={400,470,560,700,900 }; int NUM_KEYS = 5; int adc_key_in; int key=-1; int get_key(unsigned int input) { int k; for (k = 0; k < NUM_KEYS; k++) { while (input < adc_key_val[k]) { return k; } } if (k >= NUM_KEYS)k = -1; // No valid key pressed return k; } void setup() { Serial.begin(9600); // 9600 bps } 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 ==0) Serial.println("r"); if (key ==1) Serial.println("l"); if (key ==2) Serial.println("h"); if (key ==3) Serial.println("b"); if (key ==4) Serial.println("s"); }
- 程序效果
- S3 -- 前進
- S4 -- 后退
- S2 -- 左轉(zhuǎn)
- S1 -- 右轉(zhuǎn)
- S5 -- 停止
資料下載
- 模擬按鍵示例程序下載
鏈接:https://pan.baidu.com/s/1QReHaInd2T2wP7-yzmiSwQ 密碼:g914
- 產(chǎn)品購買鏈接:http://lifestyle201.com/goods-873.html
- 奧松機器人技術(shù)論壇:http://www.makerspace.cn