Teclat matriu de polsadors
Protocol
Digital I / O o I2C utilitzant Mòdul PCF8574 I2C I/O
Llibreria
Keypad es pot instal·lar directament des del gestor de llibreries
Keypad_I2C si utilitzem el Mòdul PCF8574 I2C I/O
Referències
http://playground.arduino.cc/Main/KeypadTutorial
Preu
0,60 €
Proveïdor
Exemple
/* * aug16a * Teclat matricial amb mòdul PCF8574 I2C I/O * Control Led RGB * Per a ESP8266 NodeMcu 1.0 */#include <Keypad_I2C.h>
#include <Keypad.h>
#include <Wire.h>
#define I2CADDR 0x38
const int ledR = D8;const int ledG = D7;const int ledB = D6;int r,g,b;const byte ROWS = 4; //four rowsconst byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
{'1', '2', '3', 'S'},
{'4', '5', '6', 'G'},
{'7', '8', '9', 'L'},
{'*', '0', '#', 'P'}
};
// Digitran keypad, bit numbers of PCF8574 i/o port
byte rowPins[ROWS] = {0, 1, 2, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad
Keypad_I2C kpd( makeKeymap(keys), rowPins, colPins, ROWS, COLS, I2CADDR, PCF8574 );
void setup() { r=255; g=255; b=255; color(r,g,b); Wire.begin( ); kpd.begin( makeKeymap(keys) );
}
void loop() { char key = kpd.getKey(); if (key) { switch(key){ case '1': r++;
if (r>255) r=255;
break;
case '4':
r--;
if (r<0) r=0;
break;
case '2':
g++;
if (g>255) g=255;
break;
case '5': g--; if (g<0) g=0; break; case '3': b++; if (b>255) b=255; break;
case '6':
b--;
if (b<0) b=0;
break;
case 'S':
r=0; g=0; b=0;
break;
case 'G':
r=255; g=255; b=255;
break;
case '7': r=255; g=0; b=0; break; case '8': r=255; g=50; b=0; break; case '9': r=255; g=100; b=0;
break;
case 'L':
r=0; g=255; b=0;
break;
case '*':
r=0; g=0; b=255;
break;
case '0':
r=100; g=0; b=255;
break;
case '#':
r=255; g=0; b=255;
break;
case 'P':
r=255; g=255; b=255;
break;
}
color (r,g,b);
}
}
void color(int r,int g,int b) {
float lr, lg, lb;
lr=r*180/255;
lg=g*180/255;
lb=b*180/255;
analogWrite (ledR,lr);
analogWrite (ledG,lg);
analogWrite (ledB,lb);
}