Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

C / C++ Forum


You are currently viewing our C / C++ Forum as a guest. Please register to participate.
Login



Reply
Old 03-05-2011, 08:05 AM Key pad help
Super Spam Talker

Posts: 755
Name: Barry O' Brien
Location: Ireland
Trades: 0
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);
}
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
audiomad is offline
Reply With Quote
View Public Profile Visit audiomad's homepage!
 
 
Register now for full access!
Old 03-27-2011, 09:34 PM Re: Key pad help (hidden as a bot trap test)
Shey's Avatar
Keeper of the herd

Posts: 1,599
Name: Shey
Location: Behind you, laying my ever corrupting hands upon your shoulders. Soon, you shall be an extension of me.
Trades: 0
Sketch it in Arduino IDE

Here's an example:

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'#','0','*'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

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

void loop(){
char key = keypad.getKey();

if (key != NO_KEY){
Serial.println(key);
}
}



The example above is taken from Keypad Library for Arduino - keypad tutorial. Here's the link: http://arduino.cc/playground/Code/Keypad
__________________
RenditionDigital provides Software Development, Games Development, Digital Publishing, Social Media moderation in all flavors-
Please login or register to view this content. Registration is FREE
. What is software engineering? There is a great group of highly skilled tech people
Please login or register to view this content. Registration is FREE
. |Also visit My Blog
Please login or register to view this content. Registration is FREE
Shey is offline
Reply With Quote
View Public Profile Visit Shey's homepage!
 
Reply     « Reply to Key pad help
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12325 seconds with 11 queries