wait_on_escape - confused

Folks, this is part of the code I am looking at:

  int temp1;
  for (int i=0;i<4;i++)


    if ((temp1==5)||(temp1==6))
      lcd.print(" ");
      alarm_is_on=false; // Turn off alarm

Yes, from the “multi day alarm clock” code.

I want the output (aka BUZZER) to go high at alarm time.

I have started to modify the code to do that, but it still seems to pulse. LED blinks.

Now I could simply do the line: digitalwrite(buzzer,high) but then there would be no checking for buttons pressed and turning the alarm off.

So it got me to look at the bigger routine.
This “wait_on_escape” looks like what detects the button press.

But other routines use that instruction (which it isn’t - right?) for delays.

Alas I can’t find a routine called “wait_on_escape” so I am stuck.

Basically in the alarm part of the code - which by that time the alarm IS valid - turns on the BUZZER pin to HIGH and leaves it there until a key is pressed.

I also would like to print a little bell symbol on the screen to show the alarm is active as well.
I have the code - well, other people have shown it to me - and I can work it out, but WHERE to put it is yet beyond me.

Anyway, I am slowly learning.

Google can work it out. There is a library called phi-menu (and phi-prompt) that have this functionality. Perhaps the code you are looking at uses it?

From the documentation of Phi-menu:

int wait_on_escape(int ref_time) Returns key pressed or 0 if time expires before any key was pressed. Use this function to wait for users to press a key. You may replace delay() with this function to regulate program flow while checking user input at the same time. User modification: you should not modify this.


Please understand I am LEARNING.

As the code doesn't reference "PHI-prompt" I missed finding it.

(It would be nice if when functions are called which are not in that piece of the code, the person could mention where the function is to make it easier for people like me to find.)

Also, as those two routines are not loaded when I load my code, I have less than 1% of knowing to look there.

Yeah, "MrGoogle".......

I thought places like this we are supposed to HELP one another.

I have said it before: I am told daily I am stupid, I admit I am not THAT smart, I know I still have a lot to learn.

John, Thanks. I shall look into that routine a bit more and hope to ge things working. I really need this alarm routine to be working as not having an alarm clock is getting a bit annoying.

Now I have a few "interface" problems.

Erm, was just doing a little detective work for you and explained how - what's the issue with that?

No real problem, but I don't like being fobbed off to google.

The second reply was more helpful in that it explained what the function was doing for few extra key presses.

I am frustrated - my own fault - trying to get my head around the syntax, and the way the code is written, I am chasing ghosts instead of learning.

I am lacking sleep - thus I am making the alarm clock - and trying to get my head around code with what I would call bad or poor comments which don't explain where to find the functions, or in which file to find them.

I have nearly got the code working, but the LED (for now) still pulses although I have done my darndest to make it come on and stay on until a key is pressed. Sitting in front of the machine trying permutation after permutation to get it working is really slow learning and the frustration level is off the scale.

(I am also noticing my typing skills are getting bad/worse. Letters swapped and all that. WHich I know woun't be helping me when writing code. But that's another story.)


Found the routine and looked at it.

Indulge me:

 * \details This function is the center of phi_prompt key sensing. It polls all input keypads for inputs for the length of ref_time in ms
 * If a key press is sensed, it attempts to translate it into function keys or pass the result unaltered if it is not a function key.
 * It only detects one key presses so holding multiple keys will not produce what you want.
 * For function key codes, refer to the "Internal function key codes" section in the library header.
 * \param ref_time This is the time the function is allowed to wait, while polling on all input keypads.
 * \return Returns translated key or NO_KEY if no key is detected after the time expires.

(Dunno why I did that, but.....)

Ok: If a key press is sensed, it attempts to translate it into function keys or pass the result unaltered if it is not a function key.

My head is swimming.

The code I am using all keys are defined - as function keys? - so I guess that makes sense.

It only detects one key presses so holding multiple keys will not produce what you want.

Keh? What I want? I am going to bash my head against the wall a bit more and see if I can resolve the problem I have.

Good news!

I got it working - or doing what I want.

I won't worry about posting the code, because I had to modify a lot of different parts.

