Banner Ausblenden
Kleines Logo

Willkommen auf PSI-Online

Keypad

Hier möchte ich das Bauteil Keypad vorstellen und euch ein kleines Beispiel-Programm zeigen.

Damit das Programm funktioniert, muss die Datei Keypad.h auf der library vorhanden sein.Die Datei könnt ihr hier downloaden http://playground.arduino.cc/code/Keypad

Die Datei müsst ihr natürlich noch Entpacken und in den library-Ordner auf eurem Computer verschieben.

Keypadbild

int green = 13;

int yellow= 12;                                                                                                    

int red = 11;                               


#include 

 

const byte numRows= 4; //number of rows on the keypad

const byte numCols= 4; //number of columns on the keypad
char keymap[numRows][numCols]=
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};

//Code that shows the the keypad connections to the arduino terminals
byte rowPins[numRows] = {9,8,7,6}; //Rows 0 to 3
byte colPins[numCols]= {5,4,3,2}; //Columns 0 to 3

//initializes an instance of the Keypad class
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

void setup(){

  pinMode(green,OUTPUT);
  pinMode(red,OUTPUT);
  pinMode(yellow,OUTPUT);


 
Serial.begin(9600);
}

//If key is pressed, this key is stored in 'keypressed' variable
//If key is not equal to 'NO_KEY', then this key is printed out
//if count=17, then count is reset back to 0 (this means no key is pressed during the whole keypad scan process
void loop()
{
  ROT();
  GELB();
  GRUEN();

}

void ROT () {
char keypressed = myKeypad.getKey();
if (keypressed != NO_KEY)
{
Serial.println(keypressed);
}
  if(keypressed == '3'){
  digitalWrite(red,HIGH);
  delay(1000);
  digitalWrite(red,LOW);
}
}

void GELB () {
char keypressed = myKeypad.getKey();
if (keypressed != NO_KEY)
{
Serial.println(keypressed);
}
  if(keypressed == '2'){
  digitalWrite(yellow,HIGH);
  delay(1000);
  digitalWrite(yellow,LOW);
}
}

void GRUEN () {
char keypressed = myKeypad.getKey();
if (keypressed != NO_KEY)
{
Serial.println(keypressed);
}
  if(keypressed == '1'){
  digitalWrite(green,HIGH);
  delay(1000);
  digitalWrite(green,LOW);
}
}

 


 

 

Erstellt: Andreas Hecker (05.12.2014) Letzte Änderung: David Gu (16.12.2014)