We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › saving a changing digital state from sensor
Page Index Toggle Pages: 1
saving a changing digital state from sensor (Read 338 times)
saving a changing digital state from sensor
May 28th, 2009, 6:34am
 
hi there,

unfortunately i didn't find an answer to my question yet. maybe you could help..

i have a motion detection sensor with a digital out that states "1" for "no movement" and "0" for "there's movement".

when there's movement the sensor outputs "0" 2 short times, then goes back to "1".

i wish to show a video if there's movement, so i need to measure the 0-trigger - for that i have to record the state as long as the duration of the video.

that's my problem. dunno how to do that.

hope you can guide me on path, i'm stuck in the forest.
thanks in advance,
chris
Re: saving a changing digital state from sensor
Reply #1 - May 28th, 2009, 7:02am
 
It's a little tough not knowing exactly how your hardware is working and sending in info, but if it were me, I'd probably just assign a boolean variable which allows access to the sensor status, and pair that with a timer which correlates to your video playback. So here's some code/pseudo that demonstrates what I'm thinking:
Code:

int sensor_status;
boolean movIsFinished = true;

if(movIsFinished){
    sensor_status = somehardware.getSensorStatus();
    movIsFinished = false;
}
if(sensor_status == 0){
    play movie;
    if(check_to_see_if_movie_is_finished_playing){
         movIsFinished = true;
    }
}


So basically, you're only updating your sensor_status variable when no movie is playing. That way, although your hardware is constantly sending in numbers, your system will ignore them until you need to check on them again, i.e. when your movie is finished playing. There are a few ways you can check to see if your movie is finished. You should check those out at the video library page. I don't know, is this the type of answer you were after  Undecided
Page Index Toggle Pages: 1