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 ?
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.
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?
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...)
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.
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.