Pages: 1 [2]   Go Down
Author Topic: A simple question I am sure  (Read 863 times)
0 Members and 1 Guest are viewing this topic.
California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Now you're just being mean.
How so?

Quote
I don't understand what to call the variables

You give variables meaningful name: pirSesnorPin, pirSensorState, lastPirSensorState, ledPin, ledState, etc...

Quote
how to summon them and get them to do anything

You don't summon variables; you either declare them:
Code:
int pirSensorPin;
Assign something to them:
Code:
pirSensorPin = 2;
or use their values in an experession or function call:
Code:
pirSensorState = digitalRead(pirSensorPin);

Quote
is it something to do with sacrificing chickens?
Now you're just being facetious.

It seems like it might be prudent for you to go through some of the examples first so that you can get a baseline understanding of programming concepts such as variables, assignments, selections and iterations.
« Last Edit: November 28, 2012, 01:14:49 pm by Arrch » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was trying to be humorous. There seems to be a degree of dark arts about this, at least to the uninitiated.

I meant you are being mean by directing me back to your previous reply, when I don't understand how to do point 1 or 2,
(1) Record the time at which the transition occurred from "no movement detected" to "movement detected". This is typically done by comparing the last read value of a sensor with it's current. "Record" means use the result from millis() to assign a value to a variable.
(2) Keep checking the time you recorded against the current time. If it's over a certain value, do some other action such as turning a light off.

 I thought I had told it to do that in the code but obviously not.
Telling me it is wrong but not why or what to do is not an effective teaching trick. But telling people the same thing in several diferent ways is very useful

I can get the machine to do all sorts of things but not this. Where do you suggest I start?
Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I meant you are being mean by directing me back to your previous reply, when I don't understand how to do point 1 or 2,
I wouldn't expect you to after only an hour, and most of it was probably spent posting and waiting for replies instead of trying to figure it out. Short of writing the code for you, I don't know what else I can do for you; some of this stuff you just have to actually play around with to figure out.

Where do you suggest I start?

For (1), take a look at the StateChangeDetection example under "02. Digital" in the Arduino IDE. Get it to print out the current time on the state changes for the PIR sensor. That's where you should be starting.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm sorry.

I spent several hours, that feel like days, banging my head.

I think I have found a route, but it seems different from what you suggested.

Thank you for trying to help me.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6373
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Hardware is so much easier. 
So think of it as hardware.  You'd use a retriggerable monstable timer, right?   It has a "trigger" input, and a "Q" output.  When you trigger it, the Q output goes "true" for some time, and then goes false again.  So what does it take to do that in software?  Rather than have an RC circuit gradually charging or discharging a cap until it reaches a certain voltage level, software will monitor the current time (via millis()) until that reaches a certain value.
Code:
static const mono_time = 5000;   // Out "time constant" is 5000 milliseconds.  This is "built in."
/*
 * Implement a "monostable" timer.  If "trigger" is true, set the end time.
 * Regardless of "trigger", return true if the timeout has not expired.
 */
boolean monostable(boolean trigger)
{
  static unsigned long start_time;  //  The millis() time when we were triggered
  unsigned long elapsed_time;

  if (trigger) {
    /* We received a trigger.  Record the time. */
    start_time = millis();
  }
  /* Now calculate how long it's been since the last trigger */
  elapsed_time = millis() - start_time;
  /* if the elapsed time is smaller than our desired timer value, our
    * output should be true.  */
  if (elapsed_time < mono_time) {
    return true;
  }
  /* Otherwise our output is false */
  return false;
}
Then in your main code, if you see PIR activity, you call "monostable(true)"
and later, you check the value by calling "monostable(false)" to see if your light should turn off:
Code:
void loop()
{
  if (pir_active()) {  // motion detected?
    light_on();  // turn on the light
    monostable(true);  // and fire our monostable.
  }
  // (other stuff ?)
  if (monostable(false) == false) { // check if the monostable has expired
    light_off();  // if so, turn the light off again.
  }
  // more other stuff ?
}
Logged

Offline Offline
Full Member
***
Karma: 4
Posts: 187
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I am a humble chemist after all

Quote
I'm just a poor science teacher, please don't just tell me I'm wrong and not tell me a solution

Quote
Now you're just being mean.

I don't understand your advice in reply 9.

I don't understand what to call the variables, how to summon them and get them to do anything, is it something to do with sacrificing chickens?


Quote
'm sorry.

I spent several hours, that feel like days, banging my head.

I think I have found a route, but it seems different from what you suggested.


It's mean your are looking here for some one who will serve you meal(code)smiley-cool.
« Last Edit: November 29, 2012, 12:31:47 am by Cybernetician » Logged

From Idea To Invention

Pages: 1 [2]   Go Up
Jump to: