You really haven't got the hang of testing a variable and acting on it state
Look at you loop() function after Auto Formatting it in the IDE
void loop()
{
digitalWrite(POWER_PIR, HIGH);
val = digitalRead(PIR_SIGNAL); // read the input pin
if (val)
servo1.write(0);
delay(50);
servo1.write(10);
delay(50);
servo1.write(0);
delay(50);
servo1.write(10);
delay(50);
}
The only line of code that depends on the value of the val variable is the first servo1.write(). Subsequent commands are executed unconditionally. This is not the first time that this has been pointed put to you
Put the dependant code block in braces like this
void loop()
{
digitalWrite(POWER_PIR, HIGH);
val = digitalRead(PIR_SIGNAL); // read the input pin
if (val)
{
servo1.write(0);
delay(50);
servo1.write(10);
delay(50);
servo1.write(0);
delay(50);
servo1.write(10);
delay(50);
}
}
Which would you consider the more advantageous route?
And I meant to ask, since this goes to sleep is it really necessary to do and else on the POWER_PIR. I don't think it would be because once it wakes up, everything shuts down???
{
// power up the LDR, take a reading
digitalWrite (LDR_ENABLE, HIGH);
int value = getReading (LDR_READ);
// power off the LDR
digitalWrite (LDR_ENABLE, LOW);
if (value < LIGHT_THRESHOLD) // if it's dark, do stuff
{
power_timer0_enable ();
delay (1); // let timer reach a known point
power_timer1_enable();
delay (1);
digitalWrite (POWER_PIR, HIGH);
} else
digitalWrite (POWER_PIR, LOW);
OK Mr. Bob you have my attention. I've been learning all kinds of cool stuff. Not "there" yet, but I'm on my way slowly but persistently. So I have a question for you. (7 lines of code or less) that sounds VERY IMPRESSIVE. So..... If you have a moment please expand upon this WITHOUT DELAY, per say possibly an example, And lets use the following because it's only 8 of my 60 lines long. If you say it can be done, I believe you. However, finding a tutorial that addresses this specific situation is damn near impossible, well....... it actually is impossible. different degrees with different delays.
after thought, I'm looking at this thinking the "delays" (not) would need to be presented prior to setup. In that a, lets say 2000 would need to be like. interval 1? and a delay (not) could be an interval 2, which might be 50. That's with a ? mark behind it.
as they say, an example is worth a thousand words.
to put it in its simplest form, it "wiggles " back and forth. it goes L, R, L, R, L.......real quick, (short delays) R, (delay) L, (delay) R, L, R it just mimics a pattern. It DOESN'T simply sweep 0 to 180 to 0. like every tutorial out there on the internet. I can do it with delays, BUT they block everything else!
You can write a 900 page book on how to use a hammer and dolly to take the crease out of the door of a Rolls Royce. (FYI, they are hand made) By the end of the day it will look worse then when we started.
You can take me out to the garage and "SHOW ME" how to do it, and in a day or 2, I'll be as good if not better than you. I have to "SEE IT" to understand it. It's how "I" process stuff.
So please SHOW ME how it works! There's 8 lines. NOT 60. Seems like it shouldn't take much at all? UKHeliBob even said so...........He said the whole thing (60 lines) could be done in 7 or 8 lines using a for loop. OK, show me 8 and I can do 800.
Thanks, Fred
OK, 2 replys came in while writing this. I'll post, then read the replies. Thanks
Delta, sir not trying to dis you in any respect. I have what is called chemo brain fog, brought about by 24 weeks of the nastiest drugs being pumped into my body for 52 hours straight per session. I have good days and I have some really bad ones. Just trying to get past blinking LEDs and delay. i will revisit your comment, study it more closely. Your input is greatly appreciated. And the best part is it is written down so I can revisit it. There are a lot of tutorials. Some are good and then there are those where you work on something for 2 days only to find out you wasted 2 days. UKHeliBob presented an example. At first it looked really complicated. But as I dissect it line by line. Means go look up and read what every line means. Why did he write it this way, what does that mean, how come this is where it is etc......I will eventually reach that ah-ha moment. There is just a lot to this stuff and I have a great deal of admiration for your ability to do it. Please except my apologies if you felt like I wasn't interested in your input. I am, and I am going to learn!