Show Posts
Pages: 1 ... 5 6 [7]
91  Using Arduino / Programming Questions / Re: how to manipulate a string ????? on: February 09, 2012, 07:56:23 pm
i was using an example with a 3x4 keypad and i converted it for my 4x4 keypad ! but thanks a lot for your time !
92  Using Arduino / Programming Questions / how to manipulate a string ????? on: February 09, 2012, 06:32:26 pm
Hello to you all !

i have an Arduino Mega 2560 with a 2x16 cld screen and a 4x4 keypad, every thing is ok connected and i runned the dynamickepad example and everything worked just fine.
i am trying to create a text string that i can add or dellete 32 characters from it and eventualy i can print the string to the lcd.
so i messed up with the example, add something here, dellete something there but i can not find a way to make it work.
i am sure that it not the most efficient code, so any suggestion is more than welcome.

Here is the code :
Code:
#include <Keypad.h>

#include <LiquidCrystal.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
// Define the keymaps.  The blank spot (lower left) is the space character.
char alphaKeys[ROWS][COLS] = {
    { 'a','d','g','A' },
    { 'j','m','p','B' },
    { 's','v','y','C' },
    { ' ','.','#','D' }
};

char numberKeys[ROWS][COLS] = {
    { '1','2','3','A' },
    { '4','5','6','B' },
    { '7','8','9','C' },
    { ' ','0','#','D' }
};

boolean alpha = false;   // Start with the numeric keypad.
char* keypadMap = (alpha == true) ? makeKeymap(alphaKeys) : makeKeymap(numberKeys);

byte rowPins[ROWS] = {48, 49, 50, 51}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {40, 41, 43, 42}; //connect to the column pinouts of the keypad

//create a new Keypad
Keypad keypad = Keypad(keypadMap, rowPins, colPins, sizeof(rowPins), sizeof(colPins));

unsigned long startTime;
const byte ledPin = 13;                                                 // Use the LED on pin 13.

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

char* myStrings[32];
int i;
void setup(){
  lcd.begin(16, 2);
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);                                                // Turns the LED on.
  keypad.addEventListener(keypadEvent);                                      // Add an event listener.
  keypad.setHoldTime(500);
}

void loop(){
  char key = keypad.getKey();
    if (alpha && millis()-startTime>100) {           // Flash the LED if we are using the letter keymap.
        digitalWrite(ledPin,!digitalRead(ledPin));
startTime = millis();
    }
}
void keypadEvent(KeypadEvent key) {
    static char virtKey = NO_KEY;      // Stores the last virtual key press. (Alpha keys only)
    static char physKey = NO_KEY;      // Stores the last physical key press. (Alpha keys only)
    static char buildStr[12];
    static byte buildCount;
    static byte pressCount;

    switch (keypad.getState())
    {
    case PRESSED:
        if (isalpha(key)) {              // This is a letter key so we're using the letter keymap.
            if (physKey != key) {        // New key so start with the first of 3 characters.
                pressCount = 0;
                virtKey = key;
                physKey = key;
                myStrings[i] = key;
            }
            else {                       // Pressed the same key again...
                virtKey++;               // so select the next character on that key.
                pressCount++;            // Tracks how many times we press the same key.
                myStrings++;
          }
            if (pressCount > 2) {        // Last character reached so cycle back to start.
                pressCount = 0;
                virtKey = key;
            }
            lcd.print(myStrings);       // Used for testing.
        }
        if (isdigit(key) || key == ' ' || key == '.')  lcd.print(myStrings);
        if (key == '#')  lcd.println();
        break;

    case HOLD:
        if (key == '#')  {                   // Toggle between keymaps.
            if (alpha == true)  {            // We are currently using a keymap with letters
                keypad.begin(*numberKeys);   // and want to change to numbers.
                alpha = false;
                digitalWrite(ledPin, LOW);
            }
            else  {                          // Or, we are currently using a keymap with numbers
                keypad.begin(*alphaKeys);    // and want to change to letters.
                alpha = true;
            }
        }
        else  {                             // Some key other than '#' was pressed.
            buildStr[buildCount++] = (isalpha(key)) ? virtKey : key;
            buildStr[buildCount] = '\0';
            lcd.println();
            lcd.println(buildStr);
        }
        break;

    case RELEASED:
        if (buildCount >= sizeof(buildStr))  buildCount = 0;    // Our string is full. Start fresh.
        break;

    }  // end switch-case
}  // end keypad events


Moderator: CODE TAGS.

AND THIS IS THE COMPILER RESULT :


sketch_feb09b.cpp: In function 'void keypadEvent(KeypadEvent)':
sketch_feb09b:68: error: invalid conversion from 'KeypadEvent' to 'char*'
sketch_feb09b:73: error: lvalue required as increment operand
sketch_feb09b:79: error: call of overloaded 'print(char* [32])' is ambiguous
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:55: note: candidates are: size_t Print::print(char) <near match>
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:56: note:                 size_t Print::print(unsigned char, int) <near match>
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:57: note:                 size_t Print::print(int, int) <near match>
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:58: note:                 size_t Print::print(unsigned int, int) <near match>
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:59: note:                 size_t Print::print(long int, int) <near match>
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:60: note:                 size_t Print::print(long unsigned int, int) <near match>
sketch_feb09b:81: error: call of overloaded 'print(char* [32])' is ambiguous
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:55: note: candidates are: size_t Print::print(char) <near match>
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:56: note:                 size_t Print::print(unsigned char, int) <near match>
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:57: note:                 size_t Print::print(int, int) <near match>
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:58: note:                 size_t Print::print(unsigned int, int) <near match>
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:59: note:                 size_t Print::print(long int, int) <near match>
C:\Users\sakis\Desktop\arduino-1.0\hardware\arduino\cores\arduino/Print.h:60: note:                 size_t Print::print(long unsigned int, int) <near match>

