I've changed the code slightly in the CKeypad::GetKey() functions to: char CKeypad::GetKey()įor (int row = 0 row < ROWS & key = 'x' ++row)įor (int col = 0 col < COLS & key = 'x' ++col)Īnd in the main program code setup to add the Serial coms: void setup()Īnd in the main program loop: void loop() I'll draw up a schematic and post that here if that helps. But if I then disable that part of the program and enable the program to read the key press and display the number accordingly and connect the 7-segment to the breadboard and the Arduino to the breadboard then the display will just show complete random data!! This is why a year or so back when I last looked at creating this project I started to use the 74C922 keypad decoder. If I just run the code without connecting the breadboard with the PCF8574 and keypad connected, and enable the code to loop through numbers 0 to 1000000, the 7-segment will happily show the numbers. If (pow((double)10, (double)(count - 1)) įor (int row = 0 row < ROWS & !key ++row)įor (int col = 0 col < COLS & !key ++col) Unsigned int CDisplay::didgitCount(const unsigned long num, const unsigned int max) Returns the number of digits that need to M_pLC->setDigit(addr, 0, (byte)digit1, false) M_pLC->setDigit(addr, 1, (byte)digit2, false) M_pLC->setDigit(addr, 2, (byte)digit3, false) M_pLC->setDigit(addr, 3, (byte)digit4, false) M_pLC->setDigit(addr, 4, (byte)digit5, false) M_pLC->setDigit(addr, 5, (byte)digit6, false) M_pLC->setDigit(addr, 6, (byte)digit7, false) M_pLC->setDigit(addr, 7, (byte)digit8, false) Display the value of each digit in the display Unsigned int digits = didgitCount(number, 8) Void CDisplay::printNumber(int addr, unsigned long number) Void CDisplay::ClearDisplay(int deviceId) Void CDisplay::ShowNumber(int deviceId, unsigned long number) M_pLC = new LedControl(dataPin, clkPin, csPin, numDevices) įor (int addr = 0 addr getDeviceCount() ++addr) #define KEYPAD_ADDR 0x20 // PCF8574 A0, A1, and A2 all groundedĬDisplay m_display(DIN_PIN, CLK_PIN, CS_PIN, NUM_DISPLAYS) ĬDisplay::CDisplay(int dataPin, int clkPin, int csPin, int numDevices) Plus a 5x3 keypad connected via a PCF8574 IC. I could have used a 1-digit 7-segment but I want my eventual project to contain quite a few 7-segment displays. I've got an 8-digit 7-segment display to show the numbers. We would have stopped checking when our result = 0 corresponding to Col#1 and as we were testing for Row#0 we then know that the key pressed is on Col#1 Row#0. We do a BITWISE AND against 0x01 for Col#0 which yields 1, then we do a BITWISE AND against 0x02 for Col#1 which yields 0, and a BITWISE AND against 0x04 which yields 100. If the result = 0 then we have found the column on which the key pressed is held on.įor example, if we pressed key on Col#1 Row#0, so we send the bit pattern: 11110111 to the PCG8574 and receive the bit pattern back as: 11110101. So for each key read, iterate through each of the three columns and do a BITWISE AND for the value read against each of the following values: The column on which the key pressed is held on will have had its 1 bit changed to a 0 bit. Read the PCF8574 and receive the bit pattern, then do a BITWISE AND against: Send a 1 to all three columns and a 0 to the row we're testing for and a 1 for the other, i.e. Iterate through each row, and for each row do: Say we have a 3x5 keypad, and we have the pins connected as follows: It appears to be a mask for the four rows but I'm confused by either the lower bytes & upper bytes being the same between rows. I'll attempt to adjust your code on Saturday for a 5x3 keypad, but in the meantime could you explain the significance of the pcf8574_row_data array? I can see that you have assigned the following values to it: pcf8574 -> 1111 1110 // 0xfe 254 I've been thinking about what the code would look like for a 5x3 keypad (5 rows & 3 columns). If you need help adapting that for 5x3 keys, post your attempt and I can take a look. When you say "appropriate caps", did you have all those?įor scanning a 4x4 keypad with a pcf8574, there is some code on the Playground. The pcf chip should also have a 0.1uF bypass cap. Each max7219 should have a 0.1uF bypass close to its power pins, and a 10uF reservoir cap also. And the keypad did not suffer from interference if the display circuit was disconnected? Sounds like lack of bypass caps to me.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |