Show Posts
Pages: 1 ... 5 6 [7] 8 9 ... 12
91  Using Arduino / Programming Questions / Re: Getting Error:- 'INPUT_PULLUP' was not declared in this scope on: January 11, 2013, 06:59:25 pm
Hi tack,
This is an error being received with a library, so it's not code in my sketch. I guess I could go and modify all the INPUT_PULLUP uses in the library to PinMode(pin, INPUT) and digitalWrite(pin, HIGH) but I was hoping there was a more elegant solution, such as updating the mighty1284P core files so I don't have to change the library every time an update is released.

If you don't mind running a quick test for me...

Change line 46 in keypad.h from:
Code:
#if defined(ARDUINO) && ARDUINO < 101

to:
Code:
#if !defined INPUT_PULLUP

And see if it works for you.  If so then I will update the library so you won't have to mess around with it.

-Mark Stanley
92  Using Arduino / Displays / Re: a simple 32 character text writer with 4 keys, detect still pressed ? on: December 21, 2012, 08:06:41 pm
This is great news and I'm really surprised that it works with v22 of the Arduino software.  I attempted to maintain backward compatibility but in truth I never tested the library on anything older than Arduino 1.0.

Thanks for the info.  It gives me greater confidence. smiley-wink
93  Using Arduino / Displays / Re: a simple 32 character text writer with 4 keys, detect still pressed ? on: December 19, 2012, 09:20:29 pm
Hi Boffin1,
I tried including  KeyState getState()   but it says its not declared in this scope but it looks like a function of Keypad.h ?

Is there another option to if (key)   that will not cause debounce hassles ?
You were correct in assuming that getState() is what you would use to solve your problem.  It returns one of four states IDLE, PRESSED, HOLD, or RELEASED which you can test, eg.

Code:
  if ( kpd.getState() == HOLD ) {
      // reset your repeat timer
  }
I don't understand why you are getting a scope problem, though.  The function is public and you should be able to use it.  Can you show me an example of what you wrote when it gave you the compile error?
94  Using Arduino / Programming Questions / Re: Editing a Library on: December 19, 2012, 08:59:19 pm
Hi euphoricnoise, sorry about the late reply but I am just getting over the flu.

