? concerning a flow chart

aarg, you may very well be the best programmer in the world. but if you can't teach or help me to learn, you are a waste of my time. and I would prefer you'd be that

...chip who isn't here...

back to state variables and conditions.

the first variable is: isDark //the condition under which all things will run. that's taken care of.

the second is: READ the LDR power pin, it goes high for 10 seconds every half hour. when it goes high you write the 2 LEDs high.

the third is what I would like to LEARN TODAY!: how do I tell LED #2 to wait a second, go on for a second, then go off for the remainder of the LDR interval.

I can delay for the first second and then turn it on, but I can't figure out how to turn it back off.

are you able to help?

oh explicative! I see you posted again while I was typing. you are obviously not someone to turn to for help! but thanks anyway.

what type of statement(s) would I need to study to accomplish these 2 different timings?

Something to play with

const byte ledPin1 = 10;
const byte ledPin2 = 11;
unsigned long led1StartTime;
unsigned long led2StartTime;
unsigned long led1Period = 10000;
unsigned long led2Period = 1000;
boolean led2Flag = false;

void setup()
{
  Serial.begin(115200);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  digitalWrite(ledPin1, LOW);  //led1 on
  digitalWrite(ledPin2, HIGH); //led2 off
  led1StartTime = millis();
  led2StartTime = millis();
}

void loop()
{
  unsigned long currentTime = millis();
  if (currentTime - led1StartTime >= led1Period)
  {
    digitalWrite(ledPin1, HIGH);  //turn off led1 after 10 seconds
  }
  if (currentTime - led2StartTime >= led2Period)
  {
    if (led2Flag == false)
    {
      digitalWrite(ledPin2, LOW);  //led2 on after 1 second
      led2Flag = true;  //don't do it again
      led2StartTime = currentTime;
    }
    else
    {
      digitalWrite(ledPin2, HIGH);  //led2 off after 1 second      
    }
  }
}

Change the logic to suit your setup.

Bob, thank you very much, now I have something to work with that I haven't found in a tutorial yet. I have to break it down into small pieces, so the first part....

const byte ledPin1 = 10; // this of course is a constant

const byte ledPin2 = 11; //as well as this

unsigned long led1StartTime; // this is a variable, because it is not "defined" here, correct? it is more or less a place holder?

unsigned long led2StartTime; //also a variable

unsigned long led1Period = 10000; //this is a constant because it will not change

unsigned long led2Period = 1000; /this is also, it won't change

boolean led2Flag = false; // this one I am "guessing" I am going to say it is a constant, because you defined it to = false or 0..... I do know that a Boolean has only 2 arguments, they are true or false. 0 or 1, or 0 and any non 0 integer is also considered as a 1.

is this correct so far?

and seriously, I appreciate the help!

this is a variable, because it is not "defined" here, correct?

It is a variable whether or not its value is defined when it is declared.

it is more or less a place holder?

More or less. It is declared here, which makes it a global variable and its value will be defined later in the program.

unsigned long led1Period = 10000; //this is a constant because it will not change

It should/could be declared as a const because its value will not change but it has not been declared as a const in this program.

boolean led2Flag = false; // this one I am "guessing" I am going to say it is a constant

It is not a const (no const in the declaration) nor can it be because its value will be changed later in the program. It is, however, a boolean variable and can only have the value of true or false.

0 or 1, or 0 and any non 0 integer is also considered as a 1.

Generally correct but a future version of the compiler or another compiler could use values other than 0 and not 0 for true/false. Unlikely, but possible, so you should really only use true or false.

It looks like you need to do some more reading on variable types and declaring/defining them. You will usually get away with a sketchy understanding but it makes it more difficult to understand when people offer advice and you misunderstand it. For instance, if I suggested declaring a local volatile unsigned long integer in your program what would it mean to you ?

Fredric58:
aarg, you may very well be the best programmer in the world. but if you can’t teach or help me to learn, you are a waste of my time. and I would prefer you’d be that

…chip who isn’t here…

Well, I’m going insane… :slight_smile:

