Jump to content
43oh

Ditschi93

Members
  • Content Count

    1
  • Joined

  • Last visited

Posts posted by Ditschi93

  1. Hello,

    i want to control relays with my keypad. I work with the Launchpad TM4C123 80MHz.

    i wrote a script but the relay isn´t working. The relay is alright and i don´t know the problem.

    Can anyone help me?

    Quote


    #include <Keypad.h>
    const byte numRows= 4; //number of rows on the keypad
    const byte numCols= 4; //number of columns on the keypad
    //keymap defines the key pressed according to the row and columns just as appears 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] = {PF_3,PB_3,PC_4,PC_5}; //Rows 0 to 3
    byte colPins[numCols]=  {PC_7,PD_6,PD_7,PF_4}; //Columns 0 to 3

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

    int REL = PA_7;

    void setup()
    {
    pinMode(REL,OUTPUT);
      Serial.begin(9600);
      Serial.begin(9600);//sets baud rate for serial communication
    }
    char lastKey=0; 
    void loop() 
    {char keypressed = ourKeypad.getKey();
      if (keypressed != NO_KEY);
      {
        Serial.print(keypressed);
      }
      //} These two line are your problem
      //{
      //char key = keypad.getKey(); // keypad was not declared anywhere, I assume it was meant to be this:
      
      char key = ourKeypad.getKey();
      if (int(key) == 1) {
        digitalWrite(REL, LOW);
        delay(1000);
        digitalWrite(REL, HIGH);
        delay(1000);
      }
    }

     

×
×
  • Create New...