Show Posts
Pages: 1 ... 20 21 [22] 23 24 ... 197
316  Using Arduino / Programming Questions / Re: Feasibility of a temperature gauge on: February 20, 2014, 07:38:12 pm
Why not use an LCD screen instead of a servo? I have a code that you can modify to work with a TFT screen.
317  Development / Other Software Development / Re: New TFT Extension Library on: February 20, 2014, 06:35:06 pm
@PaulS

Is there anyway I can make the precompiler detect if someone actually has the UTFT or UTouch libraries and then have the precompiler determine what lines to enable for the library to work?
318  Using Arduino / Project Guidance / Re: password activated garage on: February 20, 2014, 06:22:25 pm
This is what you need.

Note: This is pseudo code.
Code:
#define Password_Lenght 4
char Data[Password_Lenght + 1]; // 4 is the number of chars it can hold + 1 for NULL char
byte idx = 0;
.
.
.
  // this could be in your loop() or its own function.
  customKey = customKeypad.getKey(); // my method, but you can use eKey instead
  if (customKey) // check if a key is actually pressed.
  {
      if( currentKey == Password_Lenght  + 1)
      {
          checkPassword( Data );
          currentKey = 0;
      }
      else
      {
          Data[ currentKey ] = customKey; // currentKey is first set to 0.
          Data[ currentKey++ ] = '/0';  // Add a null char to the end if needed and increment currentKey every time you enter a new key.
      }
  }
.
.
.
void checkPassword( char * myPass)
{
  PWs[ idx ].append( myPass ); // idx = 0
  if (PWs[ idx ].evaluate()) 
    // show password is good message
  else  idx++;

  if( idx == (Password_Lenght - 1) ) // if idx has reached the maximum number of passwords, show message "password was not found".
}

You can also use "idx" to switch case statements for your motors. Once the password is checked either good or not found, and your done with your motors, you need to reset idx back to 0.
319  Using Arduino / Project Guidance / Re: password activated garage on: February 20, 2014, 05:28:56 pm
This is wrong.
Quote
Password PWs[ 3 ] = { "1103", "1102", "1101" };


You need this, don't change anything here.
Code:
Password password = Password( "1103" ); //password to unlock box, can be changed
Password password2 = Password ("C");
Password password3 = Password ("1102");

Password PWs[ 3 ] = { password, password2, password3 };

Where is the part or function that collects the chars for your password?
Quote
you'll need to make a new char array to hold the password, then put it into the append( ) function.
320  Using Arduino / Project Guidance / Re: password activated garage on: February 20, 2014, 04:48:46 pm
Quote
Password password = Password( "1103" ); //password to unlock box, can be changed
 Password password2 = Password ("C");
 Password password3 = Password ("1102");

Password PWs[ 3 ] = { password, password2, password3 };
Thats it for that part.

Where you put it is up to you, you can make a new function or put it in the main loop() function.
321  Using Arduino / Project Guidance / Re: password activated garage on: February 20, 2014, 03:44:57 pm
You first need an array, like so.
Password PWs[ 3 ] = { password, password2, password3 };

Next, instead of putting the password directly into password.append(eKey); , you'll need to make a new char array to hold the password, then put it into the append( ) function.

Finally, you need to evaluate each password and if the password does not match increment the password array.
Code:
if (PWs[ idx ].evaluate()) 
  // show password is good message

else  idx++;

if( idx == 3 ) // if idx has reached the maximum number of passwords, show password was not found.
322  Using Arduino / Project Guidance / Re: password activated garage on: February 20, 2014, 02:09:30 pm
You have 3 passwords yet looking at your code, your only checking the first one.
323  Using Arduino / Programming Questions / Re: Store status of previous key pressed on: February 20, 2014, 02:39:18 am
Why do you have all those read lcd button lines? They are not needed, all you need is the first one. That "glitter" is what happens when you rapidly clear the screen and show a new value over and over again.
324  Using Arduino / Programming Questions / Re: Store status of previous key pressed on: February 20, 2014, 02:11:23 am
Ahh, I forgot that when no button is pressed, it outputs 5. So what you do is add "&& button !=  btnNONE" to "if(button != prev_button)" and it will work.
325  Using Arduino / Programming Questions / Re: Store status of previous key pressed on: February 20, 2014, 01:49:43 am
 smiley-roll