A board like this is more suited to solving particular issues and dealing with specific stumbling blocks, than it is for delivering a blow by blow incremental course on programming. That’s what your threads seem like. So it seems to me that you must not be looking in the right other places for learning. I’m definitely not the worlds best programmer, yet I can solve 99.9% of my problems by doing online research, or writing experimental code.

But if I’m not welcome, I will respect that. Bye.

well thank you, I read everything I can get my hands on, some of it makes sense some doesn't. I have done or followed through 100's of online tutorials and completed the task or project being given.

I have read through all the definitions in the reference section, and again, some make sense and some don't. I can do a lot of things now that I had no idea how to do 3 or 4 weeks ago.

aarg, you are welcome as a seasoned programmer, as a comedian, not so much. just give me a break, and help me through this. this may not be the place to break down a specific program, but! it's short and if you could bear with me and let me go through it, line by line, I believe it would open doors for me. and I would be greatly appreciative.

as for a violatile local int. well the local I believe would appear inside a, say loop, wherein it is locked into that portion of the code, meaning it couldn't accidently be picked up as a global might. violatile, to me is unstable requiring some sort of constraint or special condition. as for me it is either a straight jacket or solitary. I will go look it up though!

I only have a couple more questions. then I will get out of the way......

this part surprised me, I would have thought the opposite. I realize what is below this has a bearing on it, but can you explain it?

digitalWrite(ledPin1, LOW); //led1 on? digitalWrite(ledPin2, HIGH); //led2 off?

and then this question about millis

if (currentTime - led1StartTime >= led1Period)

the way interpret this is: currenttime // is how much time has elapsed [u]since[/u] the clock started? the clock starts as soon as you get to that piece of code?

which seems it would make the, led1StartTime // ZERO?

so if it runs for 7 sec - 0 it is >= led1period // is false .....................8 is false .....................10 is true

so in a sense it is a 10 second timer?

yea I know it's elementary, but if I can get a command on timing and delays I will be on my way

then there will be just 1 more ? later. if I haven't figured it out by then, thanks again

aarg what's your all time favorite dan?

digitalWrite(ledPin1, LOW);  //led1 on?  
digitalWrite(ledPin2, HIGH); //led2 off?

this part surprised me, I would have thought the opposite

It depends on how the LEDs are wired. My test system needs the output pin to the LED to go LOW to turn it on. Remember, I said

Change the logic to suit your setup.

if (currentTime - led1StartTime >= led1Period)

the way interpret this is: currenttime // is how much time has elapsed since the clock started? the clock starts as soon as you get to that piece of code?

No, the start time for the period we are timing starts when we set led1StartTime to the current time from millis(). Note that none of these are real times, just the value from millis() so we are using them for comparisons as to how much time has elapsed between when the start time was saved and the current time.

so in a sense it is a 10 second timer?

That is exactly it. The test will fail until 10 seconds or more has elapsed so the program can go on its way without pausing. When 10 seconds is up we take action.

thanks Bob, I will figure this out I will turn it upside down and inside out till I understand it. I have discovered a HUGE problem. that's my ability to ask the appropriate question. I think. here is the code for a blinking LED, it is correct in that it works, it may not be perfect but it does work. my question is, can this be done. or am I simply wasting time? this code has the blueLed turning on for 10 seconds with a 5s interval between.

where it says in the comment blueLed on. this is also where the redLed needs to start, but! the redLed needs to wait 1s go on 1s and then just go away and it needs to go on with that delay every time the blue goes on. it could even go on at the same time as the blue if it only lasts for 2 seconds. can I use the info / code you sent me, change the logic and make this happen?

unsigned long previousMillis = 0;
unsigned long interval;
//unsigned long redLedStartTime;
//unsigned long redLedPeriod;
//boolean redLedFlag = false;
//const byte blueLed = 10;
//const byte redLed = 11;

void setup() {

  pinMode(blueLed, OUTPUT);
  //pinMode(redLed, OUTPUT);
  //digitalWrite(redLed, LOW);
  //redLedStartTime = millis();

}

void loop()

