“SKU:RB-02S159 模擬鍵盤模塊”的版本間的差異
來(lái)自ALSROBOT WiKi
(→?example3_Arduino) |
(→?資料下載) |
||
(未顯示1個(gè)用戶的2個(gè)中間版本) | |||
第356行: | 第356行: | ||
:S5 -- 停止 | :S5 -- 停止 | ||
? | == | + | ==資料下載== |
[[文件:erweima.png|230px|無(wú)框|右]] | [[文件:erweima.png|230px|無(wú)框|右]] | ||
* 模擬按鍵示例程序下載 | * 模擬按鍵示例程序下載 | ||
? | 鏈接:https://pan.baidu.com/s/ | + | 鏈接:https://pan.baidu.com/s/1i2nLla1HmTKN5EYAHERvKw |
+ | 提取碼:2u42 | ||
* 產(chǎn)品購(gòu)買鏈接:http://lifestyle201.com/goods-873.html | * 產(chǎn)品購(gòu)買鏈接:http://lifestyle201.com/goods-873.html | ||
+ | * 奧松機(jī)器人技術(shù)論壇:http://www.makerspace.cn |
2021年12月10日 (五) 10:41的最后版本
目錄 |
產(chǎn)品概述
奧松機(jī)器人新推出的模擬鍵盤模塊,我們?cè)谠O(shè)計(jì)按鍵輸入電路時(shí),采用獨(dú)立IO連接按鍵或者矩陣連接的方式,矩陣連接相對(duì)于獨(dú)立連接的方式來(lái)說(shuō)占用IO相對(duì)較少,但有沒(méi)有一種更好的方式呢,模擬鍵盤模塊就很好的解決了這個(gè)問(wèn)題,它能讓你用一個(gè)模擬IO口,實(shí)現(xiàn)五個(gè)按鍵狀態(tài)的讀取,真正實(shí)現(xiàn)了電路的簡(jiǎn)化,并且在按下按鍵時(shí),按鍵旁的LED會(huì)隨之亮起。
產(chǎn)品參數(shù)
基本參數(shù)
- 品名:模擬按鍵模塊
- 貨號(hào):RB-02S159
- 尺寸:55*40mm
- 固定孔:M3*4
電氣性能
1.工作電壓:3.3V~5V
2.工作溫度限值:-20℃ ~ +70℃
3.信號(hào)類型:模擬信號(hào)
4.接口類型:3P 防插反接口
5.工作電流:小于等于20mA,5V 供電下
6.按鍵及指示燈:S1 ~ S5 五個(gè)按鍵旁分別配有指示燈,按下時(shí)亮起
7.按鍵模擬值:
- S1=380±40
- S2=470±40
- S3=560±40
- S4=680±40
- S5=840±40
8.引腳定義:
- +:電源正極
- -:電源負(fù)極
- S:信號(hào)
使用方法
example1_Arduino
- 主要硬件
- Arduino UNO 控制器
- 傳感器擴(kuò)展板 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 控制器
- 傳感器擴(kuò)展板 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會(huì)顯示與按鍵帽相同的顏色。
example3_Arduino
- 主要硬件
- Arduino UNO 控制器
- 傳感器擴(kuò)展板 V5.0
- 模擬按鍵模塊
- 單頭防插反 3P 傳感器連接線
- USB 數(shù)據(jù)線
- 4WD 移動(dòng)平臺(tái)
- APC220 無(wú)線數(shù)傳模塊
- MotorDriver Shield 電機(jī)驅(qū)動(dòng)板
- 示例程序
接收端
#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 -- 前進(jìn)
- S4 -- 后退
- S2 -- 左轉(zhuǎn)
- S1 -- 右轉(zhuǎn)
- S5 -- 停止
資料下載
- 模擬按鍵示例程序下載
鏈接:https://pan.baidu.com/s/1i2nLla1HmTKN5EYAHERvKw 提取碼:2u42
- 產(chǎn)品購(gòu)買鏈接:http://lifestyle201.com/goods-873.html
- 奧松機(jī)器人技術(shù)論壇:http://www.makerspace.cn