Code:
int prev_button = -1; // set globally at top of code
.
.
.
void lcd_call()
{
  int button = read_LCD_buttons();
  if(button != prev_button)
  {
    prev_button = button;
  }

  if (prev_button == left)
  {
    digitalClockDisplay();
  }
  else if(prev_button == right)
  {
    Display_angle();
  }
  else if(prev_button == up)
  {
    Display_coordinate();
  }
  else if(prev_button == down)
  {
    button_loop();
  }
  else
  {
    digitalClockDisplay();
  }

} // end of function

It would be more presentable if you used case statements instead of all the IF/ELSE statements for your functions.
326  Using Arduino / Programming Questions / Re: Store status of previous key pressed on: February 20, 2014, 01:25:57 am
I understand what you want to do. But you need to follow the comments I gave you. Do you know what a global variable is, and why are you using labels?
327  Using Arduino / Programming Questions / Re: advice on defining variables on: February 20, 2014, 01:18:21 am
Liudr beat me to it.

Your map function doesn't look right.
Quote
char  range = map(key, UL, LL, 0, 3);
Why are UL and LL type char and arrays? Why do they have no initial value? What is the highest and lowest values UL and LL are supposed to represent?

Why not just switch using "key" and look for the key pressed, '1' - '#' ?
328  Using Arduino / Programming Questions / Re: Store status of previous key pressed on: February 20, 2014, 12:53:50 am
Quote
Is it right syntax
Nope.

Quote
void lcd_call()
{
int button=0;  // Ok
int prev_button=0; // No, this will overwrite prev_button and it will not remember what the button previously was. Take it out and make it global.
button = read_LCD_buttons(); // Ok
if (button!=btnNONE) // add spaces for clarity, what does btnNONE equal, -1, 0,  '/0' ?
{
  goto labe1; //NO!!! Labels are not needed, especially not for something as simple as this.
}else // separate them on new lines
{
 prev_button= button; // When do you compare button to prev_button?
}
label:serial.println("hello"); // Again, don't use labels.

329  Using Arduino / Project Guidance / Re: Keypad door lock reset on: February 20, 2014, 12:45:18 am
Maybe this will help you. I don't expect you to have the libraries that are used in this sketch, its is merely just an example.

Code:
/*
 || @version 1.0
 || @author Andrew Mascolo
 ||
 || @description
 || Simple use of keypad, password and LCD
 */
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define Password_Lenght 7 // Give enough room for six chars + NULL char

LiquidCrystal_I2C lcd(0x20,20,4);
char Data[Password_Lenght]; // 6 is the number of chars it can hold + the null char = 7
char Master[Password_Lenght] = "123456";
byte data_count = 0, master_count = 0;
boolean good;
char customKey;

const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};

byte rowPins[ROWS] = {
  2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
  10,9,8}; //connect to the column pinouts of the keypad

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

void setup(){
  lcd.init();// initialize the lcd
  lcd.backlight();
}

void loop()
{
  lcd.setCursor(0,0);
  lcd.print("Enter Password");
 
  customKey = customKeypad.getKey();
  if (customKey) // makes sure a key is actually pressed, equal to (customKey != NO_KEY)
  {
    Data[data_count] = customKey; // store char into data array
    lcd.setCursor(data_count,1); // move cursor to show each new char
    lcd.print(Data[data_count]); // print char at said cursor
    data_count++; // increment data array by 1 to store new char, also keep track of the number of chars entered
  }

  if(data_count == Password_Lenght-1) // if the array index is equal to the number of expected chars, compare data to master
  {
    if(!strcmp(Data, Master)) // equal to (strcmp(Data, Master) == 0)
      good = true;
    else
      good = false; 

    lcd.setCursor(0,0);
    delay(1000); // added 1 second delay to make the password completely show on screen before it gets cleared.
    if(good) // equal to (good == true)
    {
      lcd.clear(); //clear the screen for new message
      lcd.print("Password is good");
      delay(1000);
      lcd.clear(); // clear the screen for next use
      clearData(); // reset the array holding the user password
    }
    else
    {
      lcd.clear(); // same as above
      lcd.print("Password is bad");
      delay(1000);
      lcd.clear(); // same as above
      clearData(); // same as above
    }
  }
}

void clearData()
{
  while(data_count !=0)
  {   // This can be used for any array size,
    Data[data_count--] = 0; //clear array for new data
  }
  return;
}
330  Using Arduino / Programming Questions / Re: Store status of previous key pressed on: February 20, 2014, 12:18:22 am
You really can't figure it out?

  • Make a new variable, previous_key.
  • Set previous_key to NULL or -1.
  • Read the key press.
  • If key press does not equal previous_key (which it won't, the first time), update previous_key.
I'm sure you can figure the rest out from here.
Pages: 1 ... 20 21 [22] 23 24 ... 197