Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Character Array Crashing Arduino? on: June 16, 2012, 08:31:31 am
By using

Code:
Serial.print(passyear);


It outputs 2165.


Pardon my ignorance but if now.year() equals 2012 why is it being stored as 2165?


Edit:

If I move this chunk of code:

Code:
  RTC_DS1307 RTC;
   RTC.adjust(DateTime(__DATE__, __TIME__));
 RTC.begin();
DateTime now = RTC.now();
int nowyear = now.year();
itoa( nowyear, passyear, 10);
  password.set(passyear) ;

From Void Setup to Void guessPassword, passyear now equals 2012.  Any reason as to why?

---------------
Final Edit

Thankyou everyone very much! I created a new function (Unsure what they are called?) and put my set password code in there, works like a charm.

Code:
#include <Password.h>
#include <Keypad.h>
#include <Wire.h>
#include "RTClib.h"

Password password("");
  char passyear[5];


const byte ROWS = 4; // Four rows
const byte COLS = 4; //  columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 7, 6, 5, 4 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 12, 11, 10, 8 };


// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

#define relay 3
#define speakerPin 13


 
void setup(){
Wire.begin();
     pinMode (3, OUTPUT);
  pinMode (13, OUTPUT);
  Serial.begin(9600);
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
  }

void loop()
{
  keypad.getKey();
}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
  Serial.print("Pressed: ");
  Serial.println(eKey);
  switch (eKey){
    case '*': SetPass(); guessPassword(); break;
    case '#': password.reset();  break;
     default:
     password.append(eKey);
  }
}

void SetPass(){
 
       RTC_DS1307 RTC;
   RTC.adjust(DateTime(__DATE__, __TIME__));
 RTC.begin();
DateTime now = RTC.now();
int nowyear = now.year();
itoa( nowyear, passyear, 10);
  password.set(passyear) ;
 
}


void guessPassword(){
     Serial.print("Guessing password... ");
     if (password.evaluate()){
      digitalWrite(speakerPin,HIGH);
              digitalWrite(relay,HIGH);
              delay (2000);
              digitalWrite(relay,LOW);
     Serial.print("Correct");
     }else{

     Serial.print(passyear);
     }
}

Again, Why did the positioning of my code cause an incorrect value to be stored?
2  Using Arduino / Programming Questions / Re: Character Array Crashing Arduino? on: June 16, 2012, 07:41:17 am
I'm still very new to this, what would be the best method to do this?
3  Using Arduino / Programming Questions / Re: Character Array Crashing Arduino? on: June 16, 2012, 06:12:15 am
Thankyou *VERY* much everyone, so far so good!

Code:
#include <Password.h>
#include <Keypad.h>
#include <Wire.h>
#include "RTClib.h"

Password password("");
  char passyear[5];


const byte ROWS = 4; // Four rows
const byte COLS = 4; //  columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 7, 6, 5, 4 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 12, 11, 10, 8 };


// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

#define relay 3
#define speakerPin 13


 
void setup(){

   RTC_DS1307 RTC;
   RTC.adjust(DateTime(__DATE__, __TIME__));
 RTC.begin();
DateTime now = RTC.now();

itoa( now.year(), passyear, 10);
  password.set(passyear) ;



   Wire.begin();
     pinMode (3, OUTPUT);
  pinMode (13, OUTPUT);
  Serial.begin(9600);
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
  }

void loop()

 


{
  keypad.getKey();

}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
  Serial.print("Pressed: ");
  Serial.println(eKey);
  switch (eKey){
    case '*': guessPassword(); break;
    case '#': password.reset();  break;
     default:
     password.append(eKey);
  }
}

void guessPassword(){
     Serial.print("Guessing password... ");
     if (password.evaluate()){
      digitalWrite(speakerPin,HIGH);
              digitalWrite(relay,HIGH);
              delay (2000);
              digitalWrite(relay,LOW);
     Serial.print("Correct");
     }else{
     Serial.print(passyear);
     }
}

