Key pad help

This is a discussion on Key pad help within the C Programming forums, part of the General Programming Boards category; Working on some basic work for college need a little help in getting a number pad to recognize the numbers ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    3

    Key pad help

    Working on some basic work for college need a little help in getting a number pad to recognize the numbers when pressed on a key pad, The code below is for an ardunio board but its based on C, Can anyone help?

    Code:
    // Pins //
    #define SegA 6 // A
    #define SegB 15 // B
    #define SegC 7 // C
    #define SegD 14 // D
    #define SegE 8 // E
    #define SegF 10 // F
    #define SegG 9 // G
    
    // ports //
    #define PortA 18 // 1
    #define PortB 3 // 2
    #define PortC 19 // 3
    #define PortD 2 // 4
    
    void setup() {
    pinMode(SegA, OUTPUT); 
    pinMode(SegB, OUTPUT);
    pinMode(SegC, OUTPUT);
    pinMode(SegD, OUTPUT);
    pinMode(SegE, OUTPUT);
    pinMode(SegF, OUTPUT); 
    pinMode(SegG, OUTPUT);
    
    // ports //
    pinMode(PortA, OUTPUT);
    pinMode(PortB, OUTPUT);
    pinMode(PortC, OUTPUT);
    pinMode(PortD, OUTPUT);
    
    }
    void loop() {
    // Transistor switches // LEFT
    digitalWrite(PortA, LOW); // Seg 1
    digitalWrite(PortB, LOW);  // SEG 2
    digitalWrite(PortC, LOW); // SEG 3
    digitalWrite(PortD, HIGH); // SEG 4
    
    // 0 //
    digitalWrite(SegA, HIGH);  // A
    digitalWrite(SegB, HIGH); // B
    digitalWrite(SegC, HIGH);  // C
    digitalWrite(SegD, HIGH); // D
    digitalWrite(SegE, HIGH); // E
    digitalWrite(SegF, HIGH); // F
    digitalWrite(SegG, LOW); // G
    delay (1000);
      
    // 1 //
    digitalWrite(SegA, LOW);  // A
    digitalWrite(SegB, HIGH); // B
    digitalWrite(SegC, HIGH);  // C
    digitalWrite(SegD, LOW); // D
    digitalWrite(SegE, LOW); // E
    digitalWrite(SegF, LOW); // F
    digitalWrite(SegG, LOW); // G
    delay (1000);
    
    // 2 //
    digitalWrite(SegA, HIGH);  // A
    digitalWrite(SegB, HIGH); // B
    digitalWrite(SegC, LOW);  // C
    digitalWrite(SegD, HIGH); // D
    digitalWrite(SegE, HIGH); // E
    digitalWrite(SegF, LOW); // F
    digitalWrite(SegG, HIGH); // G
    delay (1000);
    
    // 3 //
    digitalWrite(SegA, HIGH);  // A
    digitalWrite(SegB, HIGH); // B
    digitalWrite(SegC, HIGH);  // C
    digitalWrite(SegD, HIGH); // D
    digitalWrite(SegE, LOW); // E
    digitalWrite(SegF, LOW); // F
    digitalWrite(SegG, HIGH); // G
    delay (1000);
    
    // 4 //
    digitalWrite(SegA, LOW);  // A
    digitalWrite(SegB, HIGH); // B
    digitalWrite(SegC, HIGH);  // C
    digitalWrite(SegD, LOW); // D
    digitalWrite(SegE, LOW); // E
    digitalWrite(SegF, HIGH); // F
    digitalWrite(SegG, HIGH); // G
    delay (1000);
    
    // 5 //
    digitalWrite(SegA, HIGH);  // A
    digitalWrite(SegB, LOW); // B
    digitalWrite(SegC, HIGH);  // C
    digitalWrite(SegD, HIGH); // D
    digitalWrite(SegE, LOW); // E
    digitalWrite(SegF, HIGH); // F
    digitalWrite(SegG, HIGH); // G
    delay (1000);
    
    // 6 //
    digitalWrite(SegA, LOW);  // A
    digitalWrite(SegB, LOW); // B
    digitalWrite(SegC, HIGH);  // C
    digitalWrite(SegD, HIGH); // D
    digitalWrite(SegE, HIGH); // E
    digitalWrite(SegF, HIGH); // F
    digitalWrite(SegG, HIGH); // G
    delay (1000);
    
    // 7 //
    digitalWrite(SegA, HIGH);  // A
    digitalWrite(SegB, HIGH); // B
    digitalWrite(SegC, HIGH);  // C
    digitalWrite(SegD, LOW); // D
    digitalWrite(SegE, LOW); // E
    digitalWrite(SegF, LOW); // F
    digitalWrite(SegG, LOW); // G
    delay (1000);
    
    // 8 //
    digitalWrite(SegA, HIGH);  // A
    digitalWrite(SegB, HIGH); // B
    digitalWrite(SegC, HIGH);  // C
    digitalWrite(SegD, HIGH); // D
    digitalWrite(SegE, HIGH); // E
    digitalWrite(SegF, HIGH); // F
    digitalWrite(SegG, HIGH); // G
    delay (1000);
    
    // 9 //
    digitalWrite(SegA, HIGH);  // A
    digitalWrite(SegB, HIGH); // B
    digitalWrite(SegC, HIGH);  // C
    digitalWrite(SegD, HIGH); // D
    digitalWrite(SegE, LOW); // E
    digitalWrite(SegF, HIGH); // F
    digitalWrite(SegG, HIGH); // G
    delay (1000);
    }
    I was told to use if statements but don't really know how to go about using them, please help thanks

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,915
    The code you supplied seems to be for some kind of display. You do not seem to have anything related to reading keys in this code.

    Jim

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Some actual code might help....

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    3
    we did a display 0 - 9 we where told to use if statements and change the above code to display the number when a key is pressed. I new to c but my lecturer is also an idiot.

    can anyone point me in the right direction?

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by audiomad View Post
    we did a display 0 - 9 we where told to use if statements and change the above code to display the number when a key is pressed. I new to c but my lecturer is also an idiot.

    can anyone point me in the right direction?
    POST CODE... none of us are mind readers...

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    2,915
    The code you posted is only for the display. You need to post the code for all of your code especially the main function and any function dealing with the keypad.


    Jim

  7. #7
    Registered User
    Join Date
    Mar 2011
    Posts
    3
    Quote Originally Posted by jimblumberg View Post
    The code you posted is only for the display. You need to post the code for all of your code especially the main function and any function dealing with the keypad.


    Jim
    that's why I'm asking here I don't understand how to do that with functions

  8. #8
    Registered User
    Join Date
    Mar 2011
    Posts
    1
    Get rid of what you have now and start with this.

    Arduino playground - Keypad Library

    this is the keypad code for the arduino board.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  2. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  3. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 05:42 PM
  4. FAQ: Directional Keys - Useing in Console
    By RoD in forum FAQ Board
    Replies: 38
    Last Post: 10-06-2002, 05:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21