-I am trying to build a 16 buttonpad MIDI controller using the sparkfun 4x4 board (https://www.sparkfun.com/products/7835?)
-Right now, the controller can take in one button input and output one thing (monophonic)
-I am trying to program the arduino so more than one button input can be taken in (polyphonic)

The latest version, 3.0, of the keypad library supports up to 10 active keys all being pressed at the same time.  I wanted to give you an example but I see that I botched the upload so the multikey example included with the library download is completely off the mark.

I've included my initial draft of that example here.  Two things to notice are that you should use kpd.getKeys() for scanning multiple key presses and that you will get a list of keys in the kpd.key[] array.

The array kpd.key[] is an array containing keys that have the following members:

  char kchar;
  KeyState kstate;            // IDLE, PRESSED, HOLD, RELEASED
  boolean stateChanged;


Hopefully this is enough to get you going on your project.  I will work on the multikey example over the holidays and see if I can update the Keypad page http://playground.arduino.cc/Code/Keypad too.

Code:
/* @file MultiKey.ino

#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 kpd
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the kpd

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

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

void loop(){

  // Fills kpd.key[] array with up-to 10 active keys.
  // Returns true if there are ANY active keys.
  if (kpd.getKeys())
  {
    for (int i=0; i<LIST_MAX; i++)   // Scan the entire list.
    {
      if (kpd.key[i].kchar != NO_KEY)    // Test for an active key.
      {
        switch (kpd.key[i].kstate) {  // Test for key state IDLE, PRESSED, HOLD, or RELEASED
            case HOLD:
                Serial.print("Key ");
                Serial.print(kpd.key[i].kchar);
                Serial.print(" is being HELD and the state ");
                if (!kpd.key[i].stateChanged)
                    Serial.println("has not changed.");
                else
                    Serial.println("has changed.");
                break;
            case PRESSED:
                Serial.print("Key ");
                Serial.print(kpd.key[i].kchar);
                Serial.print(" is PRESSED and the state ");
                if (!kpd.key[i].stateChanged)
                    Serial.println("has not changed.");
                else
                    Serial.println("has changed.");
                break;
            case RELEASED:
                Serial.print("Key ");
                Serial.print(kpd.key[i].kchar);
                Serial.print(" has been RELEASED and the state ");
                if (!kpd.key[i].stateChanged)
                    Serial.println("has not changed.");
                else
                    Serial.println("has changed.");
                break;
            default:
                Serial.print("Key ");
                Serial.print(kpd.key[i].kchar);
                Serial.print(" is IDLE and the state ");
                if (!kpd.key[i].stateChanged)
                    Serial.println("has not changed.");
                else
                    Serial.println("has changed.");
        }
      }
    }
  }
}  // End loop
95  Community / Exhibition / Gallery / Re: Low power consumption (0.1 uA) but wake up on keypad press on: December 06, 2012, 10:38:14 pm
Hi Nick & Everyone,

  I've been following this post with great interest. Of course I'm finding the low power stuff to be very interesting but equally as important I was discovering what impact my changes have made between the two versions of the library.

Nick:  You are using version 1.8 of the library (Keypad2) which had the original problem with shorted pins when pressing multiple keys. Since then I've implemented your suggestions so the latest version, 3.0, includes those fixes.

Zigmund:  Along the way I figured out that I could drastically improve the number of times the loop runs per second by restricting the number of calls to the library to once every 10 milliseconds (mS) by default. The default can be changed by setDebounceTime(1) which sets the debounce time to 1mS which is the minimum.  By reducing the debounce time it allows getKey() to be called more frequently.  I would love to hear how it affects the responsiveness when using version 3.0 of the library.  I may need to change my method of limiting.
96  Using Arduino / LEDs and Multiplexing / Re: How to use this keypad? on: November 13, 2012, 07:50:50 pm
Hi feveran,

  I wonder if you could tell me what it is you want to accomplish?  Do you want to learn how to make this hardware work or are you just interested in using it for your project?  I can help either way but I am asking because I don't want to take over your project.  I can write the code to make the buttons and joystick work but if that is what you are interested in doing then I can teach you how to write the code and understand the hardware.

  What do you think?

-Mark
97  Using Arduino / LEDs and Multiplexing / Re: How to use this keypad? on: November 08, 2012, 01:45:50 pm
This is a very interesting piece of kit.  A PDF of the schematic is here http://www.wvshare.com/downloads/accBoard/5-IO-Keypad.7z.

Because this board contains keys and a joystick you'll need to be just a bit more careful with your programming logic.  But in general what you need to do is...

1.  Wire up the board. Leave board pin 1 unconnected (it doesn't do anything). Connect board pin 2 to arduino GND pin.  Connect board pins IO1 thru IO5 to arduino pins 2 thru 6 them in any order.

2.  In setup() you'll need to enable the internal pullup resistors with pinMode(pinNum, INPUT_PULLUP).

3.  Create a readAllPins() function that does a digitalRead() on each of the arduino pins 2 thru 6 one at a time.

4.  Create a scanKeys() function that does a digitalWrite(pinNum, LOW) on each of the arduino pins 2 thru 6 one at a time and in order.  Then for each arduino pin that you digitalWrite(pinNum, LOW) call your readAllPins() function and store the values into a variable.

5.  Inside loop():  Call your read function first and if any pin is low that means the joystick is being used. You can tell which direction by the arduino pin number that reads low.  If all pins are high then call your scanKeys() function to see if any buttons are being pressed.

You can't use the keys and the joystick at the same time and there's no debouncing. All that can be fixed later once you are more familiar with what I wrote above.

Let me know if you need more detail.  I wouldn't mind playing with the code for this.

98  Using Arduino / Project Guidance / Re: Just not working the way it should on: November 03, 2012, 09:32:51 pm
Code:
  if(key)  // Check for a valid key.
I'd prefer to see this explicitly stated:
Code:
  if(key != NO_KEY)  // Check for a valid key.

Hi Paul,

  I originally had NO_KEY explicitly stated but someone got confused so I changed it to what you see now.  Originally I thought it was a good idea to be explicit but do you mind if I ask why you prefer it that way?

-Mark
99  Using Arduino / Programming Questions / Re: code for 4*4 keypad on: October 28, 2012, 09:55:05 pm
I think the example, DynamicKeypad, that I wrote is almost exactly what you are looking for.

Keypad library download http://arduino.cc/playground/Code/Keypad#Download.

Once you have the library installed you can open the example from File->Examples->Keypad->DynamicKeypad.
100  Using Arduino / Project Guidance / Re: Multiplexing input/output consoles to one Arduino? on: October 01, 2012, 08:11:45 pm
The LCD and Keypad libraries both support mulitiplexing.  You simply share any (or all) of the LCD data pins with the keypad row pins and there's no need for additional hardware.  I've had this working many times.  I'm not sure about the LCD control pins.  You'll have to check the library to find out, or you can just try it.

There's no reason most libraries couldn't support some muxing.  All the library has to do is reset its (muxable) pins each time before use, instead of just once in setup().  Then just tell the sketch authors which pins they can share.
101  Using Arduino / Project Guidance / Re: Compile error with Keypad Library on: August 15, 2012, 12:10:43 pm
This is what I get when I try to compile Hello Keypad :
C:\Temp\Arduino101\libraries\Keypad\Keypad.cpp: In member function 'bool Keypad::scanKeys()':
C:\Temp\Arduino101\libraries\Keypad\Keypad.cpp:86: error: 'INPUT_PULLUP' was not declared in this scope

I put the following in Keypad.h so I'm not sure why you get that error. The code checks to see which version of Arduino you are using and then defines INPUT_PULLUP if you have any version less than 1.0.1.

Code:
// See http://code.google.com/p/arduino/issues/detail?id=246
#if defined(ARDUINO) && ARDUINO < 101
#define INPUT_PULLUP INPUT
#endif

Are you having problems with any other libraries?
102  Using Arduino / Project Guidance / Re: Voltage drop across adjustable regulator on: August 11, 2012, 08:37:36 am
Wow! I have no idea how I missed that.   <<scratches head>>
103  Using Arduino / Project Guidance / Re: Voltage drop across adjustable regulator on: August 10, 2012, 06:21:23 pm
Before you do anything else you need to add capacitors to the input and output of the regulator.  You should be able to find a data sheet on your part which will show the capacitors needed for proper regulation.

Or else you can try 10uF electrolytics on both pins and see if it just works.
104  Using Arduino / Project Guidance / Re: Voltage drop across adjustable regulator on: August 10, 2012, 09:46:22 am
It would really help if I could see your circuit but you need to have input/output capacitors connected to the regulator.

Another possibility is that you are momentarily exceeding the current rating for the regulator.  Most three terminal regulators have short circuit protection and will shut off the output.  With the output pulsing on/off your meter would display the average.
105  Using Arduino / Audio / Re: MIDI Keyboard Encoder - Arduino Piano/Keyboard (question) on: August 08, 2012, 11:56:50 am
To achieve step 3, you need matrix scanning code (which is what the Keypad library is). As a bonus, the way it is written eliminates the need for the diodes in your wiring diagram, hence the simpler
sammyg, you are correct that the diodes are not required for preventing shorts between keys on keypads and keyboards.  But there is another problem called shadowing where some combinations of multiple keypresses will cause the keyboard driver to think that an extra key is being pressed when it is not.  That would mean an extra note would be added to the chord.  The solution is to place a diode across every key.  All midi keyboards should already have the diodes but if op builds his own he should add them.
Pages: 1 ... 5 6 [7] 8 9 ... 12