Beginners Program
TyroneR
Posts: 22
Im new to microcontrollers and
I have been messing around with the Sound Impact Sensor ,and the IR motion senser to create a secuirity system.
As I am sure that you all know that the Sound impact sensor, and the IR motion senser sends a high signal to their assigned pins when there is change in the enviroment (what they are monitoring).
I belive that their is a better way to monitor sound , and motion by keeping track how often the assigned pin recieves a high signal .
This way mySound Impact sensor will not sound the alarm if it hears one little thing over a long period of time(lets say 15 min). But rather if it stayes high continously for a period of time(lets say 2 sec.), or if it goes high and low more than one time in a time frame of lets say 2min. The alarm will sound.
What I am asking is. Is there an example out there that monitors the state of an I/O pin and stores a value if high , starts a count down (desired time) while waiting for the I/O pin to go high again.
If the I/O pin does not go high again with in that time frame set. The Propeller will clear that value and start over, but if it the I/O pin doesgo high again before the count down ends and the Propeller resets itself.
I would like the alarm to sound, or light an LED.
I hope what I am trying to do makes sense to you all,
_clkmode = xtal1 + pll16x ' Set clock mode
_xinfreq = 5_000_000
VAR
byte state ' Variable for storing PIR output
OBJ
pst : "Parallax Serial Terminal" ' Use Serial Terminal object
PUB PIR
dira[18]~ ' Set pin 18 (Sound impact sensor) to input
dira[19]~ ' Set pin 19 (IR sensor) to input
pst.start(115200) ' Start Terminal at 115200 baud
pst.str (string("Warming up..."))
waitcnt(clkfreq * 20 + cnt) ' PIR "warm-up" time
pst.clear ' Clear the screen
repeat
if ina[18] == 1 'Waiting for P13 to recieve a high signal
dira[1]:= outa[1] :=0 'If P13 is high,turn off green LED (P1)
dira[0]:= outa[0] :=1 'If P13 is high,turn on red LED (P0)
waitcnt(clkfreq/4 + cnt) 'Wait 1/4 of a second before moving on to the next line of code
else
dira[0] := outa[0] :=0 'If P13 is Low,turn off red LED (P0)
dira[1]:= outa[1]:=1 'If P13 is high,turn on green LED (P1)
waitcnt(clkfreq/6 + cnt) ' Wait 1/7 of a sec before moving on
state := ina[19] ' Save state of PIR Sensor
pst.home ' Move cursor to upper left
pst.str(string("IN0 = "))
pst.bin(state, 1) ' Display results
waitcnt(clkfreq/200 + cnt) ' Small delay
I have been messing around with the Sound Impact Sensor ,and the IR motion senser to create a secuirity system.
As I am sure that you all know that the Sound impact sensor, and the IR motion senser sends a high signal to their assigned pins when there is change in the enviroment (what they are monitoring).
I belive that their is a better way to monitor sound , and motion by keeping track how often the assigned pin recieves a high signal .
This way mySound Impact sensor will not sound the alarm if it hears one little thing over a long period of time(lets say 15 min). But rather if it stayes high continously for a period of time(lets say 2 sec.), or if it goes high and low more than one time in a time frame of lets say 2min. The alarm will sound.
What I am asking is. Is there an example out there that monitors the state of an I/O pin and stores a value if high , starts a count down (desired time) while waiting for the I/O pin to go high again.
If the I/O pin does not go high again with in that time frame set. The Propeller will clear that value and start over, but if it the I/O pin doesgo high again before the count down ends and the Propeller resets itself.
I would like the alarm to sound, or light an LED.
I hope what I am trying to do makes sense to you all,
_clkmode = xtal1 + pll16x ' Set clock mode
_xinfreq = 5_000_000
VAR
byte state ' Variable for storing PIR output
OBJ
pst : "Parallax Serial Terminal" ' Use Serial Terminal object
PUB PIR
dira[18]~ ' Set pin 18 (Sound impact sensor) to input
dira[19]~ ' Set pin 19 (IR sensor) to input
pst.start(115200) ' Start Terminal at 115200 baud
pst.str (string("Warming up..."))
waitcnt(clkfreq * 20 + cnt) ' PIR "warm-up" time
pst.clear ' Clear the screen
repeat
if ina[18] == 1 'Waiting for P13 to recieve a high signal
dira[1]:= outa[1] :=0 'If P13 is high,turn off green LED (P1)
dira[0]:= outa[0] :=1 'If P13 is high,turn on red LED (P0)
waitcnt(clkfreq/4 + cnt) 'Wait 1/4 of a second before moving on to the next line of code
else
dira[0] := outa[0] :=0 'If P13 is Low,turn off red LED (P0)
dira[1]:= outa[1]:=1 'If P13 is high,turn on green LED (P1)
waitcnt(clkfreq/6 + cnt) ' Wait 1/7 of a sec before moving on
state := ina[19] ' Save state of PIR Sensor
pst.home ' Move cursor to upper left
pst.str(string("IN0 = "))
pst.bin(state, 1) ' Display results
waitcnt(clkfreq/200 + cnt) ' Small delay
Comments
I'm surprised not to see anybody helping this guy.
To TyroneR.....
I can't help you right now because I don't know the code that well. I just browse this forum because I find it interesting.
It has been over a year since I did anything with the Propeller, but I'll download your program and take a look.
I'm not sure where my propeller is. I should have some results Thursday night.
Thanks
BTW, should I use to cogs? I noticed when I combined the IR senser with the Sound impact sensor. It seemed a little slower ( the response).
My LCD display project had a sorta similar requirement - to turn off the back lighting in a few seconds
of inactivity. I used a second cog with the job of counting down the time-out period.
That would normally be done with an interrupt handler, but the Prop is more advanced!
Anyway, take a look at this and see if it gives you any ideas...
Edit: The attached ZIP file has the other drivers if you need them.
[
Thanks for the reply. This will definetly keep me busy this weekend.
So it may be a case of the blind leading the blind here?
While all of the above code is in a single source file, run time is not that way.
The second cog stuff is really running on a different computer (so to speak).
Thinking about it that way really helped.
At first I was trying to get the timeout code to shut down the back-lighting by itself
and a quick call to send a control code looked like the simplest way to do this.
But I couldn't get the objects that were loaded by the first cog to work for me.
- ir : "IR_Remote"
- lcd : "serial_lcd"
- num : "simple_numbers"
There was no indication of a problem from the compiler.
It simply did not work correctly.
Serial.LCD wrote seriously strange stuff to the display.
It looked like it WAS sending something.
But what?
In the end, I started thinking about this project as an interrupt handler.
While this example has all day (waits one second) to do anything,
faster functions wouldn't. Sending serial bytes would definitely
impact timing for a servo driver or some such.
So just do the down-count and let the main program deal with it
as it wants.
I didn't have to FORMALLY pass the address of LCDtime to the second cog.
It was defined as a VAR, the compiler had it handy and it worked as expected.
To ACCESS that variable, the second cog must refer to is by address (pointer).
byte[@LCDtime]
But would that still work if the code were in a different file?
Sharing methods between cogs?
I don't have a handle on that yet.