// This line sets the RTC with an explicit date & time, for example to set
// May 21, 2015 at 6pm you would call: (use 24 hour time)
// rtc.adjust(DateTime(2015, 5, 21, 18, 0, 0));
Oh, my bad; I must have copied some of that from "The Internet"..
Invoking / executing / (Yes you're right we used to say "call" a subroutine (Now usually called a function).
Also it may not be clear: You would UPLOAD/RUN this sketch to SET the time. THEN you would write your own code, or comment OUT those lines to come back and run this sketch later to check how the RTC is doing...
Glad to see you are exhibiting the primary Engineering skill: Persistence!
By the way, get into the habit of commenting your lines of code.
Reason, when you are 65, it will remind you what is happening.
Example:
//To set the RTC time:
//uncomment the third line down, as needed make changes to: SS,MM,HH,DD,DT,MM,YY
//upload this sketch, comment the line again, upload this sketch again!!!
//DS3231 SS,MM,HH,DD,DT,MM,YY
//setDS3231time (45,14,18, 1, 8, 5,16); //uncomment to set the RTC time
Some people suggest putting blocks of code into there own separate functions.
In the loop() function you add 'calls' to these functions, loop() runs over and over.
This may help keep your code easier to follow and debug.
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
ReadSensors(); // Each of these is a function defined below
MakeDecisions();
TakeActions();
delay(1000); // Wait 1 second
}//--(end main loop )---
I have used that basic framework in pretty complex sketches, such as controlling a multi-zone high temperature kiln.
RayJorgensen:
I got it running at the right time. It'd be nice on normal time, but that can come later.
Can I set all my sensors as "calls" or "subs"? It would really reduce the lines to sort thru to adjust my ifs based on those static values.
Thanks for the laughs and the info.
Good to hear you are having fun Ray.
One of the keys to programing is getting the code structured, so grouping into functions helps in code layout, execution and the all important debug or "what the ???" part of the "fun"
So for a simple Temperature and Humdity weather station it could be like this;
Its just some pseudo code and C++ just to illustrate the principle.
include libraries
// assign global variables
int TempRead;
int HumdityRead;
int TempDegC;
int HumPercent;
// etc
int TempPin = A0;
int HumPin = A1;
// etc
void setup() {
Serial.begin(9600); // if you are going to display to monitor
// setup I/O
pinMode(TempPin, INPUT);
pinMode(HumPin, INPUT);
etc
}
//== == = Main Loop == == ==
void loop() {
ReadInputs();
ConvertValues();
Display();
SendToMonitor();
}
//== == Functions == == =
void ReadInputs()
{
TempRead = analogRead(TempPin);
HumidityRead = analogRead(HumPin);
}
void ConvertValues()
{
TempDegC = TempRead * some scale factor;
HumPercent = HumidityRead * some scale factor;
}
void Display()
{
// some code that uses TempDeC and HumPercent and puts it on a dislay
}
void SendToMonitor()
{
// some code that sends TempDeC and HumPercent to serial monitor
}
I hope it helps, forum members feel free to comment.
You guys are cracking me up - old fogies teaching/learning, in "old fogy" ways. Being one myself (though rarely admitting it), I'm kinda getting a kick out of it all.
I'm certainly enjoying and learning from all THANKS.
I'm hooking up my waterproof temp sensors.I'll end up having at least 8 of these. Can I use 1 - 4.7 ohm resistor for multiple sensors or do I need 1 for each?
Just cause I'm curious - why the resistor between 5v and signal?
Well, I don't know how to do that nor do I have a desire to!!! How should I notate a "omh" with the keyboard on my computer? Just so we all know what we are talking about. I tested the resistor with the meter to make sure a had the right one.