Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 3 months ago.
I keep getting the same error 289 in using Keypad.h
I'm trying to figure out why I keep getting this error when using Keypad.h. It says No instance of constructor "Keypad::Keypad matches the argument list "Keypad keypad(R0,R1,R2,R3,C0,C1,C2);"
Below is my code:
- include "mbed.h"
- include "Keypad.h"
DigitalOut R0 (PA_0); DigitalOut R1 (PA_1); DigitalOut R2 (PA_4); DigitalOut R3 (PB_0); DigitalIn C0 (PA_8); DigitalIn C1 (PB_10); DigitalIn C2 (PB_4);
char Keytable [12] = { C0, C1, C2 '1', '2', '3', R0 '4', '5', '6', R1 '7', '8', '9', R2 '*' ,'0', '#' R3 }; uint32_t Index;
uint32_t cbAfterInput(uint32_t index) { Index = index; return 0; }
int main() { R0 R1 R2 R3 C0 C1 C2 Keypad keypad(R0,R1,R2,R3,C0,C1,C2); keypad.attach(&cbAfterInput); keypad.start();
while (1) { wfi(); printf("Interrupted\r\n"); printf("Index:%d => Key:%c\r\n", Index, Keytable[Index]); } }
And this is the Keypad.h file if you need it:
/* mbed Keypad library, using user-defined interrupt callback
- Copyright (c) 2012 Yoong Hor Meng
- Permission is hereby granted, free of charge, to any person obtaining
- a copy of this software and associated documentation files (the
- "Software"), to deal in the Software without restriction, including
- without limitation the rights to use, copy, modify, merge, publish,
- distribute, sublicense, and/or sell copies of the Software, and to
- permit persons to whom the Software is furnished to do so, subject to
- the following conditions:
- The above copyright notice and this permission notice shall be included
- in all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
- /
- ifndef KEYPAD_H
- define KEYPAD_H
- include "mbed.h"
- include "FPointer.h"
/**
- An interrupt-based interface to 4x4 keypad.
- On each key pressed on a keypad, the index of the key is passed to a
- user-defined function. User is free to define what to be done with the
- input.
- Example:
- @code
- #include "mbed.h"
- #include "Keypad.h"
- Define your own keypad values
- char Keytable[] = { '1', '2', '3', 'A', r0
- '4', '5', '6', 'B', r1
- '7', '8', '9', 'C', r2
- '*', '0', '#', 'D' r3
- };
- c0 c1 c2 c3
- uint32_t Index;
- uint32_t cbAfterInput(uint32_t index) {
- Index = index;
- return 0;
- }
- int main() {
- r0 r1 r2 r3 c0 c1 c2 c3
- Keypad keypad(p21, p22, p23, p24, p25, p26, p27, p28);
- keypad.attach(&cbAfterInput);
- keypad.start(); energize the keypad via c0-c3
- while (1) {
- wfi();
- printf("Interrupted\r\n");
- printf("Index:%d => Key:%c\r\n", Index, Keytable[Index]);
- }
- }
- @endcode
- /
class Keypad { public: / Create a 4x4 (row, col) or 4x3 keypad interface:
- | Col0 | Col1 | Col2 | Col3
-++++-- Row 0 | x | x | x | x
- Row 1 | x | x | x | x
- Row 2 | x | x | x | x
- Row 3 | x | x | x | x
- @param row<0..3> Row data lines
- @param col<0..3> Column data lines
- @param debounce_ms Debounce in ms (Default to 20ms)
- / Keypad(PinName r0, PinName r1, PinName r2, PinName r3, PinName c0, PinName c1, PinName c2, PinName c3, int debounce_ms = 20);
/ Destructor
- / Keypad();
/ Start the keypad interrupt routines
- / void start(void);
/ Stop the keypad interrupt routines
- / void stop(void);
/ User-defined function that to be called when a key is pressed
- @param fptr A function pointer takes a uint32_t and
- returns uint32_t
- / void attach(uint32_t (*fptr)(uint32_t));
protected: InterruptIn *_rows[4]; DigitalOut *_cols[3]; int _debounce; miliseconds int _nRow; int _nCol; FPointer _callback; Called after each input
void _checkIndex(int row, InterruptIn *therow); void _cbRow0Rise(void); void _cbRow1Rise(void); void _cbRow2Rise(void); void _cbRow3Rise(void); void _setupRiseTrigger(void); };
- endif KEYPAD_H
I just can't figure out why this one error keeps happening.