Visualizzazione post con etichetta Keypad. Mostra tutti i post
Visualizzazione post con etichetta Keypad. Mostra tutti i post

martedì 13 gennaio 2015

Password inserita da Keypad.


La libreria Password permette di inserire una password da keypad.

      
      
      #include <Password.h> //http://www.arduino.cc/playground/uploads/Code/Password.zip
      #include <Keypad.h> //http://www.arduino.cc/playground/uploads/Code/Keypad.zip
      #include <LiquidCrystal.h>
    
      Password password = Password( "1234" );
    
      LiquidCrystal lcd(8, 9, 10, 11, 12, 13);//pin ARDUINO MEGA 2560
    
      const byte RIGHE = 4; 
      const byte COLONNE = 4; 
      
      char keys[RIGHE][COLONNE] = {{'1','2','3','A'},
                                   {'4','5','6','B'},
                                   {'7','8','9','C'},
                                   {'F','0','E','D'}};
      
      byte rowPins[RIGHE]   = {14, 15, 16, 17}; //pin ARDUINO MEGA 2560
      byte colPins[COLONNE] = {18, 19, 20, 21};;//pin ARDUINO MEGA 2560

      Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, RIGHE, COLONNE );
      
      void setup()
           { lcd.begin(20, 4); 
             keypad.addEventListener(keypadEvent); }
      
     
      void loop(){
     
        keypad.getKey();
        lcd.setCursor(0, 0);
        lcd.print("Ins.Codice e press F");
   
      }//-------------Fine LOOP------------------------------
      
      void keypadEvent(KeypadEvent eKey){
           switch ( keypad.getState())
                  { case PRESSED:
                    switch ( eKey )
                           { case 'F': checkPassword(); 
                             break;
                            case 'E': password.reset();
                             break;
                            default: password.append(eKey);}}
      }//------------ FINE Void -------------------------------
      
      void checkPassword() {
           if ( password.evaluate())
              { lcd.setCursor(0, 1);
                lcd.print("Impianto Inserito   "); }
          else
              { lcd.setCursor(0, 1);
                lcd.print("Codice Errato        ");   }
     
      }//------------ FINE Void -------------------------------

domenica 20 luglio 2014

Pulsantiera su un solo ingresso.


NOTA
Nel listato che segue le resistenze non hanno il valore di cui sopra. Esso si riferisce alla shield LCD della DFRobat con pulsanti.

/*
Una serie di 5 resistenze fanno capo al pin A0.
5 Pulsanti, ciascuno ad ogni pressione cortocircuita una o
più resistenze variando il valore di tensione su A0.

*/
    #include <LiquidCrystal.h>
    
    LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
    
    # define Pulsanti  A0  
    
    long Value=   0;
 
    
    void setup()  
    {  pinMode(Pulsanti, INPUT);    
       lcd.begin(16, 2);       
       Serial.begin(9600);      } 
       
    void loop() {
      
      Value = analogRead(Pulsanti);
       
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("VALUE");
        lcd.setCursor(12, 0);
        lcd.print(Value);
        Serial.print("VALUE  ");
        Serial.println(Value);
    
      if (Value >1020) 
           {lcd.setCursor(13, 0);
            lcd.setCursor(0, 1);
            lcd.print("TASTI OFF "); 
            Serial.print("TASTI OFF  ");  }
      
      if (Value >=0 && Value <=20) 
           {lcd.setCursor(13, 0);
            lcd.setCursor(0, 1);
            lcd.print("TASTI UNO"); 
            Serial.print("TASTI UNO");  }  
            
       if (Value >=90 && Value <=110) 
           {lcd.setCursor(13, 0);
            lcd.setCursor(0, 1);
            lcd.print("TASTO DUE"); 
            Serial.print("TASTO DUE");  }    
   
        if (Value >=240 && Value <=265) 
           {lcd.setCursor(13, 0);
            lcd.setCursor(0, 1);
            lcd.print("TASTO TRE"); 
            Serial.print("TASTO TRE");  }
            
        if (Value >=390 && Value <=415) 
           {lcd.setCursor(13, 0);
            lcd.setCursor(0, 1);
            lcd.print("TASTO QUATTRO"); 
            Serial.print("TASTO QUATTRO");  } 
            
        if (Value >=600 && Value <=700) 
           {lcd.setCursor(13, 0);
            lcd.setCursor(0, 1);
            lcd.print("TASTO CINQUE"); 
            Serial.print("TASTO CINQUE");  }             
            
    delay(300);
    
    }

