Show Posts
Pages: 1 2 [3] 4 5 ... 13
31  Using Arduino / Programming Questions / Re: A better way to debounce buttons for sending UART keyboard messages. on: September 27, 2013, 12:04:58 pm
There are definitely some things you can do to improve your code but because you need state tracking for the buttons you have the added benefit of already using the best method for debouncing buttons.  You just need to turn your state tracking into a state machine by using a switch/case statement.

I was thinking a button array, possibly.
That's the method I used in the keypad driver.  You can save a lot of space by using the bitRead() and bitWrite() functions found on the Arduino Reference page.

Quote
All the examples I see on the web do not send just a single report when pushing the button down and then another on the release.
That's generally a problem caused by not using a state machine or state tracking.  They can't tell when a button has actually changed so the code gets out of hand very quickly.

Quote
Any ideas or better methods to reduce code? I am also worried about SRAM usage.
Yes, but I'm at work right now so this will be a bit short to start with.

You need to move your state tracking into a separate function that takes the button's previous state and pin number as variables so you can do all your state checking/updating only when called.

As I said above, create a bitMap array of any type of variable that can be used by bitRead() and bitWrite() and use that to store your states for each button.

That will help clean up your code but I would wait until you are through making everything work before you try to reduce ram usage.
32  Using Arduino / Programming Questions / Re: GSM moden library conflict? on: September 13, 2013, 12:20:50 pm
It seems to be a conflict between libraries Keypad and GSM...
Any idea how to solve it?
I made a first attempt at including a namespace in the keypad library which I just attached below.  I did this while at work so I haven't had a chance to test it out.  If you want to use the attached copy of the keypad library then you will need to change the KeyState variables (IDLE, PRESSED, HOLD, or RELEASED) in your sketch to m_key::IDLE, m_key::PRESSED, m_key::HOLD, and m_key::RELEASED.
33  Using Arduino / Programming Questions / Re: Cell number logged with Keypad on: September 05, 2013, 08:06:02 pm
I added waitForKey() to the library a little while ago so you could have just done:
Code:
void User_Int()
{
  lcd.clear();
  lcd.print("Enter Cell no.");
  char Cell_num[10];
  for(int i=0;i<10;i++)
  {
   Cell_num[i]=keypad.waitForKey();
  }
  lcd.print(Cell_num);
  delay(1000);
}
34  Using Arduino / Programming Questions / Re: How To Use digitalRead on Serial Pins 0(RX)/1(TX) on Arduino Uno on: September 03, 2013, 07:39:40 pm
You can use the 4 datalines of the display for other things.
Is the keypad library interrupt driven ? If not, you can perhaps use 4 outputs of the Arduino for both the datalines of the display and also 4 output lines for the keypad. I'm not sure of it, I would have to check the libraries.
You are correct. If matzeatweb is using the Keypad library http://playground.arduino.cc/Code/Keypad and the LiquidCrystal library [Sketch -> Import Library... -> LiquidCrystal] then yes, they are written so that the 4 data pins from the LCD and the Row pins of the keypad can be connected together.
35  Using Arduino / Programming Questions / Re: Can anyone tell me what is the connection with the android in this arduino code on: August 30, 2013, 11:44:46 am
Well, if my assumptions are correct the meetAndroid would connect you to the Android device.

You might want to check out http://www.amarino-toolkit.net/index.php/tutorials.html for tutorials on how to pair with your bluetooth module.  The first tutorial is the First connection and Test Event Tutorial.
36  Using Arduino / Programming Questions / Re: C++ Problem with a Class on: August 08, 2013, 10:42:07 am
mstanley:
Thank you - But I did not want t inherit on purpose:
I want to hide anything from the original class, and be able to "start from scratch",
that's why I chose to contain an object, instead of inheriting the class.

What else can I do?
Then you will need to move
Code:
NECIRrcv*  m_ir;
  outside (ahead) of your class.  That will make your m_ir object have global scope thus making it available to your class.  I believe the wire library uses the same technique to make a global object available.  You can see what I am talking about at the bottom of the Wire.cpp file:
Code:
// Preinstantiate Objects //////////////////////////////////////////////////////

TwoWire Wire = TwoWire();
37  Using Arduino / Programming Questions / Re: C++ Problem with a Class on: August 08, 2013, 10:29:09 am
I tried to do a very simply thing:

To create a simple class, that will be called "IR_Receiver",
which will contain an object of NECIRrcv.

The reason I want to create this class, is in order to add some more methods of mine.
What you need to do is have your class inherit (class inheritance) the NECIRrcv class.  Then you will be able to extend it (extend a class) with your own methods.  What I gave here is a VERY rough example (won't compile, won't run, and may not even teach you anything) in order to give you something to search on.  I've bolded the keywords you'll want to search.

