Show Posts
Pages: 1 ... 71 72 [73] 74 75 ... 100
1081  Using Arduino / Programming Questions / Re: keypad brainfart on: October 27, 2011, 08:08:40 pm
Thanks guys, perhaps I shall start with everything upfront, and once the sketch is running, start moving scope specific declarations to their functions one by one and test.

Then again, I always mean to go back and remove commented out junk, and duplicated instructions, but never seem to get the time to do so...

AWOL, is it a memory thing?
1082  Using Arduino / Programming Questions / Re: keypad brainfart on: October 27, 2011, 02:59:17 pm
Is there any preference for where to declare a variable type?
Does it "cost" more to have it globally declared, for instance?
1083  Using Arduino / Programming Questions / Re: keypad brainfart sorted on: October 27, 2011, 11:01:52 am
Thanks Guys

We learn something every day !

I removed the char in the get key routine and now I have only one key to play with :-)

What a great forum !
1084  Using Arduino / Programming Questions / Re: keypad brainfart on: October 27, 2011, 10:54:34 am
OK Awol , I wil post the code when I tidy it, but I did declare char key; in the initial global settings......

And Paul, I think I can see what you are saying, I am confused that I can get it to Serial.print("key read =");   Serial.println(key); OK so I thought that the variable has now been set to F or char 70 whatever, and as I had declared it globally I could use it elsewhere..

let my do some tidying up and post the whole code
1085  Using Arduino / Programming Questions / Re: Counting with a phototransistor. on: October 27, 2011, 10:42:12 am
Been there, done that , repeatedly kicked myself :-)

if you say if( y=0)    it will make it so,  you need to say if( y==0  )    ( is equal to )
1086  Using Arduino / Programming Questions / keypad brainfart on: October 27, 2011, 10:30:12 am

Heres a snippet of code from my current project, I am reading from a keypad, which works fine because if I press button F, the Serial.println(key);  returns F.
but then immediately  I try to run a switch routine in function whichkey() and I get no value returned for any key.   It doesn't print the "switch on" text, and if I try to serialPrinmt t it shows 0 in HEX BIN or whatever ?

It prints the "whichkey routine" so I know its getting that far ............

I have tried it as case 'F'   and as  char 70 but no luck.

I have copied the same code I use when sending over virtualwire with a radio link which works fine ( switching with the ASCII code )

I know I am going to kick myself as I think I have been here before !  :-)     Give me a reminder someone please ...

Code:


void loop (){
 
  char key = keypad.getKey();                 // reading the keypad
  if(key)                                     // same as if(key != NO_KEY)- did something change?
  {     Serial.print("key read =");   Serial.println(key);
  whichkey();
   show ();
}
}// end of loop
void whichkey (){
     Serial.println("whichkey routine");
   Serial.println(key, HEX );
  switch (key)  {
      case 'F':  //  F chr 70  ON    dont have to do anything, ISR brings it on
   Serial.print("switch on");
   break;
     
  } // end of switch key
}// end of
1087  Using Arduino / Programming Questions / Re: if ( var) ? on: October 19, 2011, 11:36:10 pm
Yes thats what I finally came to, the confusion was that I was reading the comment as being just related to its line, (  if ( key ) ),not the previous functions of the keypad library.
Often the comment precedes the code it refers to.

Thanks guys, I can go back to bed now !
1088  Using Arduino / Programming Questions / Re: if ( var) ? on: October 19, 2011, 10:37:53 pm
Hmm the brains a bit wooly at 5am,  perhaps I will ask the wife when she gets up, her mind works like this  :-)

 if NO_KEY were to be the previous value of key, I could understand the idea of " did something change? "  but it is not declared or used in the example.

It looks to me as though this is simply going to be true for any keypress ( other than 0 )  even if it is the same value, so where is the " did something change? "

Unless the keypad.h does not allow a subsequent value to be the same?
 Which could explain it, the comment would be more about the operation of the library, rather than about the if(key) which is what I was trying to understand ?
1089  Using Arduino / Programming Questions / Re: if ( var) ? on: October 19, 2011, 10:07:52 pm
its the " did something change? "  comment that has me confused...

