[Solved] Computer Time & While Statement

Is it possible to get the current time from my pc and put it to the console so i can more efficiently debug my program?

And ;

#include <avr/interrupt.h>
#include <avr/sleep.h>

const int ldr=A2;				//LDR Sensor
int tempPinA=A0;                             	//Input read pin for LM35_A is Analog Pin 0
int tempPinB=A1;                             	//Input read pin for LM35_B is Analog Pin 1
int outPin=13;                               	//Output pin Pin13
float valA=0;                                	//Variable_A to store the value from sensor_A
float valB=0;                                	//Variable_B to store the value from sensor_B

void softReset()                                //Workaround for SLEEP
{
  asm volatile ("jmp 0");
}

void wake() {

  sleep_disable();
  detachInterrupt (0);
}

void setup() {
  if(analogRead(ldr) < 150)			//At Dusk
  {
    ADCSRA = 0;
    set_sleep_mode(SLEEP_MODE_PWR_DOWN); 	//Set Sleep Mode
    sleep_enable(); 
    noInterrupts ();				//Activate
    attachInterrupt (0, wake, CHANGE);
    interrupts();
    sleep_cpu();                              //ZzZzZzZzZzZz
  }				
  pinMode(outPin, OUTPUT);                    	//Set outPin to output
}
void loop () {	                                //Loop 
  int valA = analogRead(tempPinA);                	//Read the value of sensor_A
  valA = map(valA, 0, 1023, 0, 100);
  int valB = analogRead(tempPinB);                	//Read the value of sensor_B
  valB = map(valB, 0, 1023, 0, 100);
  Serial.begin(9600);                           //Console Debugging
  Serial.println(analogRead(A2),DEC);           //Debug
  delay(500);
  Serial.print(valA);Serial.println(" Degrees Celsius");           //Debug
  delay(500);
  Serial.print(valB);Serial.println(" Degrees Celsius");           //Debug
  delay(500);

  if (valA > valB)                            //Check if temperature_A is greater than temperature_B
  {
    digitalWrite (outPin, HIGH);              	//If temperature_A greater than temperature_B set outPin to ON
  }
  else                                        	//Otherwise
  {
    digitalWrite (outPin, LOW);               	//If temperature_A is equal or lesser set outPin to OFF
  }
  delay(10000UL);                              //Pump 1 minutes
  softReset();
}

If i change;

  if (valA > valB)                            //Check if temperature_A is greater than temperature_B
  {
    digitalWrite (outPin, HIGH);              	//If temperature_A greater than temperature_B set outPin to ON
  }
  else                                        	//Otherwise
  {
    digitalWrite (outPin, LOW);               	//If temperature_A is equal or lesser set outPin to OFF
  }
  delay(10000UL);

to;

while (valA - valB > 5)
 {
    digitalWrite (outPin, HIGH);

Am i writing HIGH until valA is not great than valB by 5 ?

Am i writing HIGH until valA is not great than valB by 5 ?

By itself, you're potentially creating an infinite loop, because the variables aren't being updated in the body of the loop.

    noInterrupts ();				//Activate
    attachInterrupt (0, wake, CHANGE);
    interrupts();

You don't need to disable interrupts to add a new one.

If i change;...to;

That depends on whether you ever update val1 and val2 inside the while loop. snippets-r-us.com is up the road a ways.

Im trying to run a pump for the period that valA is > valB by 5 degrees without using a delay.

Can you please give me an example?

Can you please give me an example?

Blink without delay.

I think i've looked at that example alot, & each and every time, i don't get it.

Blink without delay has about four significant expressions.
There isn't a lot to not get.

What about it don't you understand?

I am under the understanding that after softReset(); pins default to their default value.

I was checking for sleep condition every iteration not once, so maybe i got that wrong or in the wrong place?
So i have been sticking with what works.

And blinkwithoutdelay, even thought its english, i would find it easier to compare with something with values.

And blinkwithoutdelay, even thought its english, i would find it easier to compare with something with values

I'm afraid I don't understand that sentence.

I don't really see why you've got a soft reset in your sketch either.

And blinkwithoutdelay, even thought its english, i would find it easier to compare with something with values.

I don't understand this. The blink without delay example records when it does something, and, on every pass through loop, looks to see if it is time to do something again.

Actually, blink without delay isn't even appropriate for what you are doing.

Im trying to run a pump for the period that valA is > valB by 5 degrees without using a delay.

Why would you need to use delay()? Turn the pump on at some condition, presumably when valA exceeds valB+5. Turn the pump off at some other condition, presumably when valA is no longer greater than valB + 5.

  if (valA >= valB+5)
  {
    digitalWrite (outPin, HIGH); 
  }
  else
  {
    digitalWrite (outPin, LOW);
  }

I am under the impression that sleep goes into setup? Can it go into the loop? , therefore i do not need softreset and can drop the delay also!
Every example has sleep running in setup, does this mean it runs once or does it mean it runs once and stays resident in memory?

And is it possible to get the computer time?

JB_AU:
And is it possible to get the computer time?

I don't believe it is possible to get the Serial Monitor to time-stamp lines. But there are plenty of other programs out there that will. What platform are you on (so we know what to suggest if the following list isn't appropriate).

  • Many people on this list suggest PuTTY quite often. I haven't used it, myself, so I don't know if it has time-stamping capabilities. According to the website it is available for Windows and Unix Platforms. My suspicion is that it is probably ported to many of the Linux varieties, and possibly also to OSX.
  • What I use on my Win7(x64) machine is RealTerm. As far as I know it is only available on Windows. While I haven't used it, it does have time stamping of lines (generates a new time-stamp after a newline) with options to separate the time stamp from the serial data with either a coma or a space. It offers the following time stamp formats: Unix, UnixHex, Matlab, and YMDHS. And can do this while capturing to a file. RealTerm has some quirks, but is quite powerful otherwise. (One of these days I'll probably take a look at PuTTY...)

Basically, you would use the other program instead of the Serial Monitor. (Just remember to close the port in the other program before trying to upload a sketch...)

JB_AU:
I am under the impression that sleep goes into setup? Can it go into the loop?

No, and no.

Sleep stops the program at the point where you execute the sleep, and when the processor is woken it resumes from the same place.

If sleep doesn't go into setup, why does it work then ? Because the above works, i am only now trying to fine tune things, and test some real world (Outside) variables, so i'll now concentrate on timestamps.

So all i have left now is to checkout realterm.

And maybe add this UV Sensor at a later time.

Cheers as always

Realterm failed under win7 HP 32bit for me, but Terminalbpp from;

sites.google.com/site/terminalbpp/

A Okey Dokey and very straight forward to me XD

JB_AU:
Realterm failed under win7 HP 32bit for me, but Terminalbpp from;

sites.google.com/site/terminalbpp/

A Okey Dokey and very straight forward to me XD

After taking a quick glance at the home page for terminalbpp I'll certainly take a good hard look at it. As much as I like and advocate for RealTerm, some of it's quirks are quite off putting for new users as well as for me.

Thanx for the find.