Loading...
Logo
Processing Forum
This code was originally set as part of a class exercise/task several semesters ago when I started Programming.The task is to write some code for a basic alarm using set variables for the designated alarm time. I want to make it so when my Alarm is active an audio file (sound of an alarm) is played, the alarm should only last 8 seconds, during which time my forever loop --my while loop printing a full stop every second-- is paused for this amount of time after which it should return back to printing a series of full stops every second

Copy code
  1. //import processing.video.Movie;

  2. int alarm_time;
  3. int alarm_hour;
  4. int alarm_minute;
  5. int current_time;
  6. int t,count;
  7. boolean alarm;


  8. void setup(){
  9. //Set alarm time
  10. alarm_hour = 17;
  11. alarm_minute = 54;

  12. //Define alarm time & curent time
  13. alarm_time = alarm_hour + alarm_minute;
  14. current_time = hour() + minute();
  15. }


  16. void draw(){
  17. //"forever while loop" infinite loop, prints (or rather should) a full stop every half second
  18. boolean always_true = true;
  19. while( always_true ){
  20. print( "." );
  21. for( int i = 0; i < 1000000000; i++ ){
  22. float result = sqrt( 257 );

  23. if(alarm){
  24. // increase the count-variable every second
  25. if ((millis()-t)/1000>count) {
  26. print(++count+" ");
  27. }
  28. // disable alarm after 8 seconds
  29. if (millis()-t > 8000) {
  30. alarm = false;
  31. }

  32. //activate alarm
  33. if(alarm_time == current_time){
  34. println();
  35. println("ALARM!!!");
  36. print("Counting: ");
  37. t = millis();
  38. count = 0;
  39. alarm = true;
  40. }
  41. }
  42. }
  43. }
  44. }
  45. //new Movie(this,"alarm.m4v");
Copy code
  1.  

Replies(4)

Hi Kayleb,

It appears this is an assignment for class, usually people here want to help you learn not do your work for you :) 
While we are happy to help you with issues in your program, it's unclear what you are having trouble with. right now it just looks like a half-done project. I'm not really sure what you are having trouble with (unless it is finishing...). 

First off I notice you have no setup() function, only a draw(). In Processing, the draw loop is the 'forever' loop, as you call it. If you have numbers that are not updated each frame, those would be best to put in a setup(). I see your first few lines are setting up the alarm, maybe those could be in setup. Second I see you have a for() loop that is iterating  1000000000 times. I'm not really sure what you are looping through. when you enter a loop like that, everything in the brackets must compute before anything else in the application can happen. so while that loop goes through that many iterations, your program will appear to hault, giving no feedback or information until the i reaches the end. 

hope this helps, some more info of what is currently working/not working, what you have tried, etc work better than listing your project requirements and expecting someone else to code it for you :)
good luck!
ak

Yes, additionally:

Do you want one program for each task or have it all rolled into one?

Do you have a question or a problem with the code?

Thanks!

Greetings, Chrisir  




"It appears this is an assignment for class" yes this was a class 'exercise' from my first semester of Programming :( It was a bit of an audacious attempt, and foolish at that considering I forgot to note what I was asking help for. 

EDIT:
I managed to get a hand on the actual code. I was making some mistakes in the way I was organising my events i.e. my timer and delay timer. The solution was a lot clearer than I made it out. Thanks anyway for the advice, helped me understand a bit better what I was I getting wrong. Apologies for not being clearer about the nature of the question and not being clearer about my issues N.B. @akiersky This was an exercise devised by my tutor/mentor


hello,

for playing a movie see:

http://forum.processing.org/topic/how-i-can-control-the-sound-with-movie-class

so it's approx.:


at the beginning:

import processing.video.*;
Movie myMovie;



in setup()

myMovie = new Movie(this,"alarm.m4v");

in draw()

image(myMovie, 0, 0);


of course this: alarm_time = alarm_hour + alarm_minute + alarm_second; is wrong. They are all numbers but to add hours to minutes makes no sense.
You rather want to store the alarm time (you have that) in setup()

  1. //Set alarm time
  2. alarm_hour = 17;
  3. alarm_minute = 54;

And then in draw() compare it to the current time, so it's approx.:
if(alarm){
if ( alarm_hour == hour() && alarm_minute == minute()) {
// go alarm
image(myMovie, 0, 0);
}

}

see
http://www.processing.org/reference/hour_.html


Greetings,

Chrisir