Dear Lost and Confused, You were "Fobbed off to Google" because that is the resource that most of us here use the most frequently... besides our minds. Answers = Hard Work + Google and what ever other resources available, or the ability to pursue a project until you have exhausted your available resources and then ask for help... IMO...

I will point out that I have several times followed a similar path I.E. asking for help before I could/would/should have completely researched what I meant to do, found a dead end and then asked for help. In most all cases had I done a little more work first I would have learned more about what I needed to do than the answers I received in this forum as the answers are to the point or issue rather than to the subject in toto. Again IMO...



I agree most whole heartedly.

I don't want to be spoon fed. I understand that I need to put in the "hard yard" to learn.

But after 3 hours of trying to understand what is going on and getting different results for reasons unknown, it really gets frustrating.

Google: Well, yes it is handy, but it can take you on some wild goose chases as well.

Anyway, after looking at the function and a bit more at the code as I explained:

I have it working.

There are little things - more cosmetic rather than functional - which may be done later.

But for now, I am yet another step closer to getting this alarm clock working.

I wish I was, I bought a GPS module (for a 'time server'), a barometer (BMP085), a hygrometer (DHT22), a 4D Systems 3.2" SGC display and a couple of Sure electronics 3208 displays as well as some X10 TW523 transceivers... oh yeah and a couple of radios for comm to the displays and for outside temp/humidity data I/O and control, I have all but the radio's (Next) and the display (from Robot Shop that was used or a demo and returned for a new one). I have both some nordic/knockoff's and a couple of sets or 433 Mhz modules that I need to get talking to each other... (I Love Ebay) Once I get the radios working I then need to integrate the whole thing as I have all the sketches tested already... all this while learning the language (s) in my spare time... Gawd, It's Great to be Retired, I can do what I want when I want... As for Google it is amazing what you can find although it does require a lot of patience and perseverance. You might pay attention to places like Adafruit, Sparkfun and there are a couple of other groups/sales outfits where great information can be had... And Don't forget Wiki, there is a Mountain of Data there. Arduino has a huge presence in Wiki. The best advice I can offer is to make a good plan, try and break it, if/when you do fix it and try again once the plan is reasonably bullet proof then work your plan... That was the hardest lesson I had to learn from technician to engineer, it never changes. Your work will never be better than the plan that created it... Oh yeah, don't deviate from the plan, Re-Plan your work when you run into difficulties... IMO I did find one really useful accessory in my travels. It is a shield that plugs into/onto the Uno and extends all I/O to a header PCB that plugs into a breadboard. The device makes developing a project much easier as things like the PSU can be external to the Uno which is great for high current loads/projects.



Sounds like you are really having fun.

Good on you.

All the best with the project/s.

My list is growing.

I am going to work on an Auto-irrigation system of sorts for my plants at home. Then there is a kind of fancy door bell/phone monitor/intercom thing which deals with all communications requests but for my mobile. But having one of these "smart phones" it can kind of look after itself.

And I am sure there are a few others in the wings waiting to be found.

Yeah, I too am a Hardware person who is trasitioning over to software and my knowledge of C is basically ZERO.

But, yes, I am happy I have got it to this stage.

Alas the documentation that came with the shield is "incorrect" or not for that exact board. Also it doesn't give a good break down of what pins do what from the Arduino board to it, and it's pins to where locally.

So I am in a bit of bad area just now with the "real world interface".

Oh well.

There is a common mistake that most hardware noobs make and that is properly bypassing projects and estimating load load current for external loads. Remember that the on-board regulator isn't good for a great deal of current. IMO the Only thing that should be connected to an Uno is the I/O and ground wires. Vcc for external devices unless well bypassed is frequently a source of noise and also that noise currents flow equally in the supply and ground leads... So Bypass it at the source. IMO


Yeah, I think I know what you mean.

All/most of my projects will have "isolation" between the Arduino and the real world.

Either opto, or transistor/relay set up - with flyback diode.

I probably would also have isolation at the power supply with a resistor (or something like that) and a big cap.

Alas those kind of projects are a bit away just now. I have to get this alarm clock working first - then get some better sleep.