{
  unsigned long currentMillis = millis();          //get current value of millsecond counter
  if (currentMillis - previousMillis >= interval)  //if the time period has elapsed (method of comparison is rollover safe)
  {
    byte currentState = digitalRead(blueLed);
    if (currentState)
    {
      interval = 5000;                            //blueLed OFF 5 seconds
    }
    else
    {
      interval = 10000;                           //blueLed ON 10 seconds
    }
    digitalWrite(blueLed, !currentState);         //change state of the LDR
    previousMillis = currentMillis;                //save the time of change
  }


}

Fredric58:
this part surprised me, I would have thought the opposite. I realize what is below this has a bearing on it, but can you explain it?

digitalWrite(ledPin1, LOW); //led1 on?
digitalWrite(ledPin2, HIGH); //led2 off?

It depends on how you have the LED wired up. If you have one leg in +5V and the other leg in an output pin, then it takes a LOW to turn it on. If one leg is on ground and the other on the input pin then it takes a HIGH.

HIGH and LOW do NOT mean on and off. They mean the pin gives +5VDC or 0VDC. Depending on the electronics you are controlling, either of those could turn it on or off.

And please don't whine if you don't see the point of someone's help. You didn't pay anyone here. Nobody here owes you anything. And if you have a bad attitude towards our help, then you may well find yourself all on your own with this. We're not employees being paid to help you. We're volunteers. Try to keep that in mind. Don't waste our time. If you have a problem with your code then ask away. If you want someone to teach you how to write code then take a class. They're not usually free.

MANY MANY MANY MANY THANKS, it just CLICKED . guys I really appreciate all you input. I understand it.

this is sooooooo cool!

thanks again!!!!!!!

thank you delta, don't understand your post but thank you anyways.

Fredric58: thank you delta, don't understand your post but thank you anyways.

Which post? The one explaining the difference between on and off and LOW and HIGH? Or the one asking you to quit bitching about arrg's replies?

this part surprised me, I would have thought the opposite. I realize what is below this has a bearing on it, but can you explain it?

digitalWrite(ledPin1, LOW); //led1 on? pin at ground potential
digitalWrite(ledPin2, HIGH); //led2 off? pin at potential x Volts

Electricity 101
Current flows when difference in potential exists.

You are setting one end of the LED ( output device) via processor pins and depending how the other end of the LED is connected ( +something V or ground) current will flow - LED on - difference of potential exists , or not flow - LED off - both ends of LED on same potential , hence no potential difference exists.

Reverse polarized diode will be subject of next lecture.

where it says in the comment blueLed on. this is also where the redLed needs to start, but! the redLed needs to wait 1s go on 1s and then just go away and it needs to go on with that delay every time the blue goes on

Your program has only got the code in it for one lot of timing but there is no reason why you can’t have 2 or more, each with different start times and/or periods.

Look at the code I posted in reply #10. It has 2 tests in it to see whether different periods have ended

  if (currentTime - led1StartTime >= led1Period)

and

  if (currentTime - led2StartTime >= led2Period)

When either of the periods end the appropriate code is run. As it happens the start times are the same, although I made them separate variables for the sake of clarity.

You can use the same “2 sets of timing” approach in your program. Look at Several things at the same time for an extended example of doing and timing more than one period at a time.

well excuse me Delta_G. but aarg and I are close friends, we just don't know it yet. and both avid steely dan fans. in fact I am waiting to hear back as to which tune is his favorite of all time. and I do understand the difference between highs and lows, vs ons offs and how you can flip em with pull downs or ups. and again, i thank you for your input. if you read carefully you will notice that I take blame in my difficulty for learning this, as robin once pointed out, I need to ask the question in the correct manner, in other words, be SPECIFIC. which I have been working on. as for aarg giving me a break, I think we will both agree he has probably mastered programming but not so much yet comedy. though I do give him kudos for trying. very difficult to make it in the comedy world. as for classes, I wish there was one around here, I'd be there today. if I seem a little gruff and rough around the edges it is because I am. so let me offer you a personal apology for twisting your frillies in a wad. btw, it wasn't as you put it bitching, it was subtle with undertones taken from lyrics from one of our favorite bands. are you NOT a steely dan fan?