Last problem: The year is being stored as 2165? I have confirmed using the DS1307 example project that the year is correctly set, I've even added some code to set the time based on the compilation date of the project. Could it be the way I am storing the value?

Code:
itoa( now.year(), passyear, 10);
  password.set(passyear) ;
4  Using Arduino / Programming Questions / Re: Character Array Crashing Arduino? on: June 16, 2012, 01:59:41 am
Ok, With that modification, These errors occur:


sketch_jun16a:29: error: no matching function for call to 'Password::Password()'
C:\Users\Luke\Desktop\Programs\Arduino\libraries\Password/Password.h:51: note: candidates are: Password::Password(char*)
C:\Users\Luke\Desktop\Programs\Arduino\libraries\Password/Password.h:49: note:                 Password::Password(const Password&)
sketch_jun16a.cpp: In function 'void guessPassword()':
sketch_jun16a:82: error: 'passyear' was not declared in this scope

Code is:

Code:
#include <Password.h>
#include <Keypad.h>
#include <Wire.h>
#include "RTClib.h"





const byte ROWS = 4; // Four rows
const byte COLS = 4; //  columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 7, 6, 5, 4 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 12, 11, 10, 8 };


// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

#define relay 3
#define speakerPin 13

Password password;

void setup(){
  RTC_DS1307 RTC;
  Wire.begin();
    RTC.begin();

 DateTime now = RTC.now();
  char passyear[5];
itoa( now.year(), passyear, 10);
  password.set(passyear) ;

 
     pinMode (3, OUTPUT);
  pinMode (13, OUTPUT);
  Serial.begin(9600);
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
 


}

void loop()

 


{
  keypad.getKey();

}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
  Serial.print("Pressed: ");
  Serial.println(eKey);
  switch (eKey){
    case '*': guessPassword(); break;
    case '#': password.reset();  break;
     default:
     password.append(eKey);
  }
}

void guessPassword(){
     Serial.print("Guessing password... ");
     if (password.evaluate()){
      digitalWrite(speakerPin,HIGH);
              digitalWrite(relay,HIGH);
              delay (2000);
              digitalWrite(relay,LOW);
     Serial.print("Correct");
     }else{
     Serial.print(passyear);
     }
}
5  Using Arduino / Programming Questions / Re: Character Array Crashing Arduino? on: June 16, 2012, 12:51:55 am
Yes, RTC Depends on external hardware. I have replaced the code block at the top with this:

RTC_DS1307 RTC;
  DateTime now = RTC.now();
  char passyear[5];
itoa( now.year(), passyear, 10);
  Password password = Password (passyear) ;  

I Then get this error:
sketch_jun16a:9: error: expected constructor, destructor, or type conversion before '(' token

I Suspect it's coming from the location of the code, yet If i move this into void_setup

sketch_jun16a.cpp: In function 'void keypadEvent(KeypadEvent)':
sketch_jun16a:67: error: 'password' was not declared in this scope
sketch_jun16a.cpp: In function 'void guessPassword()':
sketch_jun16a:75: error: 'password' was not declared in this scope
sketch_jun16a:82: error: 'passyear' was not declared in this scope

This is the current code:

Code:
#include <Password.h>
#include <Keypad.h>
#include <Wire.h>
#include "RTClib.h"





const byte ROWS = 4; // Four rows
const byte COLS = 4; //  columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 7, 6, 5, 4 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 12, 11, 10, 8 };


// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

#define relay 3
#define speakerPin 13


void setup(){
  RTC_DS1307 RTC;
  Wire.begin();
    RTC.begin();
    

 DateTime now = RTC.now();
  char passyear[5];
itoa( now.year(), passyear, 10);
  Password password = Password (passyear) ;  

 
     pinMode (3, OUTPUT);
  pinMode (13, OUTPUT);
  Serial.begin(9600);
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
  


}

void loop()

  