Breve commento:La pressione di un pulsante varia il valore di una 
delle due resistenze del partitore, non rimane quindi che leggere
 il valore analogico e porre le condizioni "if" se il valore è 
compreso fra -10% e +10% (o altra tolleranza).

giovedì 7 febbraio 2013

KeyInput



#include <Keypad.h>
  const byte ROWS = 4; 
  const byte COLS = 4; 
  char keys[ROWS][COLS] =
  {{'1','2','3','C'},
   {'4','5','6','D'},
   {'7','8','9','E'},
   {'A','0','B','F'}};
  byte rowPins[ROWS] = { 4, 3, 2, 1}; 
  byte colPins[COLS] = { 8, 7, 6, 5}; 
  Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

int ValoreF = 0;
int Valore1 = 123;

void setup() 
   {Serial.begin(9600);}

void loop() {

   char  key = keypad.getKey();

   else 
     {int number = key - 48;
      ValoreF = ValoreF * 10 + number;
      if (Valore1 < ValoreF)
         { Serial.print("OK"); }} 
  }  


Inserire un valore con Keypad, metodo teorico perchè conviene di gran lunga un encoder rotativo o un comune potenziometro.

domenica 2 dicembre 2012

Tastiera.Pilotare uno o più led.

     /*
     author Alexander Brevig

     #include <Keypad.h>

     # define LED1 3
     # define LED2 4
   
     const byte RIGHE    = 4; 
     const byte COLONNE = 4; 
   
     char Tasti[RIGHE][COLONNE] =
       {{'1','2','3','C'},
        {'4','5','6','D'},
        {'7','8','9','E'},
        {'A','0','B','F'}};
      
     byte righe[RIGHE] = {8, 7, 6, 5}; 
     byte colonne[COLONNE] = {12, 11, 10, 9}; 

     // Creazione della tastiera
     Keypad cKeypad = Keypad( makeKeymap(Tasti),
                 righe, colonne, RIGHE, COLONNE); 

     void setup() 
      {pinMode     (LED1, OUTPUT);
       pinMode     (LED2,  OUTPUT);  
       digitalWrite(LED1,   HIGH);
       digitalWrite(LED2,   HIGH);
       Serial.begin(9600);       }
  
   void loop(){
        char Key = cKeypad.getKey();
  
         if (Key)
         {switch (Key)
                  {case 49: //valore ascii del numero 1
                   digitalWrite(LED1, HIGH);
                   break;
                   case 50: //valore ascii del numero 2
                   digitalWrite(LED2, HIGH);
                   break;
                   case 52: //valore ascii del numero 4
                   digitalWrite(LED1, LOW);
                   break;
                   case 53: //valore ascii del numero 5
                   digitalWrite(LED2, LOW);
                   break;     }
          Serial.println(Key);}
 }

Tastiera.Lettura da Keypad


   /*
     KEYPAD R0  R1   R2   R3  C0  C1  C2  C3
     ARDUINO 8   7    6    5   12  11  10  9
     */
     #include <Keypad.h>

     const byte RIGHE   = 4; 
     const byte COLONNE = 4; 
   
     char Tasti[RIGHE][COLONNE] =
       {{'1','2','3','C'},
        {'4','5','6','D'},
        {'7','8','9','E'},
        {'A','0','B','F'}};
      
     byte righe[RIGHE] = {8, 7, 6, 5}; 
     byte colonne[COLONNE] = {12, 11, 10, 9}; 

     // Creazione della tastiera
     Keypad cKeypad = Keypad( makeKeymap(Tasti),
                    righe, colonne, RIGHE, COLONNE); 

     void setup() 
      {Serial.begin(9600); }
  
   void loop(){
        char Key = cKeypad.getKey();
  
         if (Key)
         {Serial.println(Key);}
 }

Se la tastiera in vostro posesso ha altre lettere o numeri diversi basta modificare lo sketch
     char Tasti[RIGHE][COLONNE] =
       {{'1','2','3','C'},
        {'4','5','6','D'},
        {'7','8','9','E'},
        {'A','0','B','F'}};

Per conoscere i pin della tastiera occorre fare riferimento al datasheet.
Solitamente,guardando la tastiera ed iniziando a sinistra: il primo pin è la Colonna0 (C0) a seguire,C2,C3,la Riga0(RO),la R1,R2 ed R3.

E' comunque, con tentativi ed andando ad esclusione scoprire la piedinatura.