did you get the "transistor" and a large sum of money to spend or the "chip" who isn't here? I'm going insane

give "Bad Sneakers" a listen

speaking of classes, which I haven't been to in over 40 years, I'm sure they don't have a class specifically for arduinos, remember I'm very new at this, what is the root or say basic language that a community college might offer that would be helpful in programming an arduino? I ask cause we have one down the street. and i'll bet money the councelor isn't going to know what an arduino is. thanks

Look at the code I posted in reply #10. It has 2 tests in it to see whether different periods have ended

yes I am studying that today, taking it apart and putting it back together. and I will check out your link as well

thanks

You're right, probably very few classes for Arduino specifically. But a class in C++ would help you learn the language better. A class in electronics might help you put circuits together. A class in microcontrollers might help you understand the datasheet for the chip on the Arduino.

alright guys, here is the deal. $$$$$$$$$$$$$$$$ I have figured out how to do all the things I want the program to do. individually. ex: I can make the arduino turn on a dark sensor switch for 1 sec every half hour, use hysteresis and when it is dark, turn on my motion sensor for the rest of the night then turn it off at day. not a problem

can write a program that turns on a motion sensor that has a delay until it stabilizes. not a problem

and the other 3 or 4 things...............

the problem IZZZZZZZZZZZZZZZZZZZZZZZZZZ. when I start trying to put them all together. it all goes to shit!

here's what it will do

  1. turn the arduino on (no charge for that!) note NOTHING will run off the 3.3v or 5v power supply. all powers come from the arduino pins.

  2. the arduino will power for 1 second every half hour a LDR circuit with hysteresist, 24/7.

<<<<>>>>

  1. once it is determined it is night it will turn on my motion sensor, it will run continuously then turn back off at day.

  2. the motion sensor must have a stabilize delay of around 30 seconds. but don't use "delay" note: the pir has a high signal and the signal duration is turned all the way back to the minimum which is about 4-5 seconds.

  3. ok we are to the later part. the 1 SECOND signal (LDR) AND the PIR SIGNAL will both trigger the same action. that is in addition to the ldr monitoring day/night (the 1second) to turn on and off the PIR. if it's confusing ask!

  4. the action: (2) OUTPUTS go HIGH. they start at the same time, however, there is a caveat. (1) will go high for 12 seconds. (2) will wait 1s, go on 1s, off and (2) is finished. these outputs will wait till the next clock signal or pir signal and repeat.

this will repeat all night and everything stops at day light except the LDR going on for 1s every half hour.

please personal message if you can do this, and I don't mean TRY to do it. along with what your fee will be. turn around time and payment arrangements. if it is reasonable and I can afford it, we'll go from there.

I tried to explain as well as I can. have a question, just ask!

thanks

thanks Delta_G, c++, good to know i'll visit HCC today and see what they got. as far as electronics, I design and even hand etch my own boards, drill hundreds of teeny tiny holes in em. tedious work.

and the main reasons I got in to wanting to learn this.

I'm trying to decide if I want to send you a bid (I program microcontrollers for a living).

I'm positive I can program any sort of sequence of output based on any sort of inputs but I'm not sure I understand all that you require.

Fredric58: 1. turn the arduino on (no charge for that!) note NOTHING will run off the 3.3v or 5v power supply. all powers come from the arduino pins.

From what I understand, you have a LDR and some PIR sensors correct? I don't understand the requirement for the sensors to run off "arduino pins". Do you mean they are to be powered by I/O pins? I don't understand why you have this requirement. Even low current devices such as PIR sensors can cause damage to the the I/O pins of the Arduino if powered by the I/O pins. Sensor boards like these have capacitors which can draw a lot of current when they first power on.

Won't the Arduino be continuously powered? Why not power the sensors continuously?

Fredric58: 2. the arduino will power for 1 second every half hour

Will the Arduino be on sort of timer? Or do you mean you want the program to become active once every half hour?