Code:
#include "NECIRrcv.h"
class IR_Receiver : public NECIRrcv {
  public:
// Members:
NECIRrcv*  m_ir;
unsigned long ircode;

//Methods:
IR_Receiver(int);
unsigned long ReceiveIfAvailable();
};

// These two class methods could be placed in the IR_Receiver.cpp file.
// Constructor
IR_Receiver::IR_Receiver(int SetLeg)  {
NECIRrcv ir2(SetLeg);
m_ir  =&ir2;
m_ir->begin();
}

unsigned long IR_Receiver::ReceiveIfAvailable()  {
if(m_ir->available())  {
ircode = m_ir->read();
return ircode;
}
else  {
return 0;    //No Code Available
}
}



void setup()  {
  Serial.begin(9600);
  Serial.println("Up");
}

IR_Receiver O_IR_Receiver(4);
unsigned long IR_Code;

void loop()  {
  IR_Code  O_IR_Receiver.ReceiveIfAvailable();
  if(IR_Code!=0)  {
    Serial.println(IR_Code,HEX);
  }
}
38  International / Français / Re: Librairie keypad.h on: August 05, 2013, 08:50:11 pm
GD Joe Young a prolongé la bibliothèque du clavier avec un port I2C. Vous pouvez le trouver sur github.
https://github.com/joeyoung/arduino_keypads

Google traduit
39  Using Arduino / Programming Questions / Re: Library 'does not name a type' and 'not declared in this scope' on: July 01, 2013, 03:47:51 am
You may have to reset your sketchbook location.  Try going to File->Preferences and setting Sketchbook location: to C:\Documents and Settings\Warren\My Documents\arduino [Note that I didn't include libraries at the end of the path.]

Usually your preferences should last from one update to the next but who knows...
40  Using Arduino / Programming Questions / Re: Interesting discovery - Can you figure out what's wrong? on: June 29, 2013, 07:05:10 am
Unfortunately warnings are disabled in the Arduino compiler
More like "disabled by default".  If you go to File->Preferences and check the box for compilation next to Show verbose output during: then hit verify you get the following compiler output:

Blink.ino: In function 'String test(char, int, String)':
Blink.ino:32: warning: control reaches end of non-void function

Quote
(presumably because it confuses newcomers to programming)world.
I like to think that it protects those of us who like to help from programmers and newcomers who might have O.C.D. smiley-wink
41  Using Arduino / Programming Questions / Re: Function Calls vs Header & .cpp File Manipulations on: June 27, 2013, 10:25:23 am
Quote
When you hit the verify or load button you will see a ram usage report when the compiler is finished

No, that's program memory, thanks though!
Yeah, I guess the word RAM should have been my clue.  smiley-confuse
42  Using Arduino / Programming Questions / Re: Function Calls vs Header & .cpp File Manipulations on: June 27, 2013, 10:01:44 am
When you hit the verify or load button you will see a ram usage report when the compiler is finished.  It isn't perfect but it is useful for comparing different ways of writing your code.

Don't guess about the ram usage, test it.  You may be surprised by how the compiler optimizes your code, or not.

To capture code speed I increment a loop counter to report how many times the loop() was executed each second.  It won't tell you exactly how fast your micro is running but it is a great way to compare different ways of writing the same code.

43  Using Arduino / Programming Questions / Re: make a responsive power saving keypad on: June 24, 2013, 11:33:16 am
[Snip...] when i press two keys one after another only one key is printed.
That's how the keypad is designed.  If you would like to be able to press more than one key at a time then you should check out the Multikey sketch in File->Examples->Keypad->MultiKey.  It shows how to use the function getKeys().
44  Using Arduino / Programming Questions / Re: program does not start when supplied with external power on: June 22, 2013, 05:32:57 pm
I tried it with another sketch and get the same effect. I also tried to reset the Arduino but that did not help to get the sketch started.
Since you are using sleep_mode() in your sketch did you try another sketch without it?

Quote
What's the difference between USB power and external power concerning the starting of a sketch ?
I see that you are using CrossRoads code to connect an interrupt from the keypad.  It may be that there is a voltage difference affecting the interrupt.  Also, the original Arduino NG had a problem where the isolation resistor (R12) was too small so when it was powered by the wall wart it would back-feed power to the ftdi chip causing a glitch every 35 mS and preventing the sketch from starting up.  Can't say I've ever heard of that problem on the UNO, though.
45  Using Arduino / Project Guidance / Re: Wake up from sleep on: June 17, 2013, 11:51:38 am
dc42 is correct.  The keypad library works by polling the pins so if the microcontroller is asleep then the keypad is asleep.  You can wire up some diodes and connect the pins to an external interrupt.  CrossRoads added a hardware interrupt to his keypad and if you scroll down two more posts you'll see his code to go with it.
Pages: 1 2 [3] 4 5 ... 13