I have no idea what to do ! PLZ HELP !
93  Using Arduino / Programming Questions / Re: Trouble with any sketch that uses a library on: February 09, 2012, 12:57:18 pm
i have the same problem ! transfered the keypad library to where my sketches are saved ! i opened the examples from file - sketchbook - libraries - keypad - examples - CustomKeypad

but still when i compile the sketch i get this problems







CustomKeypad:48: error: redefinition of 'const byte ROWS'
CustomKeypad:11: error: 'const byte ROWS' previously defined here
CustomKeypad:49: error: redefinition of 'const byte COLS'
CustomKeypad:12: error: 'const byte COLS' previously defined here
CustomKeypad:51: error: redefinition of 'char hexaKeys [4][4]'
CustomKeypad:14: error: 'char hexaKeys [4][4]' previously defined here
CustomKeypad:57: error: redefinition of 'byte rowPins [4]'
CustomKeypad:20: error: 'byte rowPins [4]' previously defined here
CustomKeypad:58: error: redefinition of 'byte colPins [4]'
CustomKeypad:21: error: 'byte colPins [4]' previously defined here
CustomKeypad.cpp: In function 'void setup()':
CustomKeypad:63: error: redefinition of 'void setup()'
CustomKeypad:26: error: 'void setup()' previously defined here
CustomKeypad.cpp: In function 'void loop()':
CustomKeypad:67: error: redefinition of 'void loop()'
CustomKeypad:30: error: 'void loop()' previously defined here

i am runing on windos 7 ! Has anyone have an idea why ?
94  Using Arduino / Programming Questions / problem with keypad library? on: February 09, 2012, 12:21:59 pm
I have an arduino mega 2560 i just dowloaded the keypad library and open the first example ( custom keypad) the code is this:
Code:
/* @file CustomKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates changing the keypad size and key values.
|| #
*/
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'0','1','2','3'},
  {'4','5','6','7'},
  {'8','9','A','B'},
  {'C','D','E','F'}
};
byte rowPins[ROWS] = {3, 2, 1, 0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup(){
  Serial.begin(9600);
}
  
void loop(){
  char customKey = customKeypad.getKey();
  
  if (customKey != NO_KEY){
    Serial.println(customKey);
  }
}

but when i compile the program i get this errors :


CustomKeypad:48: error: redefinition of 'const byte ROWS'
CustomKeypad:11: error: 'const byte ROWS' previously defined here
CustomKeypad:49: error: redefinition of 'const byte COLS'
CustomKeypad:12: error: 'const byte COLS' previously defined here
CustomKeypad:51: error: redefinition of 'char hexaKeys [4][4]'
CustomKeypad:14: error: 'char hexaKeys [4][4]' previously defined here
CustomKeypad:57: error: redefinition of 'byte rowPins [4]'
CustomKeypad:20: error: 'byte rowPins [4]' previously defined here
CustomKeypad:58: error: redefinition of 'byte colPins [4]'
CustomKeypad:21: error: 'byte colPins [4]' previously defined here
CustomKeypad.cpp: In function 'void setup()':
CustomKeypad:63: error: redefinition of 'void setup()'
CustomKeypad:26: error: 'void setup()' previously defined here
CustomKeypad.cpp: In function 'void loop()':
CustomKeypad:67: error: redefinition of 'void loop()'
CustomKeypad:30: error: 'void loop()' previously defined here


Is anyone able to help me with that ! I am not that experienced with programming in C ! I am gessing there is something to do with syntax ?????? but i am not so sure . PLZ HELP !

Moderator edit: CODE TAGS added.  You may wish to give your keyboard a good shake - your "?" appears to be stuck down.
95  Using Arduino / Programming Questions / Characters to an LCD. on: February 08, 2012, 02:43:00 am
Hello i am totally new to all that.

I am trying to work with an Arduino and an LCD and i don't know how to print characters on an LCD.

Can any one help me with that ?

thanks
96  Using Arduino / Project Guidance / Re: text tranciver via Arduino on: February 08, 2012, 02:18:16 am
Thank you all for responding so quick.

The range is not that much. 30m to 50m BUT UNDERWATER, so the transmisition would have to be in low frequensy waves ( 15Mhz to 30Mhz ) and that limits my bitrate.

I was thinking to work first with the LCD too but i don't know how to print chars to the Module. Do you have any idea how something like that would hapent?
97  Using Arduino / Project Guidance / text tranciver via Arduino on: February 07, 2012, 05:57:29 pm
hello world !
I am totally new to Arduino ( so new that tommorow i will have my first Arduino in my hands ). I am planning to create a text messaging transiver.

Let me know if i am thinking wrong but my basic thought is to have a standard 16 btn numeral keypad ( 0 to 9 *# A,B,C,D) and have a counter and a timer to each press ( when ever the time is < 1 sec, if the press is to the same btn change a character to an lcd display ). Lock every character to a position in the 2x16 lcd screen. Use A to C to transmit, erase, clear. Now that everything is in order I have to transmite those data via VHF or UHF to an other identicle transiver and the second one blink a red led to show that there is a message and by pressing the D key left on the numpad to show it to the lcd screen.

Te problem is that i know nothing about programming an Arduino and I don't know how to connect all thinks together. I am pretty sure that by the end of this project I will learn a lot but until then I have to depent on the help and the knowledge of more advanced developers.

Hope I am not asking that much from the community.
Thanks in advance for your time.
Pages: 1 ... 5 6 [7]