If my key is always =  1,  then the if statement will be true, even though nothing has changed, but if it changes to 0, then it will be false, even though something changed ??

1090  Using Arduino / Programming Questions / if ( var) ? on: October 19, 2011, 09:47:53 pm
I am a bit confused with this part of the keypad code, and its' comment 

 if(key)    // same as if(key != NO_KEY)- did something change?


I tried checking it in the reference section for the if statement, and it is not mentioned, but it does say , while warning about using a single = ,  that

" This is because C evaluates the statement if (x=10) as follows: 10 is assigned to x (remember that the single equal sign is the assignment operator), so x now contains 10. Then the 'if' conditional evaluates 10, which always evaluates to TRUE, since any non-zero number evaluates to TRUE. "

Which seems to mean that  if(key) is any value other than zero, it will be TRUE, whether it has changed or not ?

1091  Using Arduino / Project Guidance / Re: too many RTC libraries? Sorted . on: October 10, 2011, 08:19:48 pm
( Just posting this in case somebody gets to this thread from a search and wants to see the outcome )

Finally its all working great, I went back to breaking the long unidays ( unix/86400 ) into higher and lower bytes to store in the RTC  eprom,  joining them again to make the previous events " unix days"

The elapsed days are simply a subtraction of the old and new days,

I convert that back to seconds to extract the DDMMYY to display as the previous event day with:-

prevunisecs = prevunidays * 86400;
    time_t t = prevunisecs;
     dayint = day(t);
    monthint = month (t);
    yearint = year (t);

The beauty now this way is that I have an up and down button on the remote, that increments ( or decrements ) the prevunidays ( and stores it each push ) and the user sees the elapsed days and the displayed date changing in unison with automatic month adjustments on the date, and when the elapsed days reaches 99 it freezes, but the date continues decreasing.

Just when you think you are getting on well with learning this new stuff, something as simple as this project, ( and the time I have spent on it,)  reminds you that you know so little !
But I am enjoying the learning...
1092  Using Arduino / Project Guidance / Re: too many RTC libraries? on: October 10, 2011, 03:09:34 pm
After 3 days of confused attempts, I did at one time manage to get the conversion from unix to yymmdd working, though I have lost my sketch when the pc crashed again  smiley-mad    but I think I can get that going again.


The other half is still eluding me,  just converting yymmgg to unix.    I just want to create an unsigned long that I can use for calculations.

The elapsed time is not needed, I can do this with the unix time, but I need to be able to use the results of both conversions independantly.

  I have read all the libraries,  but I usually end up with   "tm not declared " , or many other errors,  I do not understand" &tm" , or find any basic explanations of use of the time elements.

1093  Using Arduino / Project Guidance / Re: too many RTC libraries? on: October 10, 2011, 01:43:23 am
I understand the seconds, etc, it was just the syntax of  " tmElements_t &tm1, tmElements_t &tm2  " that confused me a bit, I am sure I can manage it now.
Thanks for the help, sometimes reading through libraries like Time have too many unknowns for learners to see what is happening.
1094  Using Arduino / Project Guidance / Re: too many RTC libraries? on: October 09, 2011, 02:41:10 pm
I saw the help you gave re the same question a ferw weeks back i.e.

unsigned long timeDiff( tmElements_t &tm1, tmElements_t &tm2)
{
  return makeTime(tm2) - makeTime(tm1);
}

But it doesnt mean anything to a newbie like me :-)    for today would tmElements_t &tm1  be for example,  09,10,11&tm1   ?

1095  Using Arduino / Project Guidance / Re: too many RTC libraries? on: October 09, 2011, 01:53:40 pm
Thanks I will try that, have been all afternoon trying to get the internet access going again !

I still need to store the previous date in eprom, but I will try the upper lower bytes again, unix converted to days so it will only be 2 bytes.

It would still be easier if I could just store the dd mm yy ( which I need for the display anyway )  and find how to convert that to unix time so I could do a straight subtraction for the days elapsed.

Any change of the old dd mm yy with the remote, would automatically display the days elapsed  ...

Pages: 1 ... 71 72 [73] 74 75 ... 100