{
  keypad.getKey();

}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
  Serial.print("Pressed: ");
  Serial.println(eKey);
  switch (eKey){
    case '*': guessPassword(); break;
    case '#': password.reset();  break;
     default:
    password.append(eKey);
  }
}

void guessPassword(){
     Serial.print("Guessing password... ");
     if (password.evaluate()){
     digitalWrite(speakerPin,HIGH);
              digitalWrite(relay,HIGH);
              delay (2000);
              digitalWrite(relay,LOW);
    Serial.print("Correct");
     }else{
    Serial.print(passyear);
     }
}


Thanks for all of your help, this is my first arduino project (as you can probably tell!).


Moderator edit: [code] [/code] tags added.
6  Using Arduino / Programming Questions / Character Array Crashing Arduino? on: June 16, 2012, 12:21:11 am
Hi all, I have an Arduino Uno and i'm making a basic project whereby the user uses a keypad to enter the current year, if the current year is correct it will fire a relay.  For some reason this code will upload fine but the arduino wont do anything once uploaded. If I leave out the array and just use a static password (Password password = Password ("1234") smiley-wink it works fine.

This is the code:

Code:
#include <Password.h>
#include <Keypad.h>
#include <Wire.h>
#include "RTClib.h"


RTC_DS1307 RTC;
DateTime now = RTC.now();
char passyear[5] = {now.year()};
Password password = Password (passyear) ;



const byte ROWS = 4; // Four rows
const byte COLS = 4; //  columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 7, 6, 5, 4 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 12, 11, 10, 8 };


// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

#define relay 3
#define speakerPin 13


void setup(){
  Wire.begin();
    RTC.begin();
    
 
    
     pinMode (3, OUTPUT);
  pinMode (13, OUTPUT);
  Serial.begin(9600);
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
  


}

void loop()

  


{
  keypad.getKey();
  
}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
  Serial.print("Pressed: ");
  Serial.println(eKey);
  switch (eKey){
    case '*': guessPassword(); break;
    case '#': password.reset();  break;
     default:
    password.append(eKey);
  }
}

void guessPassword(){
     Serial.print("Guessing password... ");
     if (password.evaluate()){
     digitalWrite(speakerPin,HIGH);
              digitalWrite(relay,HIGH);
              delay (2000);
              digitalWrite(relay,LOW);
    Serial.print("Correct");
     }else{
    Serial.print("false");
     }
}



Moderator edit: [code] [/code] tags added.
7  Using Arduino / Displays / TV Output - With Colour? on: April 24, 2012, 08:53:40 am
Hi All,

Still very new to the Arduino and was playing around with the TVOut library and was wondering - is it possible to get colour out of this?

I'm evaluating wether or not to use an LCD,VFD or possibly a small AV Monitor for a small project i'm tackling.
8  Using Arduino / Displays / Arduino To VFD on: April 19, 2012, 05:11:53 pm
Hi,

I'm trying to hook up a VFD To an Arduino (Arduino Uno), i know it's been done before but i'm unsure how to hook up this one (Not really for a project, just to experiment). It's a DigiPoS WD202 (USB Interface, though the pc recognizes it as a USB To Serial Converter, text can be passed off to the virtual COM Port) with a Winbond chip. Attached are two pictures of the Winbond chip and the interface.





Only just started with working with arduino's so bit of a n00b here  smiley-razz
9  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Unmanned Robot? on: January 23, 2011, 04:38:05 am
I Know that much  ;D

Seriously though, having never touched C/C++, how hard would it be to tackle a project like this?
10  Forum 2005-2010 (read only) / Frequently-Asked Questions / Unmanned Robot? on: January 23, 2011, 02:12:26 am
Hi,

I'm a complete n00b when it comes to arduino's! I've never touched one. I'd be using a small kit chassis (4wd) with a GPS Module and an Arduino Uno.

As far as programming goes, i know HTML, Basic PHP and Visual Basic.

Essentially, i'd like this robot to navigate itself to set waypoints, how hard would this be?
Pages: [1]