{"id":873,"date":"2025-08-22T11:27:23","date_gmt":"2025-08-22T11:27:23","guid":{"rendered":"https:\/\/tipcontrol.com\/?page_id=873"},"modified":"2025-08-22T11:27:24","modified_gmt":"2025-08-22T11:27:24","slug":"tipcontrol-macros","status":"publish","type":"page","link":"https:\/\/tipcontrol.com\/?page_id=873","title":{"rendered":"TipControl Macros"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Macros &#8211; Introduction<\/h3>\n\n\n\n<p>Macros are used to add user-defined functionality to drivers. They are written in the TipControl language and then added to a driver under a user-defined name. Once added, you can call them through <code>drv.&lt;driverName>.&lt;macroName><\/code>, for example, <code>drv.led.redToBlue()<\/code> where <code>redToBlue<\/code> could be a macro for gradually turning the LED from red to blue. The same macro can be added to another driver under a different name. Macros can take parameters and are invoked just like the pre-built driver functions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Macros &#8211; Managment<\/h3>\n\n\n\n<p>The best way to manage (add, rename, remove, save) your macros is through the TC Designer. Navigate to the menu via GoTo -> Macro or use the top menu to open the macro editor. Under &#8216;Location&#8217;, you can choose either a driver from the current device where a macro is already installed or select &#8216;Home&#8217; to store your macros locally. Right-clicking on a macro allows you to rename or remove it, while left-clicking loads the macro into the code editor. Using the &#8220;Install Macro to&#8221; field, you can select the device, driver, name, and optional parameters before installing a macro. The save button lets you store your current macro locally.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Macros &#8211; the Parameters<\/h3>\n\n\n\n<p>Macro parameters are entered by their name, separated by commas, e.g., <code>x, y<\/code>. You don&#8217;t need to specify a type for the parameter definition. The last parameter can be extended by using <code>...<\/code>, for example, <code>contact(message, names...)<\/code>. If you add a <code>*<\/code> before a parameter, it means that the parameter is passed directly to the macro, not copied. Thus, changes made to this parameter will affect the variable used when calling the function.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Macros &#8211; Coding<\/h3>\n\n\n\n<p>Macros are coded in the TipControl language. The <code>me<\/code> keyword in a macro refers to the driver it is installed on. For example, if the macro is installed on a digitalIO(led), you can turn it on using <code>me.on()<\/code>. The <code>self<\/code> keyword is used for recursive calls within the macro.<\/p>\n\n\n\n<p>Here&#8217;s a small example of calculating the distance between points (x1, y1) and (x2, y2). In the macro editor, the code would look like this:<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n   dx = lib.math.abs(x1-x2);\n   dy = lib.math.abs(y1-y2);\n   distance = lib.math.sqrt(dx*dx+dy*dy);\n   return(distance);\n}<\/code><\/pre>\n\n\n\n<p>or simplified just<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n   return(lib.math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));\n}<\/code><\/pre>\n\n\n\n<p>now select a device and driver, perhaps call the macro distance and in parameters enter x1,x2,y1,y2. After hitting install the macro should be installed.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Macros &#8211; Introduction Macros are used to add user-defined functionality to drivers. They are written in the TipControl language and then added to a driver under a user-defined name. Once added, you can call them through drv.&lt;driverName>.&lt;macroName>, for example, drv.led.redToBlue() where redToBlue could be a macro for gradually turning the LED from red to blue. [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-873","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/pages\/873","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/tipcontrol.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=873"}],"version-history":[{"count":2,"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/pages\/873\/revisions"}],"predecessor-version":[{"id":975,"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/pages\/873\/revisions\/975"}],"wp:attachment":[{"href":"https:\/\/tipcontrol.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=873"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}