<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Garden Watering Project: getting started (finally!)</title><link>/challenges-projects/project14/goinggreen/b/blog/posts/garden-watering-project-getting-started-finally</link><description>Ok so I finally got some time to myself (difficult because I have 4 kids going on 5 under 7) to play around with this project. I got my Uno out and my ebay-special 4 relay module. I figured out how it works and what the little picture on ...</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Garden Watering Project: getting started (finally!)</title><link>https://community.element14.com/challenges-projects/project14/goinggreen/b/blog/posts/garden-watering-project-getting-started-finally</link><pubDate>Sun, 13 Aug 2017 07:50:12 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:fa5b7004-3911-4b48-b125-1a8d310c401e</guid><dc:creator>fariez97</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;can I have full codes and circuit of this project?????........I very interested of this project to do my FYP&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=3423&amp;AppID=172&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Garden Watering Project: getting started (finally!)</title><link>https://community.element14.com/challenges-projects/project14/goinggreen/b/blog/posts/garden-watering-project-getting-started-finally</link><pubDate>Fri, 11 Aug 2017 12:53:14 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:fa5b7004-3911-4b48-b125-1a8d310c401e</guid><dc:creator>gecoz</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;Hi Clinton,&lt;/p&gt;&lt;p&gt;Having 2 kids myself, I do sympathise with you! The good news is that getting started with a project is usually the biggest hurdle, and you are over it now! &lt;span&gt;[View:/resized-image/__size/16x16/__key/commentfiles/f7d226abd59f475c9d224a79e3f0ec07-fa5b7004-3911-4b48-b125-1a8d310c401e/contentimage_5F00_1.png:16:16]&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;About the concept of &amp;quot;returning something&amp;quot;, I take the context is coding. I will try and answer your questions the best I can, but I apologise in advance for taking the &amp;quot;long route&amp;quot; for my expalnation, and for repeating things you probably already know along the way.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Arduino programs are basically written using the &amp;quot;&lt;strong&gt;C&lt;/strong&gt;&amp;quot; programming language (you can use &amp;quot;&lt;strong&gt;C++&lt;/strong&gt;&amp;quot; as well, but lets focus on &lt;strong&gt;C&lt;/strong&gt; for the time being). This language allows you to describe your program using what is known as functional programming paradigm: when you want your program to do something, to make the programming easier, you can break the overall task into smaller actions, executed in a defined sequence. Each action thus is fullfilling a logically cohesive &amp;quot;&lt;em&gt;function&lt;/em&gt;&amp;quot;, sometimes generating a result for such processing. Your main program defines the logic (and order) for the execution of the functions (i.e. the main program is &amp;quot;&lt;em&gt;calling&lt;/em&gt;&amp;quot; the functions), and gets back the results of the functions&amp;#39; processing (i.e. the something &amp;quot;&lt;em&gt;returned&lt;/em&gt;&amp;quot; by each function). The function&amp;#39;s code will have a &amp;quot;&lt;strong&gt;return&lt;/strong&gt;&amp;quot; statement, which tells you exactly what is passed back to the main program by the function when it finishes its processing (i.e. upon &amp;quot;&lt;em&gt;exiting&lt;/em&gt;&amp;quot;).&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;To make the coding job easier, people have written and organised function into &amp;quot;&lt;em&gt;libraries&lt;/em&gt;&amp;quot; (they are the equivalent of COTS, applied to the software world). Usually, each library tries to deal and solve one specific problem: the Timer library for Arduino you mention, for instance, deals with the timing problem, and offers some functions to make the use of timing easier for you. This library is written in &lt;strong&gt;C++&lt;/strong&gt;. The reason I mention this is because this language adds another powerful programming paradigm: object oriented programming, and many libraries are written in &lt;strong&gt;C++&lt;/strong&gt;. You don&amp;#39;t need to worry about it at this time, the only thing to remember is that &lt;strong&gt;C++&lt;/strong&gt; will define &amp;quot;&lt;em&gt;objects&lt;/em&gt;&amp;quot;, and objects will have functions and the functions will need to be &amp;quot;&lt;em&gt;called&lt;/em&gt;&amp;quot; on those objects (the functions of an object are known as &amp;quot;&lt;em&gt;methods&lt;/em&gt;&amp;quot;). Therefore, to use a function, you first need to create the object that &amp;quot;owns&amp;quot; the method, then you can call the method using the &amp;quot;&lt;em&gt;dot&lt;/em&gt;&amp;quot; notation (the famous &amp;quot;&lt;strong&gt;t.update()&lt;/strong&gt;&amp;quot; for example is calling the &lt;strong&gt;update()&lt;/strong&gt; method on the &lt;strong&gt;t&lt;/strong&gt; object).&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Now, the idea behind the Timer library is that you can define the timing events you are interested in using by calling the appropriate Timer object method. The list of methods can be found in the Timer.h file. Lets use the &lt;a class="jive-link-external-small" href="https://github.com/JChristensen/Timer/tree/master/examples/blink2" rel="nofollow ugc noopener" target="_blank" title="https://github.com/JChristensen/Timer/tree/master/examples/blink2"&gt;blink2&lt;/a&gt; example from the library source code to try and understand who does what:&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:3ef06e6b-9b7d-4651-b12d-db8be7f5e991:type=c_cpp&amp;amp;text=%2F%2FFlash+two+LEDs+at+different+rates+using+Simon+Monk%27s+Timer+library%0A%2F%2Fhttp%3A%2F%2Fwww.doctormonk.com%2F2012%2F01%2Farduino-timer-library.html%0A%2F%2F%0A%2F%2FJack+Christensen+30Sep2013%0A%2F%2F%0A%2F%2FBeerware+license%3A+Free+for+any+and+all+purposes%2C+but+if+you+find+it%0A%2F%2Fuseful+AND+we+actually+meet+someday%2C+you+can+buy+me+a+beer%21%0A%0A%23include+%22Timer.h%22+%2F%2Fhttp%3A%2F%2Fgithub.com%2FJChristensen%2FTimer%0A%0Aconst+int+LED1+%3D+8%3B+%2F%2Fconnect+one+LED+to+this+pin+%28with+appropriate+current-limiting+resistor+of+course%29%0Aconst+int+LED2+%3D+9%3B+%2F%2Fconnect+another+LED+to+this+pin+%28don%27t+forget+the+resistor%29%0Aconst+unsigned+long+PERIOD1+%3D+1000%3B+%2F%2Fone+second%0Aconst+unsigned+long+PERIOD2+%3D+10000%3B+%2F%2Ften+seconds%0ATimer+t%3B+%2F%2Finstantiate+the+timer+object%0A%0Avoid+setup%28void%29%0A%7B%0A++pinMode%28LED1%2C+OUTPUT%29%3B%0A++pinMode%28LED2%2C+OUTPUT%29%3B%0A++t.oscillate%28LED1%2C+PERIOD1%2C+HIGH%29%3B%0A++t.oscillate%28LED2%2C+PERIOD2%2C+HIGH%29%3B%0A%7D%0A%0Avoid+loop%28void%29%0A%7B%0A++t.update%28%29%3B%0A%7D]&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;First of all, this example will make 2 led blink at different intervals: led 1 will periodically switch on for 1 second then off&amp;nbsp; for 1 second, led 2 will do the same , but with a period of 10 seconds instead. Lets focus on the use of the Timer library.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;The Timer object &amp;quot;&lt;strong&gt;t&lt;/strong&gt;&amp;quot; is created at line 15. In the&lt;strong&gt; setup()&lt;/strong&gt; function. The timer is initialized by defining the 2 events it will have to manage. This is done at line 21 and 22, where the calls &amp;quot;&lt;strong&gt;t.oscillate(...)&lt;/strong&gt;&amp;quot; basically instruct the timer to create 2 events. The &amp;quot;&lt;strong&gt;oscillate&lt;/strong&gt;&amp;quot; method is basically a periodic binary switch, where you can define the output that is switched (LED1 and LED2), how long the period each state of the switch needs to be kept on for (PERIOD1 and PERIOD2) and the initial state of the switch (HIGH for both).&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;As said, those 2 lines only setup the events, but they don&amp;#39;t actually start the switching. That actually happens in the &lt;strong&gt;loop()&lt;/strong&gt; cycle. This is where the &amp;quot;&lt;strong&gt;t.update()&lt;/strong&gt;&amp;quot; comes into play.&lt;/p&gt;&lt;p&gt;Atline 27, the call to the &lt;strong&gt;update(...)&lt;/strong&gt; method will cause the timer object to go through all the events setup (in our case, the 2 events setup before), and for each event, check if the defined period has lapsed, and if so cause the output to switch state (i.e. switch the leds or on off according to the time lapsed).&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;This cycle will go on indefinitely, as the call to update is in the&lt;strong&gt; loop()&lt;/strong&gt; function.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;One final note about the Timer library: the number of events it can handle is limited to 10, so if for your project you need more than 10 events for your timing, this library will not be suitable.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;i hope this helps.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Looking forward to see how your project will progress. &lt;span&gt;[View:/resized-image/__size/16x16/__key/commentfiles/f7d226abd59f475c9d224a79e3f0ec07-fa5b7004-3911-4b48-b125-1a8d310c401e/contentimage_5F00_1.png:16:16]&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Fabio.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;P.S: As for the &amp;quot;ID&amp;quot; question, it depends on the context where you found it used. Typically I&amp;#39;d use ID to assign a unique (and immutable) identifier to a device...&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=3423&amp;AppID=172&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>