Как передать команду с матричной клавиатуры на выполнение исполнительного кода?
- Войдите на сайт для отправки комментариев
Ср, 23/09/2015 - 23:53
Уважаемые форумчане подскажите пожалуйста как передать код с матричной клавиатуры на выполнение команды. По отдельности коды работают правильно.
#include <IRremote.h> //подключение библиотек
IRsend irsend;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'A','B','C','D'},
{'E','F','G','H'},
{'I','J','K','L'},
{'M','N','O','P'}
};
byte rowPins[ROWS] = {10, 9, 8, 7}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6, 5, 4, 11}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
int y = 1; //тип числовых данных
void setup() //инициализация, установка
{
Serial.begin(9600); //инициирует последовательное соединение
//задает скорость передачи данных
}
void loop() //основная работа
{
if (Serial.available() > 0) // если есть доступные данные
{
int x = Serial.read(); // считываем байт
if (x == 49) // выполнять сравнение "x равно числу"
{
y = 1;
}
if (x == 50) {
y = 2;
}
if (y == 1) { // коды кнопок для пульта от телевизора
if (x == 65) {
irsend.sendNEC(0x33b800ff, 32); //A
delay(40);
}
if (x == 66) {
irsend.sendNEC(0x33b8a05f, 32); //B
delay(40);
}
if (x == 67) {
irsend.sendNEC(0x33b8609f, 32); //C
delay(40);
}
if (x == 68) {
irsend.sendNEC(0x807FF00F, 32); //D
delay(40);
}
if (x == 69) {
irsend.sendNEC(0x807F30CF, 32); //E
delay(40);
}
if (x == 70) {
irsend.sendNEC(0x807FB04F, 32); //F
delay(40);
}
if (x == 71) {
irsend.sendNEC(0x807F9867, 32); //G
delay(40);
}
if (x == 72) {
irsend.sendNEC(0x807F58A7, 32); //H
delay(40);
}
if (x == 73) {
irsend.sendNEC(0x807FD827, 32); //I
delay(40);
}
if (x == 74) {
irsend.sendNEC(0x807F38C7, 32); //J
delay(40);
}
if (x == 74) {
irsend.sendNEC(0x807F48B7, 32); //K
delay(40);
}
if (x == 76) {
irsend.sendNEC(0x807FB847, 32); //L
delay(40);
}
if (x == 77) {
irsend.sendNEC(0x807F6897, 32); //M
delay(40);
}
}
Serial.println(x);
//Serial.println(y);
}
{
char customKey = customKeypad.getKey();
if (customKey){
Serial.println(customKey);
}
}
}
http://arduino.ru/Reference/SwitchCase
Что вообще сделать пытаешься? o_0
Мне надо, чтобы код нажатой клавиши например ('A') приводил к выполнению кода
И в чем проблема?
Получай нажатую кнопку (100) и делай switch...case по полученному значению (40-95)
По совету "Получай нажатую кнопку (100)" не получилось. А по другому сложилось:
#include <IRremote.h> //подключение библиотек IRsend irsend; #include <Keypad.h> const byte ROWS = 4; //four rows const byte COLS = 4; //four columns //define the cymbols on the buttons of the keypads char hexaKeys[ROWS][COLS] = { {'A', 'B', 'C', 'D'}, {'E', 'F', 'G', 'H'}, {'I', 'J', 'K', 'L'}, {'M', 'N', 'O', 'P'} }; byte rowPins[ROWS] = {10, 9, 8, 7}; //connect to the row pinouts of the keypad byte colPins[COLS] = {6, 5, 4, 11}; //connect to the column pinouts of the keypad //initialize an instance of class NewKeypad Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); void setup() //инициализация, установка { Serial.begin(9600); //инициирует последовательное соединение //задает скорость передачи данных } //основная работа void loop() { /* Code after this will never be reached */ char customKey = customKeypad.getKey(); switch (customKey) { case 'A': irsend.sendNEC(0x807F08F7, 32); break; case 'B': irsend.sendNEC(0x807F08F7, 32); break; case 'C': irsend.sendNEC(0x807F08F7, 32); break; case 'D': irsend.sendNEC(0x807F08F7, 32); break; case 'E': irsend.sendNEC(0x807F08F7, 32); break; case 'F': irsend.sendNEC(0x807F08F7, 32); break; case 'G': irsend.sendNEC(0x807F08F7, 32); break; case 'H': irsend.sendNEC(0x807F08F7, 32); break; case 'I': irsend.sendNEC(0x807F08F7, 32); break; case 'J': irsend.sendNEC(0x807F08F7, 32); break; case 'K': irsend.sendNEC(0x807F08F7, 32); break; case 'L': irsend.sendNEC(0x807F08F7, 32); break; case 'M': irsend.sendNEC(0x807F08F7, 32); break; case 'N': irsend.sendNEC(0x807F08F7, 32); break; case 'O': irsend.sendNEC(0x807F08F7, 32); break; case 'P': irsend.sendNEC(0x807F08F7, 32); break; } }