[
  {
    "path": ".github/FUNDING.yml",
    "content": "# These are supported funding model platforms\n\ngithub: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]\npatreon: # Replace with a single Patreon username\nopen_collective: # Replace with a single Open Collective username\nko_fi: # Replace with a single Ko-fi username\ntidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel\ncommunity_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry\nliberapay: # Replace with a single Liberapay username\nissuehunt: # Replace with a single IssueHunt username\notechie: # Replace with a single Otechie username\ncustom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']\n"
  },
  {
    "path": "LICENSE",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<https://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<https://www.gnu.org/licenses/why-not-lgpl.html>.\n"
  },
  {
    "path": "README.md",
    "content": "# Otto DIY Robot Arduino Libraries\n\n[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)\n![version](https://img.shields.io/badge/version-13.0-blue)\n\nThis repository has the main [Otto DIY robot](https://www.ottodiy.com/) libraries for Arduino compatible boards.\n\n## Compatible Hardware\n\n- Designed to work mainly with Arduino Nano boards, but most of the code could be adapted to other microcontrollers.\n- Arduino Nano family\n- Arduino Uno\n- Arduino Micro\n- Arduino Mega\n- Arduino Mini\n- Arduino Leonardo\n- ESP8266\n- ESP32 (in development)\n\n:star: Star us on GitHub, it helps!\n\n## Installation:\n\nYou will need the [Arduino IDE on your computer](https://www.arduino.cc/en/software)\nYou can find this library in the Arduino Manager as `OttoDIYLib` by Otto DIY, for quick installation or manually:\n\n1. [Download Otto DIY libraries here](https://github.com/OttoDIY/OttoDIYLib/archive/master.zip)\n2. Open the Arduino IDE and navigate to Sketch > Include Library > Add .ZIP Library...\n3. Navigate to .zip file location that you just downloaded and open it.\n4. You will see in the bottom black area a message that it has been installed. \n5. To verify they are properly installed, go to Sketch > Include Library menu. You should now see the library at the bottom of the drop-down menu.\n\n*For more details or other ways to [install libraries, visit this link](https://www.arduino.cc/en/Guide/Libraries) \n\n## Examples:\n\nYou can find codes in File > Examples > OttoDIYLib.\n\n* `Otto_allmoves.ino` great code for testing all dance movements, sounds and gestures.\n* `Otto_APP.ino` this code is meant to work with the Bluetooth mobile app and module.\n* `Otto_touchmodes.ino` use a touch sensor or button to demo multiple modes.\n* `Otto_avoid.ino` uses the ultrasonic sensor to avoid obstacles.\n* `Otto_CalibrationWalk.ino` simple calibration for the servos.\n* `Otto_happybirthday.ino` plays a melody.\n\n* `Otto_singleladies.ino` dance according to the song.\n* `Otto_smoothcriminal.ino` dance according to the song.\n* `Otto_testSensor.ino` reads data from any analog sensor.\n* `Otto_photoresistor.ino` test light sensor.\n\n## Library Structure\n\nBase set of libraries for any biped robot that uses 4 motors in the legs, like Otto.\n\n* `Otto.h` and `Otto.cpp` contain all the main functions.\n* `Otto_gestures.h` contain all the gesture functions.\n* `Otto_mouths.h` contains all the mouth functions.\n* `Otto_sounds.h` contains all the sound functions.\n* `Otto_matrix.h` contains all the matrix functions.\n* `Oscillator.h` is the main algorithm for the servo's \"smooth\" movement.\n* `SerialCommand.c` is for Bluetooth communication via software serial\n\n### Adding libraries\n\n```cpp\n#include <Otto.h>\nOtto Otto;\n```\n\n### Pins declaration\n\nThese are the default signal connections for the servos and buzzer for AVR Arduino boards in the examples, you can alternatively connect them to different pins if you also change the pin number.\n\n```cpp\n#define LeftLeg 2 // left leg pin\n#define RightLeg 3 // right leg pin\n#define LeftFoot 4 // left foot pin\n#define RightFoot 5 // right foot pin\n#define Buzzer 13 //buzzer pin\n```\n\n### Initialization\n\nWhen starting the program, the 'init' function must be called with the use of servo motor calibration as a parameter. <br/>\nIt is best to place the servo motors in their home position after initialization with the 'home' function.\n\n```cpp\nvoid setup() {\n   Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer);\n   Otto.home();\n}\n```\nThe `home()` function makes the servos move to the center position, with Otto standing in the neutral position.\n\n## Predetermined Functions:\nMany preconfigured movements are available in the library:\n\n### Movements:\nThese are actions that involve the use of the 4 servo motors with the oscillation library combined in synergy and with smooth movements. You can change the values inside the pratensis `()` to alter the speed, direction, and size of the movements.\n\n#### Walk function\n\n```cpp\nOtto.walk(steps, time, dir);\n```\n- `steps` are just how many times you want to repeat that movement without the need for further coding or adding additional rows.\n- `time` (noted as `T` below) translated in milliseconds is the duration of the movement. A higher time value slows the movement; try values ranging from 500 to 3000.\n- `dir` is the direction: `1` for forward or `-1` backward\n\nExample:\n```cpp\nOtto.walk(2, 1000, 1);\n```\nIn this example, `2` is the number of steps, `1000` is \"TIME\" in milliseconds, and it will walk forward.\n\nTry changing T value: Slow=2000 Normal=1000 Fast= 500\n\n```cpp\nOtto.turn(steps, T, dir);\n```\n(# of steps, T, to the left or -1 to the right)\n\n```cpp\nOtto.bend (steps, T, dir);\n```\n\n(# of steps, T, 1 bends to the left or -1 to the right)\n\n```cpp\nOtto.shakeLeg (steps, T, dir);\n```\n(# of steps, T, 1 bends to the left or -1 to the right)\n\n```cpp\nOtto.jump(steps, T);\n```\n(# of steps up, T) This one does not have a dir parameter.\nOtto doesn't really jump. 😜\n\n### Dances:\n\nSimilar to movements but more fun! You can adjust the new parameter `h` \"height or size of the movements\" to make the dance more interesting.\n\n```cpp\nOtto.moonwalker(steps, T, h, dir);\n```\n(# of steps, T, h, 1 to the left or -1 to the right)\n\n`h`: Try changing between 15 and 40.\n\n\nExample:\n```cpp\nOtto.moonwalker(3, 1000, 25,1);\n```\n\n```cpp\nOtto.crusaito(steps, T, h, dir);\n```\n(# of steps, T, h, 1 to the left or -1 to the right)\n\n`h`: Try changing between 20 and 50.\n\n```cpp\nOtto.flapping(steps, T, h, dir);\n```\n(# of steps, T, h, 1 to the front or -1 to the back)\n\n`h`: Try changing between 10 and 30.\n\n```cpp\nOtto.swing(steps, T, h);\n```\n`h`: Try changing between 0 and 50.\n\n```cpp\nOtto.tiptoeSwing(steps, T, h);\n```\n`h`: Try changing between 0 and 50.\n\n```cpp\nOtto.jitter(steps, T, h);\n```\n`h`: Try changing between 5 and 25.\n\n```cpp\nOtto.updown(steps, T, h);  \n```\n`h`: Try changing between 0 and 90.\n\n```cpp\nOtto.ascendingTurn(steps, T, h);\n```\n`h`: Try changing between 5 and 15.\n\n### Sounds:\n\n```\nOtto.sing(songName);\n```\nBy just changing what is inside the () we can change the sounds easily to 19 different ones.\nIt's as simple as copying and pasting in a new row to make the sounds as many times as you like.\n\n- S_connection\n- S_disconnection\n- S_buttonPushed\n- S_mode1\n- S_mode2\n- S_mode3\n- S_surprise\n- S_OhOoh\n- S_OhOoh2\n- S_cuddly\n- S_sleeping\n- S_happy\n- S_superHappy\n- S_happy_short\n- S_sad\n- S_confused\n- S_fart1\n- S_fart2\n- S_fart3\n\nOtto can emit several sounds with the 'sing' function:\n```cpp\nOtto._tone(10, 3, 1);\n```\n\n(noteFrequency, noteDuration, silentDuration)\n\n```cpp\nOtto.bendTones (100, 200, 1.04, 10, 10);\n```\n(initFrequency, finalFrequency, prop, noteDuration, silentDuration)\n\n\n### Gestures:\nFinally, our favorite. This is a combination of the 2 previous functions we learned: sing + walk\nTheir goal is to express emotions by combining sounds with movements at the same time, and if you have the LED matrix, you can show them in the robot's mouth!\n\n```cpp\nOtto.playGesture(gesture);\n```\n- `Otto.playGesture(OttoHappy);`\n- `Otto.playGesture(OttoSuperHappy);`\n- `Otto.playGesture(OttoSad);`\n- `Otto.playGesture(OttoVictory);`\n- `Otto.playGesture(OttoAngry);`\n- `Otto.playGesture(OttoSleeping);`\n- `Otto.playGesture(OttoFretful);`\n- `Otto.playGesture(OttoLove);`\n- `Otto.playGesture(OttoConfused);`\n- `Otto.playGesture(OttoFart);`\n- `Otto.playGesture(OttoWave);`\n- `Otto.playGesture(OttoMagic);`\n- `Otto.playGesture(OttoFail);`\n\nAs you see, it’s very simple, but what it does is quite advanced.\n\n## How to Contribute:\nContributing to this software is warmly welcomed.\n1. Test it, and if you find any problems, then post an issue.\n2. Help us solve the issues or other bugs.\n3. Improve and optimize the current libraries.\nYou can do this [basically by forking](https://help.github.com/en/articles/fork-a-repo), committing modifications, and then [pull a request](https://help.github.com/en/articles/about-pull-requests). \n\nWelcome to the Otto DIY community.\n\n<a href=\"https://discord.gg/CZZytnw\"><img src=\"https://images.squarespace-cdn.com/content/v1/5cd3e3917046805e4d6700e3/1560193788834-KYURUXVSZAIE4XX1ZB2F/ke17ZwdGBToddI8pDm48kK6MRMHcYvpidTm-7i2qDf_lfiSMXz2YNBs8ylwAJx2qLijIv1YpVq4N1RMuCCrb3iJz4vYg48fcPCuGX417dnbl3kVMtgxDPVlhqW83Mmu6GipAUbdvsXjVksOX7D692AoyyEsAbPHhHcQMU6bWQFI/join_discord_button_small.png\" width=\"25%\"></a>\n\n## License\n\nThe OttoDIYLib is licensed under the terms of the GPL Open Source\nlicense and is available for free.\n\n## License: CC-BY-SA\nYou can use all resources of Otto for free, but the Otto DIY website must be included in any redistribution, and remixes must keep the CC-BY-SA license. In open source, the idea is that more people can have access; therefore, if you copy or remix Otto, you must also release it under the same open license, which means you must also release all files to the public.\n\n<a rel=\"license\" href=\"http://creativecommons.org/licenses/by-sa/4.0/\"><img alt=\"Creative Commons License\" style=\"border-width:0\" src=\"https://i.creativecommons.org/l/by-sa/4.0/88x31.png\" /></a><br /><span xmlns:dct=\"http://purl.org/dc/terms/\" property=\"dct:title\">Otto DIY</span> by <a xmlns:cc=\"http://creativecommons.org/ns#\"  property=\"cc:attributionName\"> [www.ottodiy.com](http://www.ottodiy.com) </a> is licensed under a <a rel=\"license\" href=\"http://creativecommons.org/licenses/by-sa/4.0/\">Creative Commons Attribution-ShareAlike 4.0 International License</a>.\n\nBig thanks to all our contributors:\n- @JavierIH\n- @Obijuan\n- @jarsoftelectrical\n- @stembotvn\n- @sfranzyshen\n- @tehniq3\n- @logix5\n- @DiegoSSJ\n- @loreman\n- @justinotherguy\n- @bhm93\n- @wendtbw\n- @agomezgar\n- @BodoMinea\n- @chico\n- @PinkDev1\n- @MXZZ\n- @Pawka\n- @per1234\n- @FedericoBusero\n- @hulkco\n- @mishafarms\n- @nisha-appanah\n- @pabloevaristo\n- @ProgrammerBruce\n- @Nca78\n- @dleval\n- @coliss86\n- @namepatrik\n"
  },
  {
    "path": "examples/Otto_APP/Otto_APP.ino",
    "content": "//--------------------------------------------------------------------------------------------------------------------------------------------------------------------\n//-- Otto DIY App Firmware Version 13 with standard baudrate of 9600 for Bluetooth BLE modules.\n//-- Otto DIY invests time and resources providing open source code and hardware,  \n//-- please support by purchasing kits from (https://www.ottodiy.com)\n//-- Make sure to have installed all libraries: https://github.com/OttoDIY/OttoDIYLib\n//-----------------------------------------------------------------\n//-- If you wish to use this software under Open Source Licensing, you must contribute all your source code to the community and all text above must be included in any redistribution\n//-- in accordance with the GPL when your application is distributed. See http://www.gnu.org/copyleft/gpl.html\n//---------------------\n#include <SerialCommand.h>\nSoftwareSerial BTserial = SoftwareSerial(11,12); // RX pin to 12 and TX pin to 11 on the board\nSerialCommand SCmd(BTserial);\n#include <Otto.h>\nOtto Otto;\n\n#define LeftLeg 2 \n#define RightLeg 3\n#define LeftFoot 4 \n#define RightFoot 5 \n#define Buzzer  13 \n#define DIN A3 // Data In pin\n#define CS A2  // Chip Select pin\n#define CLK A1 // Clock pin\n#define Orientation 1 // 8x8 LED Matrix orientation  Top  = 1, Bottom = 2, Left = 3, Right = 4 \n#define PIN_Button   A0\n#define PIN_ASSEMBLY    10\n\nint T = 1000;\nint moveId = 0;\nint moveSize = 15;\nvolatile bool buttonPushed=false;\nunsigned long int matrix;\nvoid receiveStop() \n{ sendAck(); Otto.home(); sendFinalAck(); }\nvoid receiveLED()\n{ sendAck(); Otto.home(); unsigned long int matrix; char *arg; char *endstr; arg = SCmd.next(); if (arg != NULL) { matrix = strtoul(arg, &endstr, 2); Otto.putMouth(matrix, false); } else { Otto.putMouth(xMouth); delay(2000); Otto.clearMouth(); } sendFinalAck(); }\nvoid recieveBuzzer() \n{ sendAck(); Otto.home(); bool error = false; int frec; int duration; char *arg; arg = SCmd.next(); if (arg != NULL) frec = atoi(arg); else error = true; arg = SCmd.next(); if (arg != NULL) duration = atoi(arg); else error = true; if (error == true) { Otto.putMouth(xMouth); delay(2000); Otto.clearMouth(); } else Otto._tone(frec, duration, 1); sendFinalAck(); }\nvoid receiveTrims() \n{ sendAck(); Otto.home(); int trim_YL, trim_YR, trim_RL, trim_RR; bool error = false; char *arg; arg = SCmd.next(); if (arg != NULL) trim_YL = atoi(arg); else error = true; arg = SCmd.next(); if (arg != NULL) trim_YR = atoi(arg); else error = true; arg = SCmd.next(); if (arg != NULL) trim_RL = atoi(arg); else error = true; arg = SCmd.next(); if (arg != NULL) trim_RR = atoi(arg); else error = true; if (error == true) { Otto.putMouth(xMouth); delay(2000); Otto.clearMouth(); } else { Otto.setTrims(trim_YL, trim_YR, trim_RL, trim_RR); Otto.saveTrimsOnEEPROM(); } sendFinalAck(); }\nvoid receiveServo() \n{ sendAck(); moveId = 30; bool error = false; char *arg; int servo_YL, servo_YR, servo_RL, servo_RR; arg = SCmd.next(); if (arg != NULL) servo_YL = atoi(arg); else error = true; arg = SCmd.next(); if (arg != NULL) servo_YR = atoi(arg); else error = true; arg = SCmd.next(); if (arg != NULL) servo_RL = atoi(arg); else error = true; arg = SCmd.next(); if (arg != NULL) { servo_RR = atoi(arg); } else error = true; if (error == true) { Otto.putMouth(xMouth); delay(2000); Otto.clearMouth(); } else { int servoPos[4] = {servo_YL, servo_YR, servo_RL, servo_RR}; Otto._moveServos(200, servoPos); } sendFinalAck(); }\nvoid receiveMovement() \n{ sendAck(); if (Otto.getRestState() == true) Otto.setRestState(false); char *arg; arg = SCmd.next(); if (arg != NULL) moveId = atoi(arg); else { Otto.putMouth(xMouth); delay(2000); Otto.clearMouth(); moveId = 0; } arg = SCmd.next(); if (arg != NULL) T = atoi(arg); else T = 1000; arg = SCmd.next(); if (arg != NULL) moveSize = atoi(arg); else moveSize = 15; }\nvoid move(int moveId) \n{ bool manualMode = false; switch (moveId) { case 0: Otto.home(); break; case 1: Otto.walk(1, T, 1); break; case 2: Otto.walk(1, T, -1); break; case 3: Otto.turn(1, T, 1); break; case 4: Otto.turn(1, T, -1); break; case 5: Otto.updown(1, T, moveSize); break; case 6: Otto.moonwalker(1, T, moveSize, 1); break; case 7: Otto.moonwalker(1, T, moveSize, -1); break; case 8: Otto.swing(1, T, moveSize); break; case 9: Otto.crusaito(1, T, moveSize, 1); break; case 10: Otto.crusaito(1, T, moveSize, -1); break; case 11: Otto.jump(1, T); break; case 12: Otto.flapping(1, T, moveSize, 1); break; case 13: Otto.flapping(1, T, moveSize, -1); break; case 14: Otto.tiptoeSwing(1, T, moveSize); break; case 15: Otto.bend(1, T, 1); break; case 16: Otto.bend(1, T, -1); break; case 17: Otto.shakeLeg(1, T, 1); break; case 18: Otto.shakeLeg(1, T, -1); break; case 19: Otto.jitter(1, T, moveSize); break; case 20: Otto.ascendingTurn(1, T, moveSize); break; default: manualMode = true; break; } if (!manualMode) sendFinalAck(); }\nvoid receiveGesture()\n{ sendAck(); Otto.home();  int gesture = 0; char *arg; arg = SCmd.next(); if (arg != NULL) gesture = atoi(arg); else     delay(2000); switch (gesture) { case 1: Otto.playGesture(OttoHappy); break; case 2: Otto.playGesture(OttoSuperHappy); break; case 3: Otto.playGesture(OttoSad); break; case 4: Otto.playGesture(OttoSleeping); break; case 5: Otto.playGesture(OttoFart); break; case 6: Otto.playGesture(OttoConfused); break; case 7: Otto.playGesture(OttoLove); break; case 8: Otto.playGesture(OttoAngry); break; case 9: Otto.playGesture(OttoFretful); break; case 10: Otto.playGesture(OttoMagic); break; case 11: Otto.playGesture(OttoWave); break; case 12: Otto.playGesture(OttoVictory); break; case 13: Otto.playGesture(OttoFail); break; default: break; } sendFinalAck(); }\nvoid receiveSing() \n{ sendAck(); Otto.home(); int sing = 0; char *arg; arg = SCmd.next(); if (arg != NULL) sing = atoi(arg); else     delay(2000); switch (sing) { case 1: Otto.sing(S_connection); break; case 2: Otto.sing(S_disconnection); break; case 3: Otto.sing(S_surprise); break; case 4: Otto.sing(S_OhOoh); break; case 5: Otto.sing(S_OhOoh2); break; case 6: Otto.sing(S_cuddly); break; case 7: Otto.sing(S_sleeping); break; case 8: Otto.sing(S_happy); break; case 9: Otto.sing(S_superHappy); break; case 10: Otto.sing(S_happy_short); break; case 11: Otto.sing(S_sad); break; case 12: Otto.sing(S_confused); break; case 13: Otto.sing(S_fart1); break; case 14: Otto.sing(S_fart2); break; case 15: Otto.sing(S_fart3); break; case 16: Otto.sing(S_mode1); break; case 17: Otto.sing(S_mode2); break; case 18: Otto.sing(S_mode3); break; case 19: Otto.sing(S_buttonPushed); break; default: break; } sendFinalAck(); }\nvoid sendAck() \n{ delay(30); Serial.print(F(\"&&\")); Serial.print(F(\"A\")); Serial.println(F(\"%%\")); Serial.flush(); }\nvoid sendFinalAck() \n{ delay(30); Serial.print(F(\"&&\")); Serial.print(F(\"F\")); Serial.println(F(\"%%\")); Serial.flush(); }\nvoid ButtonPushed()\n{ if(!buttonPushed){ buttonPushed=true; Otto.putMouth(smallSurprise); } }\n\nvoid setup() {\n  Serial.begin(9600);\n  BTserial.begin(9600);\n  Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer); //Set the servo pins and Buzzer pin\n  Otto.initMATRIX( DIN, CS, CLK, Orientation);\n  Otto.matrixIntensity(7);\n  pinMode(PIN_ASSEMBLY, INPUT_PULLUP);\n  pinMode(PIN_Button, INPUT);\n\nSCmd.addCommand(\"S\", receiveStop);\nSCmd.addCommand(\"L\", receiveLED);\nSCmd.addCommand(\"T\", recieveBuzzer);\nSCmd.addCommand(\"M\", receiveMovement);\nSCmd.addCommand(\"H\", receiveGesture);\nSCmd.addCommand(\"K\", receiveSing);\nSCmd.addCommand(\"C\", receiveTrims);\nSCmd.addCommand(\"G\", receiveServo);\nSCmd.addDefaultHandler(receiveStop);\n\nOtto.sing(S_connection);\nOtto.home();\nfor (int i = 0; i < 2; i++) {\n  for (int i = 0; i < 8; i++) {\n  Otto.putAnimationMouth(littleUuh, i);\n  delay(150);\n  }\n}\nOtto.putMouth(smile);\nOtto.sing(S_happy);\ndelay(200);\nOtto.putMouth(happyOpen);\n\nwhile (digitalRead(PIN_ASSEMBLY) == LOW) {\n  Otto.home();\n  Otto.sing(S_happy_short);   // sing every 5 seconds so we know OTTO is still working\ndelay(5000);}\n}\n\nvoid loop() {\n  SCmd.readSerial();     \n  if (Otto.getRestState()==false){ move(moveId); }\n}\n"
  },
  {
    "path": "examples/Otto_CalibrationWalk/Otto_CalibrationWalk.ino",
    "content": "//----------------------------------------------------------------\n//-- Otto DIY invests time and resources providing open source code and hardware, \n//-- please support by purchasing kits from https://www.ottodiy.com/\n//-- Make sure to have installed all libraries: https://github.com/OttoDIY/OttoDIYLib\n//-----------------------------------------------------------------\n#include <Arduino.h>\n#include <Wire.h>\n#include <SoftwareSerial.h>\n#include <EEPROM.h>\n#include <Otto.h> //-- Otto Library\nOtto Otto;  //This is Otto!\n\n#define LeftLeg 2 \n#define RightLeg 3\n#define LeftFoot 4 \n#define RightFoot 5 \n#define Buzzer  13 \n\ndouble angle_rad = PI/180.0;\ndouble angle_deg = 180.0/PI;\nint YL;\nint YR;\nint RL;\nint RR;\n\nvoid setup(){\n      Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer); //Set the servo pins and Buzzer pin\n    Serial.begin(9600);\n    YL = EEPROM.read(0);\n    if (YL > 128) YL -= 256;\n    YR = EEPROM.read(1);\n    if (YR > 128) YR -= 256;\n    RL = EEPROM.read(2);\n    if (RL > 128) RL -= 256;\n    RR = EEPROM.read(3);\n    if (RR > 128) RR -= 256;\n    Otto.home();\n    Serial.println(\"OTTO CALIBRATION PROGRAM\");\n    Serial.println(\"PRESS a or z for adjusting Left Leg\");\n    Serial.println(\"PRESS s or x for adjusting Left Foot\");\n    Serial.println(\"PRESS k or m for adjusting Right Leg\");\n    Serial.println(\"PRESS j or n for adjusting Right Foot\");\n    Serial.println();\n    Serial.println(\"PRESS f to test Otto walking\");\n    Serial.println(\"PRESS h to return servos to home position\"); \n}\n\nvoid loop(){\n    int charRead = 0;\n\n    if((Serial.available()) > (0)){\n        charRead = Serial.read();\n    }\n    if(((charRead)==('a' ))){\n        YL++;\n        Otto.setTrims(YL,YR,RL,RR);\n        calib_homePos();\n        Otto.saveTrimsOnEEPROM();\n    }else{\n        if(((charRead)==( 'z' ))){\n            YL--;\n            Otto.setTrims(YL,YR,RL,RR);\n            calib_homePos();\n            Otto.saveTrimsOnEEPROM();\n        }else{\n            if(((charRead)==( 's' ))){\n                RL++;\n                Otto.setTrims(YL,YR,RL,RR);\n                calib_homePos();\n                Otto.saveTrimsOnEEPROM();\n            }else{\n                if(((charRead)==( 'x' ))){\n                    RL--;\n                    Otto.setTrims(YL,YR,RL,RR);\n                    calib_homePos();\n                    Otto.saveTrimsOnEEPROM();\n                }else{\n                    if(((charRead)==( 'k' ))){\n                        YR++;\n                        Otto.setTrims(YL,YR,RL,RR);\n                        calib_homePos();\n                        Otto.saveTrimsOnEEPROM();\n                    }else{\n                        if(((charRead)==( 'm' ))){\n                            YR--;\n                            Otto.setTrims(YL,YR,RL,RR);\n                            calib_homePos();\n                            Otto.saveTrimsOnEEPROM();\n                        }else{\n                            if(((charRead)==( 'j' ))){\n                                RR++;\n                                Otto.setTrims(YL,YR,RL,RR);\n                                calib_homePos();\n                                Otto.saveTrimsOnEEPROM();\n                            }else{\n                                if(((charRead)==( 'n' ))){\n                                    RR--;\n                                    Otto.setTrims(YL,YR,RL,RR);\n                                    calib_homePos();\n                                    Otto.saveTrimsOnEEPROM();\n                                }else{\n                                    if(((charRead)==( 'f' ))){\n                                        Otto.walk(1,1000,1);\n                                    }else{\n                                        if(((charRead)==( 'h' ))){\n                                            Otto.home();\n                                        }else{\n                                        }\n                                    }\n                                }\n                            }\n                        }\n                    }\n                }\n            }\n        }\n    } \n}\n\nvoid calib_homePos() {\n  int servoPos[4];\n  servoPos[0]=90;\n  servoPos[1]=90;\n  servoPos[2]=90;\n  servoPos[3]=90;\n  Otto._moveServos(500, servoPos);\n  Otto.detachServos();\n}\n"
  },
  {
    "path": "examples/Otto_allmoves/Otto_allmoves.ino",
    "content": "//----------------------------------------------------------------\n//-- Otto All moves test\n//-- Otto DIY invests time and resources providing open source code and hardware, \n//-- please support by purchasing kits from https://www.ottodiy.com/\n//-- Make sure to have installed all libraries: https://github.com/OttoDIY/OttoDIYLib\n//-----------------------------------------------------------------\n#include <Otto.h>\nOtto Otto;  //This is Otto!\n\n#define LeftLeg 2 \n#define RightLeg 3\n#define LeftFoot 4 \n#define RightFoot 5 \n#define Buzzer  13 \n#define DIN A3 // Data In pin\n#define CS A2  // Chip Select pin\n#define CLK A1 // Clock pin\n#define Orientation 1 // 8x8 LED Matrix orientation  Top  = 1, Bottom = 2, Left = 3, Right = 4 \n\n///////////////////////////////////////////////////////////////////\n//-- Setup ------------------------------------------------------//\n///////////////////////////////////////////////////////////////////\nvoid setup(){\n  Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer); //Set the servo pins and Buzzer pin\n  Otto.initMATRIX( DIN, CS, CLK, Orientation);\n  Otto.sing(S_connection); //Otto wake up!\n  Otto.home();\n    delay(50);\n  Otto.playGesture(OttoHappy);\n}\n\n///////////////////////////////////////////////////////////////////\n//-- Principal Loop ---------------------------------------------//\n///////////////////////////////////////////////////////////////////\nvoid loop() { \n  Otto.walk(2,1000,1); //2 steps, \"TIME\". IF HIGHER THE VALUE THEN SLOWER (from 600 to 1400), 1 FORWARD\n  Otto.walk(2,1000,-1); //2 steps, T, -1 BACKWARD \n  Otto.turn(2,1000,1);//3 steps turning LEFT\n  Otto._tone(10, 3, 1);\n  Otto.bendTones (100, 200, 1.04, 10, 10);\n    Otto.home();\n    delay(100);  \n  Otto.turn(2,1000,-1);//3 steps turning RIGHT \n  Otto.bend (1,500,1); //usually steps =1, T=2000\n  Otto.bend (1,2000,-1);     \n  Otto.shakeLeg (1,1500, 1);\n    Otto.home();\n    delay(100);\n  Otto.shakeLeg (1,2000,-1);\n  Otto.moonwalker(3, 1000, 25,1); //LEFT\n  Otto.moonwalker(3, 1000, 25,-1); //RIGHT  \n  Otto.crusaito(2, 1000, 20,1);\n  Otto.crusaito(2, 1000, 20,-1);\n    delay(100); \n  Otto.flapping(2, 1000, 20,1);\n  Otto.flapping(2, 1000, 20,-1);\n    delay(100);        \n  Otto.swing(2, 1000, 20);\n  Otto.tiptoeSwing(2, 1000, 20);\n  Otto.jitter(2, 1000, 20); //(small T)\n  Otto.updown(2, 1500, 20);  // 20 = H \"HEIGHT of movement\"T \n  Otto.ascendingTurn(2, 1000, 50);\n  Otto.jump(1,500); // It doesn't really jumpl ;P\n  Otto.home();\n     delay(100); \n  Otto.sing(S_cuddly);\n  Otto.sing(S_OhOoh);\n  Otto.sing(S_OhOoh2);\n  Otto.sing(S_surprise);\n  Otto.sing(S_buttonPushed);       \n  Otto.sing(S_mode1);        \n  Otto.sing(S_mode2);         \n  Otto.sing(S_mode3);  \n  Otto.sing(S_sleeping);\n  Otto.sing(S_fart1);\n  Otto.sing(S_fart2);\n  Otto.sing(S_fart3);\n  Otto.sing(S_happy);\n  Otto.sing(S_happy_short);                   \n  Otto.sing(S_superHappy);   \n  Otto.sing(S_sad);               \n  Otto.sing(S_confused);\n  Otto.sing(S_disconnection);\n    delay(100);  \n  Otto.playGesture(OttoHappy);\n  Otto.playGesture(OttoSuperHappy);\n  Otto.playGesture(OttoSad);\n  Otto.playGesture(OttoVictory); \n  Otto.playGesture(OttoAngry); \n  Otto.playGesture(OttoSleeping);\n  Otto.playGesture(OttoFretful);\n  Otto.playGesture(OttoLove);\n  Otto.playGesture(OttoConfused);        \n  Otto.playGesture(OttoFart);\n  Otto.playGesture(OttoWave);\n  Otto.playGesture(OttoMagic);\n  Otto.playGesture(OttoFail);\n    Otto.home();\n    delay(100);  \n  Otto.putMouth(zero);\n  delay(100);\n  Otto.putMouth(one);\n  delay(100);\n  Otto.putMouth(two);\n  delay(100);\n  Otto.putMouth(three);\n  delay(100);\n  Otto.putMouth(four);\n  delay(100);\n  Otto.putMouth(five);\n  delay(100);\n  Otto.putMouth(6);\n  delay(100);\n  Otto.putMouth(7);\n  delay(100);\n  Otto.putMouth(8);\n  delay(100);\n  Otto.putMouth(9);\n  delay(100);\n  Otto.putMouth(smile);\n  delay(100);\n  Otto.putMouth(happyOpen);\n  delay(100);\n  Otto.putMouth(happyClosed);\n  delay(100);\n  Otto.putMouth(heart);\n  delay(100);\n  Otto.putMouth(angry);\n  delay(100);\n  Otto.putMouth(smallSurprise);\n  delay(100);\n  Otto.putMouth(bigSurprise);\n  delay(100);\n  Otto.putMouth(tongueOut);\n  delay(100);\n  Otto.putMouth(confused);\n  delay(100);\n  Otto.putMouth(21); //diagonal\n  delay(100);\n  Otto.putMouth(27); //interrogation\n  delay(100);\n  Otto.putMouth(23); //sad open\n  delay(100);\n  Otto.putMouth(24); //sad closed\n  delay(100);\n  Otto.putMouth(vamp1);\n  delay(100);\n  Otto.putMouth(vamp2);\n  delay(100);\n  Otto.putMouth(xMouth);\n  delay(100);\n  Otto.putMouth(okMouth);\n  delay(100);\n  Otto.putMouth(thunder);\n  delay(100);\n  Otto.putMouth(lineMouth);\n  delay(100);\n  Otto.putMouth(culito);\n    delay(100); \n  Otto.putAnimationMouth(littleUuh,0);\n  delay(1000); \n  Otto.putAnimationMouth(dreamMouth, 0);\n  delay(1000); \n  Otto.putAnimationMouth(dreamMouth, 1);\n  delay(1000); \n  Otto.putAnimationMouth(dreamMouth, 2);\n  delay(1000); \n}\n"
  },
  {
    "path": "examples/Otto_avoid/Otto_avoid.ino",
    "content": "//---------------------------------------------------------------------------------------------------------------------------------------------------------------------\n// Otto avoid obstacles with ultrasonic sensor sample sketch code\n//-- Otto DIY invests time and resources providing open source code and hardware, \n//-- please support by purchasing kits from https://www.ottodiy.com/\n//-- Make sure to have installed all libraries: https://github.com/OttoDIY/OttoDIYLib\n//--------------------------------------------------------------------------------------------------------------------------------------------------------------------\n#include <Otto.h>\nOtto Otto;  //This is Otto!\n//----------------------------------------------------------------------\n#define LeftLeg 2 \n#define RightLeg 3\n#define LeftFoot 4 \n#define RightFoot 5 \n#define Buzzer  13 \n#define Trigger 8 // ultrasonic sensor trigger pin\n#define Echo 9 // ultrasonic sensor echo pin\n\nlong ultrasound() {\n   long duration, distance;\n   digitalWrite(Trigger,LOW);\n   delayMicroseconds(2);\n   digitalWrite(Trigger, HIGH);\n   delayMicroseconds(10);\n   digitalWrite(Trigger, LOW);\n   duration = pulseIn(Echo, HIGH);\n   distance = duration/58;\n   return distance;\n}\n\n\nvoid setup() {\n  Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer); //Set the servo pins and Buzzer pin\n  pinMode(Trigger, OUTPUT); \n  pinMode(Echo, INPUT); \n\n}\n\nvoid loop() {\n    if (ultrasound() <= 15) {\n      Otto.sing(S_surprise);\n      Otto.playGesture(OttoConfused);\n      Otto.walk(2,1000,-1); // BACKWARD x2\n      Otto.turn(3,1000,1); // LEFT x3\n    }\n    Otto.walk(1,1000,1); // FORWARD x1\n\n}\n"
  },
  {
    "path": "examples/Otto_happybirthday/Otto_happybirthday.ino",
    "content": "//----------------------------------------------------------------\n//-- Otto Happy Birthday\n//-- With this code Otto will walk 5 steps and then sing the happy birthday\n//-- Otto DIY invests time and resources providing open source code and hardware, \n//-- please support by purchasing kits from https://www.ottodiy.com/\n//-- Make sure to have installed all libraries: https://github.com/OttoDIY/OttoDIYLib\n//-----------------------------------------------------------------\n#include <Otto.h>\nOtto Otto;\n\n#define LeftLeg 2 \n#define RightLeg 3\n#define LeftFoot 4 \n#define RightFoot 5 \n#define Buzzer  13 \n\nint speakerPin = 13;\nint length = 28; // the number of notes\nchar notes[] = \"GGAGcB GGAGdc GGxecBA yyecdc\";\nint beats[] = { 2, 2, 8, 8, 8, 16, 1, 2, 2, 8, 8,8, 16, 1, 2,2,8,8,8,8,16, 1,2,2,8,8,8,16 };\nint tempo = 150;\n\nvoid playTone(int tone, int duration) {\n\nfor (long i = 0; i < duration * 1000L; i += tone * 2) {\n   digitalWrite(speakerPin, HIGH);\n   delayMicroseconds(tone);\n   digitalWrite(speakerPin, LOW);\n   delayMicroseconds(tone);\n}\n}\nvoid playNote(char note, int duration) {\n\nchar names[] = {'C', 'D', 'E', 'F', 'G', 'A', 'B',           \n\n                 'c', 'd', 'e', 'f', 'g', 'a', 'b',\n\n                 'x', 'y' };\n\nint tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014,\n\n                 956,  834,  765,  593,  468,  346,  224,\n\n                 655 , 715 };\n\nint SPEE = 5; // play the tone corresponding to the note name\n\n/*\n* Fix for => replace 17 by the size of names array\n*/\nfor (int i = 0; i < sizeof(names); i++) {\n   if (names[i] == note) {\n    int newduration = duration/SPEE;\n     playTone(tones[i], newduration);\n   }\n}\n}\n\nvoid setup() {\n    Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer); //Set the servo pins and Buzzer pin\npinMode(speakerPin, OUTPUT);\n}\n\nvoid loop() {\n  Otto.walk(5,1300,1); \n  Otto.playGesture(OttoSuperHappy);\nfor (int i = 0; i < length; i++) {\n   if (notes[i] == ' ') {\n     delay(beats[i] * tempo); // rest\n   } else {\n     playNote(notes[i], beats[i] * tempo);\n   }\n   // pause between notes\n   delay(tempo);   \n}\n}\n"
  },
  {
    "path": "examples/Otto_photoresistorTest/Otto_photoresistorTest.ino",
    "content": "// Define the pin to which the photoresistor is connected\nconst int photoresistorPin = A0;\nint voltage_intensity = 0;\nint light_perc = 0;\nint sensorValue = 0;\n\nvoid setup() {\n  // Initialize Serial communication\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  // Read the analog value from the photoresistor\n  sensorValue = 1023. - analogRead(photoresistorPin);\n  voltage_intensity = (5.0/1023.) * sensorValue;\n  light_perc = (voltage_intensity/5.0)*100.0; //converting values to percentages\n\n  // Print the sensor value to the Serial Monitor\n  Serial.print(\"Light Percentage: \");\n  Serial.print(light_perc);\n  Serial.println(\"%\");\n\n  // Wait for a short delay\n  delay(500);\n}\n"
  },
  {
    "path": "examples/Otto_singleladies/Otto_singleladies.ino",
    "content": "//----------------------------------------------------------------\n//-- Otto Dance single ladies\n//-- This code will make Otto dance play the by Beyonce song at the same time and see it in action\n//-- Otto DIY invests time and resources providing open source code and hardware, \n//-- please support by purchasing kits from https://www.ottodiy.com/\n//-- Make sure to have installed all libraries: https://github.com/OttoDIY/OttoDIYLib\n//-----------------------------------------------------------------\n#include <Servo.h>\n#include <Oscillator.h>\n#include <EEPROM.h>\n\n#define N_SERVOS 4\n#define EEPROM_TRIM false //Activate for calibration with serial\n\n#define TRIM_RR 18\n#define TRIM_RL 18\n#define TRIM_YR 26\n#define TRIM_YL 18\n\n#define PIN_RL 2\n#define PIN_RR 3\n#define PIN_YR 4\n#define PIN_YL 5\n\n#define INTERVALTIME 10.0 \n\nOscillator servo[N_SERVOS];\n\nvoid drunk (int tempo);\nvoid kickLeft(int tempo);\nvoid kickRight(int tempo);\nvoid pasitos(int steps, int tempo);\nvoid run(int steps, int T=500);\nvoid walk(int steps, int T=1000);\nvoid backyard(int steps, int T=3000);\nvoid moonWalkLeft(int steps, int T=1000);\nvoid moonWalkRight(int steps, int T=1000);\nvoid crusaito(int steps, int T=1000);\nvoid swing(int steps, int T=1000);\nvoid upDown(int steps, int tempo);\nvoid flapping(int steps, int T=1000);\n\nvoid setup()\n{\n  Serial.begin(19200);\n  \n  servo[0].attach(PIN_RR);\n  servo[1].attach(PIN_RL);\n  servo[2].attach(PIN_YR);\n  servo[3].attach(PIN_YL);\n  \n  int trim;\n  \n  if(EEPROM_TRIM){\n    for(int x=0;x<4;x++){\n      trim=EEPROM.read(x);\n      if(trim>128)trim=trim-256;\n      Serial.print(\"TRIM \");\n      Serial.print(x);\n      Serial.print(\" en \");\n      Serial.println(trim);\n      servo[x].SetTrim(trim);\n    }\n  }\n  else{\n    servo[0].SetTrim(TRIM_RR);\n    servo[1].SetTrim(TRIM_RL);\n    servo[2].SetTrim(TRIM_YR);\n    servo[3].SetTrim(TRIM_YL);\n  }\n  \n  for(int i=0;i<4;i++) servo[i].SetPosition(90);\n\n}\n\n// TEMPO: 97 BPM\nint t=620;\ndouble pause=0;\n\nvoid loop() {\n  \n  pasitos(8,t*2);\n  crusaito(1,t);\n  patada(t);\n  delay(t);\n  twist(2,t);\n  twist(3,t/2);\n  upDown(1,t*2);\n  patada(t*2);\n  drunk(t*2);\n  flapping(1,t*2);\n  walk(2,t);\n  walk(1,t*2);\n  backyard(2,t);\n  patada(t*2);\n  flapping(1,t*2);\n  patada(t*2);\n  twist(8,t/2);\n  moonWalkLeft(2,t);\n  crusaito(1,t*2);\n  \n  for(int i=0; i<2 ;i++){\n    lateral_fuerte(0,t);\n    lateral_fuerte(1,t);\n    upDown(1,t*2);\n  }\n  \n  saludo(1,t*2);\n  saludo(1,t);\n  delay(t);\n  swing(3,t);\n  for(int i=0;i<4;i++) servo[i].SetPosition(90);\n  delay(t);\n  \n  lateral_fuerte(0,t);\n  lateral_fuerte(1,t);\n  lateral_fuerte(0,t/2);\n  lateral_fuerte(1,t/2);\n  lateral_fuerte(0,t/2);\n  delay(t/2);\n  lateral_fuerte(0,t);\n  lateral_fuerte(1,t);\n  lateral_fuerte(0,t/2);\n  lateral_fuerte(1,t/2);\n  delay(t);\n  \n  pasitos(1,t*2);\n  pasitos(1,t);\n  delay(t/2);\n  pasitos(1,t*2);\n  pasitos(1,t);\n  delay(t/2);\n     \n  crusaito(2,t);\n  crusaito(1,t*2);\n  crusaito(2,t);\n  crusaito(1,t*2);\n  crusaito(2,t);\n  crusaito(1,t*2);\n  \n  upDown(2,t);\n  crusaito(1,t*2);\n  for(int i=0;i<4;i++) servo[i].SetPosition(90);\n  delay(t/2);\n  pasitos(2,t*2);\n  pasitos(2,t);\n  flapping(1,t*2);\n  upDown(2,t);\n  upDown(1,t*2);\n  \n  for (int i=0; i<4; i++){\n    pasitos(1,t);\n    delay(t);\n  }\n  reverencia1(1,t*4);\n  reverencia2(1,t*4);\n  upDown(1,t);\n  run(2,t/2);\n  patada(t*2);\n\n  lateral_fuerte(0,t);\n  lateral_fuerte(1,t);\n  upDown(2,t);\n  lateral_fuerte(0,t);\n  lateral_fuerte(1,t);\n  upDown(2,t);\n  pasitos(4,t);\n  lateral_fuerte(0,t);\n  lateral_fuerte(1,t);\n  upDown(2,t);\n  \n  patada(t*2);\n  pasitos(2,t);\n  patada(t*2);\n  pasitos(2,t);\n  swing(2,t*2);\n  pasitos(4,t);\n  \n  for (int i=0; i<4; i++){\n    lateral_fuerte(0,t);\n    lateral_fuerte(1,t);\n    lateral_fuerte(0,t/2);\n    lateral_fuerte(1,t/2);\n    lateral_fuerte(0,t/2);\n  delay(t/2);\n  }\n  \n  pasitos(6,t);\n  delay(t);\n  pasitos(1,t);\n  delay(t/2);\n  pasitos(3,t);\n  delay(t/2);\n  swing(4,t);\n  \n  twist(2,t/2);\n  delay(t/2);\n  twist(2,t/2);\n  delay(t/2);\n  \n  drunk(t*2);\n  drunk(t/2);\n  drunk(t*2);\n  delay(t/2);\n  walk(1,t);\n  backyard(1,t);\n  \n  servo[0].SetPosition(110);\n  servo[1].SetPosition(130);\n  delay(t);\n  \n  crusaito(3,t);\n  crusaito(1,2*t);\n  upDown(1,t*2);\n  upDown(2,t/2);\n  \n  kickLeft(t/2);\n  kickRight(t/2);\n  moonWalkLeft(1,t*2);\n  moonWalkLeft(2,t);\n  moonWalkRight(1,t*2);\n  moonWalkRight(2,t);\n  \n  walk(4,t);\n  backyard(4,t);\n  \n  lateral_fuerte(0,t);\n  lateral_fuerte(0,t);\n  lateral_fuerte(1,t);\n  lateral_fuerte(1,t);\n  walk(2,t);\n  backyard(2,t);\n  \n  pasitos(6,t*2);\n  swing(1,t);\n  upDown(1,t);\n  delay(t);\n  upDown(6,t);\n  delay(t);\n  \n  for (int i=0;i<4;i++){\n    lateral_fuerte(0,t);\n    lateral_fuerte(1,t);\n  }\n  \n  delay(t);\n  for (int i=0;i<7;i++){\n    pasitos(2,t);\n    swing(2,t);\n  }\n  \n  pasitos(1,t);\n  crusaito(1,t*2);\n  upDown(1,t);\n  \n  delay(2000);\n  \n\n}\n//////////////////////////////////CONTROL FUNCTIONS//////////////////////////////////\nvoid oscillate(int A[N_SERVOS], int O[N_SERVOS], int T, double phase_diff[N_SERVOS]){\n  for (int i=0; i<4; i++) {\n    servo[i].SetO(O[i]);\n    servo[i].SetA(A[i]);\n    servo[i].SetT(T);\n    servo[i].SetPh(phase_diff[i]);\n  }\n  double ref=millis();\n   for (double x=ref; x<T+ref; x=millis()){\n     for (int i=0; i<4; i++){\n        servo[i].refresh();\n     }\n  }\n}\n\nunsigned long final_time;\nunsigned long interval_time;\nint oneTime;\nint iteration;\nfloat increment[N_SERVOS]; \nint oldPosition[]={90,90,90,90};\n\nvoid moveNServos(int time, int  newPosition[]){\n  for(int i=0;i<N_SERVOS;i++)\tincrement[i] = ((newPosition[i])-oldPosition[i])/(time/INTERVALTIME);\n  \n  final_time =  millis() + time; \n  \n  iteration = 1; \n  while(millis() < final_time){ //Javi del futuro cambia esto  \n      interval_time = millis()+INTERVALTIME;  \n      \n      oneTime=0;      \n      while(millis()<interval_time){\t  \n          if(oneTime<1){ \n              for(int i=0;i<N_SERVOS;i++){\n                  servo[i].SetPosition(oldPosition[i] + (iteration * increment[i]));\n              }\t\t\t\n              iteration++;\n              oneTime++;\n          }\n      }     \n  }   \n\n  for(int i=0;i<N_SERVOS;i++){\t\n    oldPosition[i] = newPosition[i];\n  }   \n}\n////////////////////////////////Dance Steps////////////////////////////////\nvoid pasitos(int steps, int tempo){\n  int move1[4] = {90,120,60,60};\n  int move2[4] = {90,90,90,90};\n  int move3[4] = {60,90,120,120};\n  int move4[4] = {90,90,90,90};\n  \n  for(int i=0; i<steps; i++){\n    pause=millis();\n    moveNServos(tempo*0.25,move1);\n    moveNServos(tempo*0.25,move2);\n    moveNServos(tempo*0.25,move3);\n    moveNServos(tempo*0.25,move4);\n    while(millis()<(pause+t));\n  }\n}\n\nvoid patada (int tempo){\n  for(int i=0;i<4;i++) servo[i].SetPosition(90);\n  servo[0].SetPosition(115);\n  servo[1].SetPosition(120);\n  delay(tempo/4);\n  servo[0].SetPosition(115);\n  servo[1].SetPosition(70);\n  delay(tempo/4);\n  servo[0].SetPosition(100);\n  servo[1].SetPosition(80);\n  delay(tempo/4);\n  servo[0].SetPosition(90);\n  servo[1].SetPosition(90);\n  delay(tempo/4);\n}\n\nvoid twist(int steps, int tempo){\n  int move1[4] = {90,90,50,130};\n  int move2[4] = {90,90,90,90};\n\n    \n  for(int x=0; x<steps; x++){ \n      pause=millis();\n      moveNServos(tempo*0.1,move1);\n      moveNServos(tempo*0.1,move2);\n      while(millis()<(pause+tempo));\n  }\n}\n\nvoid reverencia1 (int steps, int tempo){\n  int move1[4] = {130,50,90,90};\n  int move2[4] = {90,90,90,90};\n    \n  for(int x=0; x<steps; x++){ \n      pause=millis();\n      for(int i=0;i<4;i++) servo[i].SetPosition(90);\n      moveNServos(tempo*0.3,move1);\n      delay(tempo*0.2);\n      moveNServos(tempo*0.3,move2);\n      while(millis()<(pause+tempo));\n  }\n}\n\nvoid reverencia2 (int steps, int tempo){\n  int move1[4] = {130,50,90,90};\n  int move2[4] = {130,50,60,120};\n  int move3[4] = {90,90,90,90};\n\n    \n  for(int x=0; x<steps; x++){ \n      pause=millis();\n      for(int i=0;i<4;i++) servo[i].SetPosition(90);\n      delay(tempo*0.2);\n      moveNServos(tempo*0.05,move1);\n      moveNServos(tempo*0.05,move2);\n      moveNServos(tempo*0.05,move1);\n      moveNServos(tempo*0.05,move2);\n      delay(tempo*0.2);\n      moveNServos(tempo*0.1,move3);\n      while(millis()<(pause+tempo));\n  }\n}\n\nvoid saludo(int steps, int tempo){\n  int move1[4] = {60,60,90,90};\n  int move2[4] = {120,60,90,90};\n    \n  for(int x=0; x<steps; x++){ \n      pause=millis();\n      for(int i=0;i<4;i++) servo[i].SetPosition(90);\n      moveNServos(tempo*0.25,move1);\n      moveNServos(tempo*0.25,move2);\n      moveNServos(tempo*0.25,move1);\n      moveNServos(tempo*0.25,move2);\n      while(millis()<(pause+tempo));\n  }\n}\n\nvoid upDown(int steps, int tempo){\n  int move1[4] = {50,130,90,90};\n  int move2[4] = {90,90,90,90};\n    \n  for(int x=0; x<steps; x++){ \n      pause=millis();\n      moveNServos(tempo*0.2,move1);\n      delay(tempo*0.4);\n      moveNServos(tempo*0.2,move2);\n      while(millis()<(pause+tempo));\n  }\n}\n\nvoid lateral_fuerte(boolean side, int tempo){\n  \n  for(int i=0;i<4;i++) servo[i].SetPosition(90);\n  if (side) servo[0].SetPosition(40);\n  else servo[1].SetPosition(140);\n  delay(tempo/2);\n  servo[0].SetPosition(90);\n  servo[1].SetPosition(90);\n  delay(tempo/2);\n\n}\n\nvoid run(int steps, int T){\n    int A[4]= {10, 10, 10, 10};\n    int O[4] = {0, 0, 0, 0};\n    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)}; \n    \n    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n}\n\nvoid drunk (int tempo){\n  \n  pause=millis();\n  \n  int move1[] = {60,70,90,90};\n  int move2[] = {110,120,90,90};\n  int move3[] = {60,70,90,90};\n  int move4[] = {110,120,90,90};\n  int move5[] = {90,90,90,90};\n  \n  moveNServos(tempo*0.235,move1);\n  moveNServos(tempo*0.235,move2);\n  moveNServos(tempo*0.235,move3);\n  moveNServos(tempo*0.235,move4);\n  moveNServos(tempo*0.06,move5);\n  while(millis()<(pause+tempo));\n\n}\n\nvoid kickLeft(int tempo){\n  for(int i=0;i<4;i++) servo[i].SetPosition(90);\n  delay(tempo);\n  servo[0].SetPosition(50); //pie derecho\n  servo[1].SetPosition(60); //pie izquiero\n  delay(tempo);\n  servo[0].SetPosition(80); //pie derecho\n  servo[1].SetPosition(60); //pie izquiero\n  delay(tempo/4);\n  servo[0].SetPosition(40); //pie derecho\n  servo[1].SetPosition(60); //pie izquiero\n  delay(tempo/4);\n  servo[0].SetPosition(80); //pie derecho\n  servo[1].SetPosition(60); //pie izquiero\n  delay(tempo/4);\n  servo[0].SetPosition(40); //pie derecho\n  servo[1].SetPosition(60); //pie izquiero\n  delay(tempo/4);\n  servo[0].SetPosition(80); //pie derecho\n  servo[1].SetPosition(60); //pie izquiero\n  delay(tempo);\n}\n\nvoid kickRight(int tempo){\nfor(int i=0;i<4;i++) servo[i].SetPosition(90);\n  delay(tempo);\n  servo[0].SetPosition(120); //pie derecho\n  servo[1].SetPosition(130); //pie izquiero\n  delay(tempo);\n  servo[0].SetPosition(120); //pie derecho\n  servo[1].SetPosition(100); //pie izquiero\n  delay(tempo/4);\n  servo[0].SetPosition(120); //pie derecho\n  servo[1].SetPosition(140); //pie izquiero\n  delay(tempo/4);\n  servo[0].SetPosition(120); //pie derecho\n  servo[1].SetPosition(80); //pie izquiero\n  delay(tempo/4);\n  servo[0].SetPosition(120); //pie derecho\n  servo[1].SetPosition(140); //pie izquiero\n  delay(tempo/4);\n  servo[0].SetPosition(120); //pie derecho\n  servo[1].SetPosition(100); //pie izquiero\n  delay(tempo);\n}\n\nvoid walk(int steps, int T){\n    int A[4]= {15, 15, 30, 30};\n    int O[4] = {0, 0, 0, 0};\n    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};\n    \n    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n}\n\nvoid backyard(int steps, int T){\n    int A[4]= {15, 15, 30, 30};\n    int O[4] = {0, 0, 0, 0};\n    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(-90), DEG2RAD(-90)}; \n    \n    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n}\n\nvoid moonWalkRight(int steps, int T){\n    int A[4]= {25, 25, 0, 0};\n    int O[4] = {-15 ,15, 0, 0};\n    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180 + 120), DEG2RAD(90), DEG2RAD(90)}; \n    \n    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n}\n\nvoid moonWalkLeft(int steps, int T){\n    int A[4]= {25, 25, 0, 0};\n    int O[4] = {-15, 15, 0, 0};\n    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180 - 120), DEG2RAD(90), DEG2RAD(90)}; \n    \n    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n}\n\nvoid crusaito(int steps, int T){\n    int A[4]= {25, 25, 30, 30};\n    int O[4] = {- 15, 15, 0, 0};\n    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180 + 120), DEG2RAD(90), DEG2RAD(90)}; \n    \n    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n}\n\nvoid swing(int steps, int T){\n    int A[4]= {25, 25, 0, 0};\n    int O[4] = {-15, 15, 0, 0};\n    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};\n    \n    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n}\n\nvoid flapping(int steps, int T){\n    int A[4]= {15, 15, 8, 8};\n    int O[4] = {-A[0], A[1], 0, 0};\n    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180), DEG2RAD(90), DEG2RAD(-90)};\n    \n    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n}\n"
  },
  {
    "path": "examples/Otto_smoothcriminal/Otto_smoothcriminal.ino",
    "content": "//----------------------------------------------------------------\n//-- Otto Dance smooth criminal\n//-- This code will make Otto dance play the by Michael Jackson song at the same time and see it in action\n//-- https://www.ottodiy.com/\n//-----------------------------------------------------------------\n#include <Servo.h>\n#include <Oscillator.h>\n#include <EEPROM.h>\n#define N_SERVOS 4\n//-- Make sure the servos are in the right pin\n/*                  -------- \n                   |  O  O  |\n                   |--------|\n  RIGHT LEG (YR) 3 |        | LEFT LEG 2 (YL)\n                    -------- \n                    ||     ||\nRIGHT FOOT (RR) 5 |---     ---| LEFT FOOT 4 (RL)  \n*/\n#define EEPROM_TRIM false \n// Activate to take callibration data from internal memory\n#define TRIM_RR 7\n#define TRIM_RL 4\n#define TRIM_YR  4\n#define TRIM_YL -7\n//OTTO.setTrims(-7,-4,-4,7);\n\n#define PIN_RR 5\n#define PIN_RL 4\n#define PIN_YR 3\n#define PIN_YL 2\n\n#define INTERVALTIME 10.0 \n\nOscillator servo[N_SERVOS];\n\nvoid goingUp(int tempo);\nvoid drunk (int tempo);\nvoid noGravity(int tempo);\nvoid kickLeft(int tempo);\nvoid kickRight(int tempo);\nvoid run(int steps, int T=500);\nvoid walk(int steps, int T=1000);\nvoid backyard(int steps, int T=3000);\nvoid backyardSlow(int steps, int T=5000);\nvoid turnLeft(int steps, int T=3000);\nvoid turnRight(int steps, int T=3000);\nvoid moonWalkLeft(int steps, int T=1000);\nvoid moonWalkRight(int steps, int T=1000);\nvoid crusaito(int steps, int T=1000);\nvoid swing(int steps, int T=1000);\nvoid upDown(int steps, int T=1000);\nvoid flapping(int steps, int T=1000);\n\nvoid setup()\n{\n  Serial.begin(19200);\n  \n  servo[0].attach(PIN_RR);\n  servo[1].attach(PIN_RL);\n  servo[2].attach(PIN_YR);\n  servo[3].attach(PIN_YL);\n  \n  //EEPROM.write(0,TRIM_RR);\n  //EEPROM.write(1,TRIM_RL);\n  //EEPROM.write(2,TRIM_YR);\n  //EEPROM.write(3,TRIM_YL);\n  \n  int trim;\n  \n  if(EEPROM_TRIM){\n    for(int x=0;x<4;x++){\n      trim=EEPROM.read(x);\n      if(trim>128)trim=trim-256;\n      Serial.print(\"TRIM \");\n      Serial.print(x);\n      Serial.print(\" en \");\n      Serial.println(trim);\n      servo[x].SetTrim(trim);\n    }\n  }\n  else{\n    servo[0].SetTrim(TRIM_RR);\n    servo[1].SetTrim(TRIM_RL);\n    servo[2].SetTrim(TRIM_YR);\n    servo[3].SetTrim(TRIM_YL);\n  }\n  \n  for(int i=0;i<4;i++) servo[i].SetPosition(90);\n}\n\n// TEMPO: 121 BPM\nint t=495;\ndouble pause=0;\n\nvoid loop()\n{\n // if(Serial.available()){\n  //  char init = Serial.read();\n   // if (init=='X'){\n   //   delay(4000); //3000 - 4500\n   \ndance();\n\n//for(int i=0;i<4;i++) servo[i].SetPosition(90);\n\n          for(int i=0;i<4;i++) servo[i].SetPosition(90);\n   // }\n // }\n}\n\nvoid dance(){\n  primera_parte(); segunda_parte();\n  moonWalkLeft(4,t*2); moonWalkRight(4,t*2); moonWalkLeft(4,t*2); moonWalkRight(4,t*2);\n  primera_parte(); \n  crusaito(1,t*8); crusaito(1,t*7);\n  for (int i=0; i<16; i++){   flapping(1,t/4);   delay(3*t/4); }\n  moonWalkRight(4,t*2); moonWalkLeft(4,t*2);  moonWalkRight(4,t*2);  moonWalkLeft(4,t*2);\n  drunk(t*4);drunk(t*4);  drunk(t*4);  drunk(t*4);\n  kickLeft(t);  kickRight(t);\n  drunk(t*8);  drunk(t*4);drunk(t/2);\n  delay(t*4); \n  drunk(t/2);\n  delay(t*4); \n  walk(2,t*2);\n  backyard(2,t*2);\n  goingUp(t*2);  goingUp(t*1);\n  noGravity(t*2);\n  crusaito(1,t*2);  crusaito(1,t*8); crusaito(1,t*2); crusaito(1,t*8); crusaito(1,t*2); crusaito(1,t*3);\n  delay(t);\n  primera_parte();\n    for (int i=0; i<32; i++){   flapping(1,t/2);  delay(t/2); } \n  for(int i=0;i<4;i++) servo[i].SetPosition(90);}\n\n//////////////////////////////////CONTROL FUNCTIONS//////////////////////////////////\n\nvoid oscillate(int A[N_SERVOS], int O[N_SERVOS], int T, double phase_diff[N_SERVOS]){\n  for (int i=0; i<4; i++) {\n    servo[i].SetO(O[i]);\n    servo[i].SetA(A[i]);\n    servo[i].SetT(T);\n    servo[i].SetPh(phase_diff[i]);\n  }\n  double ref=millis();\n   for (double x=ref; x<T+ref; x=millis()){\n     for (int i=0; i<4; i++){\n        servo[i].refresh();\n     }\n  }\n}\n\nunsigned long final_time;\nunsigned long interval_time;\nint oneTime;\nint iteration;\nfloat increment[N_SERVOS]; \nint oldPosition[]={90,90,90,90};\n\nvoid moveNServos(int time, int  newPosition[]){\n  for(int i=0;i<N_SERVOS;i++)\tincrement[i] = ((newPosition[i])-oldPosition[i])/(time/INTERVALTIME);\n  \n  final_time =  millis() + time; \n  \n  iteration = 1; \n  while(millis() < final_time){ //Javi del futuro cambia esto  \n      interval_time = millis()+INTERVALTIME;  \n      \n      oneTime=0;      \n      while(millis()<interval_time){\t  \n          if(oneTime<1){ \n              for(int i=0;i<N_SERVOS;i++){\n                  servo[i].SetPosition(oldPosition[i] + (iteration * increment[i]));\n              }\t\t\t\n              iteration++;\n              oneTime++;\n          }\n      }     \n  }   \n\n  for(int i=0;i<N_SERVOS;i++){\t\n    oldPosition[i] = newPosition[i];\n  }   \n}\n\n////////////////////////////////Dance Steps////////////////////////////////\n\nvoid goingUp(int tempo){\n  \n      pause=millis();\n      for(int i=0;i<4;i++) servo[i].SetPosition(90);\n      delay(tempo);\n      servo[0].SetPosition(80);\n      servo[1].SetPosition(100);\n      delay(tempo);\n      servo[0].SetPosition(70);\n      servo[1].SetPosition(110);\n      delay(tempo);\n      servo[0].SetPosition(60);\n      servo[1].SetPosition(120);\n      delay(tempo);\n      servo[0].SetPosition(50);\n      servo[1].SetPosition(130);\n      delay(tempo);\n      servo[0].SetPosition(40);\n      servo[1].SetPosition(140);\n      delay(tempo);\n      servo[0].SetPosition(30);\n      servo[1].SetPosition(150);\n      delay(tempo);\n      servo[0].SetPosition(20);\n      servo[1].SetPosition(160);\n      delay(tempo);\n      \n      while(millis()<pause+8*t);\n\n}\n\nvoid primera_parte(){\n  \n  int move1[4] = {60,120,90,90};\n  int move2[4] = {90,90,90,90};\n  int move3[4] = {40,140,90,90};\n  \n  for(int x=0; x<3; x++){\n    for(int i=0; i<3; i++){\n      lateral_fuerte(1,t/2);\n      lateral_fuerte(0,t/4);\n      lateral_fuerte(1,t/4);\n      delay(t);\n    }\n  \n    pause=millis();\n    for(int i=0;i<4;i++) servo[i].SetPosition(90);\n    moveNServos(t*0.4,move1);\n    moveNServos(t*0.4,move2);\n    while(millis()<(pause+t*2));\n  }\n  \n  for(int i=0; i<2; i++){\n    lateral_fuerte(1,t/2);\n    lateral_fuerte(0,t/4);\n    lateral_fuerte(1,t/4);\n    delay(t);\n  }\n    \n  pause=millis();\n  for(int i=0;i<4;i++) servo[i].SetPosition(90);\n  crusaito(1,t*1.4);\n  moveNServos(t*1,move3);\n  for(int i=0;i<4;i++) servo[i].SetPosition(90);\n  while(millis()<(pause+t*4));\n}\n\nvoid segunda_parte(){\n  \n  int move1[4] = {90,90,80,100};\n  int move2[4] = {90,90,100,80};\n  int move3[4] = {90,90,80,100};\n  int move4[4] = {90,90,100,80};\n    \n  int move5[4] = {40,140,80,100};\n  int move6[4] = {40,140,100,80};\n  int move7[4] = {90,90,80,100};\n  int move8[4] = {90,90,100,80};\n       \n  int move9[4] = {40,140,80,100};\n  int move10[4] = {40,140,100,80};\n  int move11[4] = {90,90,80,100};\n  int move12[4] = {90,90,100,80};\n  \n  for(int x=0; x<7; x++){ \n    for(int i=0; i<3; i++){\n      pause=millis();\n      moveNServos(t*0.15,move1);\n      moveNServos(t*0.15,move2);\n      moveNServos(t*0.15,move3);\n      moveNServos(t*0.15,move4);\n      while(millis()<(pause+t));\n    }\n    pause=millis();\n    moveNServos(t*0.15,move5);\n    moveNServos(t*0.15,move6);\n    moveNServos(t*0.15,move7);\n    moveNServos(t*0.15,move8);\n    while(millis()<(pause+t));\n  }\n \n  for(int i=0; i<3; i++){\n    pause=millis();\n    moveNServos(t*0.15,move9);\n    moveNServos(t*0.15,move10);\n    moveNServos(t*0.15,move11);\n    moveNServos(t*0.15,move12);\n    while(millis()<(pause+t));\n  }\n}\n\nvoid lateral_fuerte(boolean side, int tempo){\n  \n  for(int i=0;i<4;i++) servo[i].SetPosition(90);\n  if (side) servo[0].SetPosition(40);\n  else servo[1].SetPosition(140);\n  delay(tempo/2);\n  servo[0].SetPosition(90);\n  servo[1].SetPosition(90);\n  delay(tempo/2);\n\n}\n\nvoid drunk (int tempo){\n  \n  pause=millis();\n  \n  int move1[] = {60,70,90,90};\n  int move2[] = {110,120,90,90};\n  int move3[] = {60,70,90,90};\n  int move4[] = {110,120,90,90};\n  \n  moveNServos(tempo*0.235,move1);\n  moveNServos(tempo*0.235,move2);\n  moveNServos(tempo*0.235,move3);\n  moveNServos(tempo*0.235,move4);\n  while(millis()<(pause+tempo));\n\n}\n\n\nvoid noGravity(int tempo){\n  \n  int move1[4] = {120,140,90,90};\n  int move2[4] = {140,140,90,90};\n  int move3[4] = {120,140,90,90};\n  int move4[4] = {90,90,90,90};\n  \n  \n  for(int i=0;i<4;i++) servo[i].SetPosition(90);\n  for(int i=0;i<N_SERVOS;i++) oldPosition[i]=90;\n  moveNServos(tempo*2,move1);\n  moveNServos(tempo*2,move2);\n  delay(tempo*2);\n  moveNServos(tempo*2,move3);\n  moveNServos(tempo*2,move4);\n\n}\n\nvoid kickLeft(int tempo){\n  for(int i=0;i<4;i++) servo[i].SetPosition(90);\n  delay(tempo);\n  servo[0].SetPosition(50); //pie derecho\n  servo[1].SetPosition(70); //pie izquiero\n  delay(tempo);\n  servo[0].SetPosition(80); //pie derecho\n  servo[1].SetPosition(70); //pie izquiero\n  delay(tempo/4);\n  servo[0].SetPosition(30); //pie derecho\n  servo[1].SetPosition(70); //pie izquiero\n  delay(tempo/4);\n  servo[0].SetPosition(80); //pie derecho\n  servo[1].SetPosition(70); //pie izquiero\n  delay(tempo/4);\n  servo[0].SetPosition(30); //pie derecho\n  servo[1].SetPosition(70); //pie izquiero\n  delay(tempo/4);\n  servo[0].SetPosition(80); //pie derecho\n  servo[1].SetPosition(70); //pie izquiero\n  delay(tempo);\n}\n\nvoid kickRight(int tempo){\nfor(int i=0;i<4;i++) servo[i].SetPosition(90);\n  delay(tempo);\n  servo[0].SetPosition(110); //pie derecho\n  servo[1].SetPosition(130); //pie izquiero\n  delay(tempo);\n  servo[0].SetPosition(110); //pie derecho\n  servo[1].SetPosition(100); //pie izquiero\n  delay(tempo/4);\n  servo[0].SetPosition(110); //pie derecho\n  servo[1].SetPosition(150); //pie izquiero\n  delay(tempo/4);\n  servo[0].SetPosition(110); //pie derecho\n  servo[1].SetPosition(80); //pie izquiero\n  delay(tempo/4);\n  servo[0].SetPosition(110); //pie derecho\n  servo[1].SetPosition(150); //pie izquiero\n  delay(tempo/4);\n  servo[0].SetPosition(110); //pie derecho\n  servo[1].SetPosition(100); //pie izquiero\n  delay(tempo);\n}\n\nvoid walk(int steps, int T){\n    int A[4]= {15, 15, 30, 30};\n    int O[4] = {0, 0, 0, 0};\n    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};\n    \n    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n}\n\nvoid run(int steps, int T){\n    int A[4]= {10, 10, 10, 10};\n    int O[4] = {0, 0, 0, 0};\n    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)}; \n    \n    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n}\n\nvoid backyard(int steps, int T){\n    int A[4]= {15, 15, 30, 30};\n    int O[4] = {0, 0, 0, 0};\n    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(-90), DEG2RAD(-90)}; \n    \n    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n}\n\nvoid backyardSlow(int steps, int T){\n    int A[4]= {15, 15, 30, 30};\n    int O[4] = {0, 0, 0, 0};\n    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(-90), DEG2RAD(-90)}; \n    \n    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n}\n\n\nvoid turnLeft(int steps, int T){\n    int A[4]= {20, 20, 10, 30};\n    int O[4] = {0, 0, 0, 0};\n    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)}; \n    \n    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n}\n\nvoid turnRight(int steps, int T){\n    int A[4]= {20, 20, 30, 10};\n    int O[4] = {0, 0, 0, 0};\n    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)}; \n    \n    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n}\n\nvoid moonWalkRight(int steps, int T){\n    int A[4]= {25, 25, 0, 0};\n    int O[4] = {-15 ,15, 0, 0};\n    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180 + 120), DEG2RAD(90), DEG2RAD(90)}; \n    \n    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n}\n\nvoid moonWalkLeft(int steps, int T){\n    int A[4]= {25, 25, 0, 0};\n    int O[4] = {-15, 15, 0, 0};\n    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180 - 120), DEG2RAD(90), DEG2RAD(90)}; \n    \n    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n}\n\nvoid crusaito(int steps, int T){\n    int A[4]= {25, 25, 30, 30};\n    int O[4] = {- 15, 15, 0, 0};\n    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180 + 120), DEG2RAD(90), DEG2RAD(90)}; \n    \n    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n}\n\nvoid swing(int steps, int T){\n    int A[4]= {25, 25, 0, 0};\n    int O[4] = {-15, 15, 0, 0};\n    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};\n    \n    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n}\n\nvoid upDown(int steps, int T){\n    int A[4]= {25, 25, 0, 0};\n    int O[4] = {-15, 15, 0, 0};\n    double phase_diff[4] = {DEG2RAD(180), DEG2RAD(0), DEG2RAD(270), DEG2RAD(270)};\n    \n    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n}\n\nvoid flapping(int steps, int T){\n    int A[4]= {15, 15, 8, 8};\n    int O[4] = {-A[0], A[1], 0, 0};\n    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180), DEG2RAD(90), DEG2RAD(-90)};\n    \n    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n}\n\nvoid test(int steps, int T){\n    int A[4]= {15, 15, 8, 8};\n    int O[4] = {-A[0] + 10, A[1] - 10, 0, 0};\n    double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180), DEG2RAD(90), DEG2RAD(-90)};\n    \n    for(int i=0;i<steps;i++)oscillate(A,O, T, phase_diff);\n}\n"
  },
  {
    "path": "examples/Otto_testSensor/Otto_testSensor.ino",
    "content": "//----------------------------------------------------------------\n//-- Otto All moves test\n//-- Otto DIY invests time and resources providing open source code and hardware, \n//-- please support by purchasing kits from https://www.ottodiy.com/\n//-- Make sure to have installed all libraries: https://github.com/OttoDIY/OttoDIYLib\n//-----------------------------------------------------------------\n\n\n///////////////////////////////////////////////////////////////////\n//-- Setup ------------------------------------------------------//\n///////////////////////////////////////////////////////////////////\n\nvoid setup() {\n  Serial.begin(9600);\n\n  pinMode( D5 , OUTPUT);    \n  pinMode(2, OUTPUT);\n    tone(  D5,523 ,125);\n   delay(125);\n  tone(  D5, 587 ,125);\n   delay(125);\n  tone(  D5, 659 ,125);\n   delay(125);\n  tone(  D5, 698 ,125);\n   delay(125);\n  tone(  D5, 784 ,125);\n   delay(125);\n  tone(  D5,880,125);\n   delay(125);\n  tone(  D5,261,125);\n   delay(125);\n\n}\n\n///////////////////////////////////////////////////////////////////\n//-- Principal Loop ---------------------------------------------//\n///////////////////////////////////////////////////////////////////\n\nvoid loop() {\n    digitalWrite(2, LOW);\n    Serial.println(\"LIGHT:\");\n    Serial.print(analogRead(A0));\n    if (1==1) {\n      digitalWrite(2, HIGH);\n      tone(  D5,440,125);\n       delay(125);\n    }\n\n}\n"
  },
  {
    "path": "examples/Otto_touchmodes/Otto_touchmodes.ino",
    "content": "//-----------------------------------------------------------------\n//-- This Otto uses a touch sensor to switch three modes\n//-- Mode 1: Otto avoid obstacles\n//-- Mode 2: Otto follow the hand\n//-- Mode 3: Otto dances!\n//-- Otto DIY invests time and resources providing open source code and hardware, \n//-- please support by purchasing kits from https://www.ottodiy.com/\n//-- Make sure to have installed all libraries: https://github.com/OttoDIY/OttoDIYLib\n//-----------------------------------------------------------------\n#include <Otto.h>\nOtto Otto;  //This is Otto!\n//---------------------------------------------------------\n//-- First step: Make sure the pins for servos are in the right position\n/*             -------- \n              |  O  O  |\n              |--------|\n  RIGHT LEG 3 |        | LEFT LEG 2\n               -------- \n               ||     ||\nRIGHT FOOT 5 |---     ---| LEFT FOOT 4  \n*/\n#define LeftLeg 2 \n#define RightLeg 3\n#define LeftFoot 4 \n#define RightFoot 5 \n#define Buzzer  13 \n#define Trigger 8 // ultrasonic sensor trigger pin\n#define Echo 9 // ultrasonic sensor echo pin\n\nconst int sensorPin = A0;\n\n  long ultrasound() {\n   long duration, distance;\n   digitalWrite(Trigger,LOW);\n   delayMicroseconds(2);\n   digitalWrite(Trigger, HIGH);\n   delayMicroseconds(10);\n   digitalWrite(Trigger, LOW);\n   duration = pulseIn(Echo, HIGH);\n   distance = duration/58;\n   return distance;\n}\nint movement = 0;\nboolean izqder = true; // TEMPO: 97 BPM\nbool obstacleDetected = false;\n///////////////////////////////////////////////////////////////////\n//-- Setup ------------------------------------------------------//\n///////////////////////////////////////////////////////////////////\nvoid setup(){\n  Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer); //Set the servo pins and Buzzer pin\n  pinMode(sensorPin, INPUT);\n  pinMode(Trigger, OUTPUT); \n  pinMode(Echo, INPUT);\n  Otto.home();\n  Otto.sing(S_happy); // a happy Otto :)\n}\n// touch sensor is in \"toggle mode\", initial value LOW\n// program expects HIGH value for first touch\n// and then expects LOW value for second touch\n// and then again HIGH and LOW etc.\n//\n  int estado = HIGH; //first expected touch value\n  \n///////////////////////////////////////////////////////////////////\n//-- Principal Loop ---------------------------------------------//\n///////////////////////////////////////////////////////////////////\nvoid loop() {\n  \n   if (digitalRead(sensorPin) == estado)\n   {\n     if (estado == HIGH)\n     {\n     estado = LOW; //toggle expect value\n     }\n     else\n     {\n      estado = HIGH; //toggle expect value\n     }\n     Otto.sing(S_buttonPushed);\n     movement = movement + 1;\n     delay(500);\n   }\n   if (movement == 1)\n   {\n        if(obstacleDetected){\n          Serial.println(\"OBJETO DETECTADO\"); \n          Otto.sing(S_OhOoh);\n          \n          if (izqder == true)\n          {\n            Otto.walk(2,1000,-1); \n            Otto.turn(2,1000,1);//2 steps turning RIGHT   \n            izqder = false;\n          }\n          else\n          {\n            Otto.walk(2,1000,-1); \n            Otto.turn(2,1000,-1);//2 steps turning LEFT   \n            izqder = true;\n          }\n          \n          //Otto.home(); \n          delay(50); \n          obstacleDetector();\n        } \n        else\n        {\n          Otto.walk(1,500,1); \n          delay(50);\n          //Otto.home();\n          obstacleDetector();\n        }\n   }\n\n   if (movement == 2)\n   {\n      if(obstacleDetected){ \n        Serial.println(\"Object detected\");  \n        Otto.walk(2,1000,1);\n        Otto.home(); \n        //delay(60);\n        obstacleDetector();\n        //delay(10) ;\n        }        \n        else{ \n            obstacleDetector(); \n        } \n   }\n\n   if (movement == 3)\n   {\n      Otto.jitter(10,500,40); \n      Otto.home();\n      Otto.moonwalker(2,1000,30,1);\n      Otto.home();\n      Otto.ascendingTurn(2,500,50); \n      Otto.home();\n      Otto.tiptoeSwing(2,1000,30); \n      Otto.home();\n      Otto.flapping(2,500,40,1);\n      Otto.home();\n      Otto.crusaito(2,3000,40,1);\n      Otto.home();\n      Otto.shakeLeg(2,1000,1);  \n      Otto.home();\n      Otto.sing(S_disconnection);\n      movement = 0;\n   }\n}\n\n///////////////////////////////////////////////////////////////////\n//-- Function to read distance sensor & to update obstacleDetected variable\nvoid obstacleDetector(){\n   int distance = ultrasound();\n        if(distance<15){\n          obstacleDetected = true;\n        }else{\n          obstacleDetected = false;\n        }\n}\n"
  },
  {
    "path": "keywords.txt",
    "content": "#######################################\n# Syntax Coloring Map For OttoDIYLib\n#######################################\n\n#######################################\n# Datatypes (KEYWORD1)\n#######################################\nOtto\tKEYWORD1\n#######################################\n# Methods and Functions (KEYWORD2)\n#######################################\ninit\tKEYWORD2\ninitDC\tKEYWORD2\ninitMATRIX\tKEYWORD2\nhome\tKEYWORD2\nputMouth\tKEYWORD2\nwriteText\tKEYWORD2\nclearMouth\tKEYWORD2\nsing\tKEYWORD2\nwalk\tKEYWORD2\nplayGesture\tKEYWORD2\n#######################################\n# Instances (KEYWORD2)\n#######################################\n\n#######################################\n# Constants (LITERAL1)\n#######################################\nFORWARD\t\t\tLITERAL1\nBACKWARD    \tLITERAL1\nLEFT        \tLITERAL1\nRIGHT       \tLITERAL1\nSMALL       \tLITERAL1\nMEDIUM      \tLITERAL1\nBIG         \tLITERAL1\n\nS_connection        LITERAL1\nS_disconnection     LITERAL1\nS_buttonPushed \t    LITERAL1\nS_mode1 \t\t    LITERAL1\nS_mode2 \t\t    LITERAL1\nS_mode3 \t\t    LITERAL1\nS_surprise \t\t    LITERAL1\nS_OhOoh \t\t    LITERAL1\nS_OhOoh2 \t\t    LITERAL1\nS_cuddly \t\t    LITERAL1\nS_sleeping \t\t    LITERAL1\nS_happy \t\t    LITERAL1\nS_superHappy \t    LITERAL1\nS_happy_short \t    LITERAL1\nS_sad \t\t\t    LITERAL1\nS_confused \t\t    LITERAL1\nS_fart1\t\t\t    LITERAL1\nS_fart2\t\t\t    LITERAL1\nS_fart3\t\t\t    LITERAL1\n"
  },
  {
    "path": "library.json",
    "content": "{\n  \"name\": \"OttoDIYLib\",\n  \"version\": \"13.0.0\",\n  \"description\": \"Official Arduino library for controlling original Otto DIY bipedal robots\",\n  \"keywords\": \"otto, ottodiy, robot, servo\",\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"https://github.com/OttoDIY/OttoDIYLib\"\n  },\n  \"authors\": [\n    {\n      \"name\": \"Otto DIY community\",\n      \"url\": \"https://github.com/OttoDIY\",\n      \"maintainer\": true\n    }\n  ],\n  \"license\": \"GPL-3.0-or-later\",\n  \"frameworks\": \"arduino\",\n  \"platforms\": \"atmelavr\"\n}\n"
  },
  {
    "path": "library.properties",
    "content": "name=OttoDIYLib\nversion=13.0.0\nauthor=Otto DIY, Camilo Parra Palacio\nmaintainer=@cparrapa\nsentence=Otto DIY official Arduino Libraries.\nparagraph=OttoDIYLib contains all the main Otto robot libraries to program Arduino avr, ESP8266 or ESP32 compatible boards.\ncategory=Device Control\nurl=https://www.ottodiy.com/\narchitectures=avr, esp8266, esp32\nincludes=Otto.h\n"
  },
  {
    "path": "src/Oscillator.cpp",
    "content": "//--------------------------------------------------------------\n//-- Oscillator.pde\n//-- Generate sinusoidal oscillations in the servos\n//--------------------------------------------------------------\n//-- (c) Juan Gonzalez-Gomez (Obijuan), Dec 2011\n//-- GPL license\n//--------------------------------------------------------------\n#if defined(ARDUINO) && ARDUINO >= 100\n  #include \"Arduino.h\"\n#else\n  #include \"WProgram.h\"\n  #include <pins_arduino.h>\n#endif\n#include \"Oscillator.h\"\n\n//-- This function returns true if another sample\n//-- should be taken (i.e. the TS time has passed since\n//-- the last sample was taken\nbool Oscillator::next_sample()\n{\n  \n  //-- Read current time\n  _currentMillis = millis();\n \n  //-- Check if the timeout has passed\n  if(_currentMillis - _previousMillis > _samplingPeriod) {\n    _previousMillis = _currentMillis;   \n\n    return true;\n  }\n  \n  return false;\n}\n\n//-- Attach an oscillator to a servo\n//-- Input: pin is the arduino pin were the servo\n//-- is connected\nvoid Oscillator::attach(int pin, bool rev)\n{\n  //-- If the oscillator is detached, attach it.\n  if(!_servo.attached()){\n\n    //-- Attach the servo and move it to the home position\n      _servo.attach(pin);\n      _pos = 90; \n      _servo.write(90);\n      _previousServoCommandMillis = millis();\n\n      //-- Initialization of oscilaltor parameters\n      _samplingPeriod=30;\n      _period=2000;\n      _numberSamples = _period/_samplingPeriod;\n      _inc = 2*M_PI/_numberSamples;\n\n      _previousMillis=0;\n\n      //-- Default parameters\n      _amplitude=45;\n      _phase=0;\n      _phase0=0;\n      _offset=0;\n      _stop=false;\n\n      //-- Reverse mode\n      _rev = rev;\n  }\n      \n}\n\n//-- Detach an oscillator from his servo\nvoid Oscillator::detach()\n{\n   //-- If the oscillator is attached, detach it.\n  if(_servo.attached())\n        _servo.detach();\n\n}\n\n/*************************************/\n/* Set the oscillator period, in ms  */\n/*************************************/\nvoid Oscillator::SetT(unsigned int T)\n{\n  //-- Assign the new period\n  _period=T;\n  \n  //-- Recalculate the parameters\n  _numberSamples = _period/_samplingPeriod;\n  _inc = 2*M_PI/_numberSamples;\n};\n\n/*******************************/\n/* Manual set of the position  */\n/******************************/\n\nvoid Oscillator::SetPosition(int position)\n{\n  write(position);\n};\n\n\n/*******************************************************************/\n/* This function should be periodically called                     */\n/* in order to maintain the oscillations. It calculates            */\n/* if another sample should be taken and position the servo if so  */\n/*******************************************************************/\nvoid Oscillator::refresh()\n{\n  \n  //-- Only When TS milliseconds have passed, the new sample is obtained\n  if (next_sample()) {\n  \n      //-- If the oscillator is not stopped, calculate the servo position\n      if (!_stop) {\n        //-- Sample the sine function and set the servo pos\n         int pos = round(_amplitude * sin(_phase + _phase0) + _offset);\n\t       if (_rev) pos=-pos;\n         write(pos+90);\n      }\n\n      //-- Increment the phase\n      //-- It is always increased, even when the oscillator is stop\n      //-- so that the coordination is always kept\n      _phase = _phase + _inc;\n\n  }\n}\n\nvoid Oscillator::write(int position) \n{\n  long currentMillis = millis();\n  if (_diff_limit > 0) {\n    int limit =  max(1,(((int)(currentMillis - _previousServoCommandMillis)) * _diff_limit) / 1000);\n    if (abs(position - _pos) > limit) {\n      _pos += position < _pos ? -limit : limit;\n    } else {\n      _pos = position;\n    }\n  }\n  else {\n      _pos = position;\n  }    \n  _previousServoCommandMillis = currentMillis;\n  _servo.write(_pos + _trim);\n}\n"
  },
  {
    "path": "src/Oscillator.h",
    "content": "//--------------------------------------------------------------\n//-- Oscillator.pde\n//-- Generate sinusoidal oscillations in the servos\n//--------------------------------------------------------------\n//-- (c) Juan Gonzalez-Gomez (Obijuan), Dec 2011\n//-- GPL license\n//--------------------------------------------------------------\n#ifndef Oscillator_h\n#define Oscillator_h\n\n#ifdef ARDUINO_ARCH_ESP32\n#include <ESP32Servo.h>\n#else\n#include <Servo.h>\n#endif\n\n//-- Macro for converting from degrees to radians\n#ifndef DEG2RAD\n  #define DEG2RAD(g) ((g)*M_PI)/180\n#endif\n\nclass Oscillator\n{\n  public:\n    Oscillator(int trim=0) {_trim=trim; _diff_limit = 0; };\n    void attach(int pin, bool rev =false);\n    void detach();\n    \n    void SetA(unsigned int amplitude) {_amplitude=amplitude;};\n    void SetO(int offset) {_offset=offset;};\n    void SetPh(double Ph) {_phase0=Ph;};\n    void SetT(unsigned int period);\n    void SetTrim(int trim){_trim=trim;};\n    void SetLimiter(int diff_limit) { _diff_limit = diff_limit; };\n    void DisableLimiter() { _diff_limit = 0; };\n    int getTrim() {return _trim;};\n    void SetPosition(int position); \n    void Stop() {_stop=true;};\n    void Play() {_stop=false;};\n    void Reset() {_phase=0;};\n    void refresh();\n    int getPosition() { return _pos;}\n\n  private:\n    bool next_sample();  \n    void write(int position);\n    \n  private:\n    //-- Servo that is attached to the oscillator\n    Servo _servo;\n    \n    //-- Oscillators parameters\n    unsigned int _amplitude;  //-- Amplitude (degrees)\n    int _offset;  //-- Offset (degrees)\n    unsigned int _period;  //-- Period (miliseconds)\n    double _phase0;   //-- Phase (radians)  \n    \n    //-- Internal variables\n    int _pos;         //-- Current servo pos\n    int _trim;        //-- Calibration offset\n    double _phase;    //-- Current phase\n    double _inc;      //-- Increment of phase\n    double _numberSamples;        //-- Number of samples\n    unsigned int _samplingPeriod; //-- sampling period (ms)\n    \n    long _previousMillis; \n    long _currentMillis;\n    \n    //-- Oscillation mode. If true, the servo is stopped\n    bool _stop;\n\n    //-- Reverse mode\n    bool _rev;\n\n    // -- Limit of the angle delta send to servos\n    //    This is for smooth movement and preventing Ardino to crash \n    //    because of the high current consumed by servo motors.\n    //    set 0 for disabling the limiter\n    int  _diff_limit;  \n    long _previousServoCommandMillis;\n};\n\n#endif\n"
  },
  {
    "path": "src/Otto.cpp",
    "content": "#if defined(ARDUINO) && ARDUINO >= 100\n  #include \"Arduino.h\"\n#else\n  #include \"WProgram.h\"\n  #include <pins_arduino.h>\n#endif\n#include \"Otto.h\"\n#include <Oscillator.h>\n\nvoid Otto::init(int YL, int YR, int RL, int RR, bool load_calibration, int Buzzer) {\n\n  servo_pins[0] = YL;\n  servo_pins[1] = YR;\n  servo_pins[2] = RL;\n  servo_pins[3] = RR;\n\n  attachServos();\n  isOttoResting=false;\n\n  if (load_calibration) {\n    for (int i = 0; i < 4; i++) {\n      int servo_trim = EEPROM.read(i);\n      if (servo_trim > 128) servo_trim -= 256;\n      servo[i].SetTrim(servo_trim);\n    }\n  }\n\n  //Buzzer pin:\n  pinBuzzer = Buzzer;\n  pinMode(Buzzer,OUTPUT);\n \n}\n///////////////////////////////////////////////////////\nvoid Otto::initMATRIX(int DIN, int CS, int CLK, int rotate){\nledmatrix.init( DIN, CS, CLK, 1, rotate);   // set up Matrix display\n}\nvoid Otto::matrixIntensity(int intensity){\nledmatrix.setIntensity(intensity);\n}\n\n///////////////////////////////////////////////////////////////////\n//-- ATTACH & DETACH FUNCTIONS ----------------------------------//\n///////////////////////////////////////////////////////////////////\nvoid Otto::attachServos(){\n    servo[0].attach(servo_pins[0]);\n    servo[1].attach(servo_pins[1]);\n    servo[2].attach(servo_pins[2]);\n    servo[3].attach(servo_pins[3]);\n}\n\nvoid Otto::detachServos(){\n    servo[0].detach();\n    servo[1].detach();\n    servo[2].detach();\n    servo[3].detach();\n}\n\n///////////////////////////////////////////////////////////////////\n//-- OSCILLATORS TRIMS ------------------------------------------//\n///////////////////////////////////////////////////////////////////\nvoid Otto::setTrims(int YL, int YR, int RL, int RR) {\n  servo[0].SetTrim(YL);\n  servo[1].SetTrim(YR);\n  servo[2].SetTrim(RL);\n  servo[3].SetTrim(RR);\n}\n\nvoid Otto::saveTrimsOnEEPROM() {\n\n  for (int i = 0; i < 4; i++){\n      EEPROM.write(i, servo[i].getTrim());\n  }\n}\n\n///////////////////////////////////////////////////////////////////\n//-- BASIC MOTION FUNCTIONS -------------------------------------//\n///////////////////////////////////////////////////////////////////\nvoid Otto::_moveServos(int time, int  servo_target[]) {\n\n  attachServos();\n  if(getRestState()==true){\n        setRestState(false);\n  }\n\n  final_time =  millis() + time;\n  if(time>10){\n    for (int i = 0; i < 4; i++) increment[i] = (servo_target[i] - servo[i].getPosition()) / (time / 10.0);\n\n    for (int iteration = 1; millis() < final_time; iteration++) {\n      partial_time = millis() + 10;\n      for (int i = 0; i < 4; i++) servo[i].SetPosition(servo[i].getPosition() + increment[i]);\n      while (millis() < partial_time); //pause\n    }\n  }\n  else{\n    for (int i = 0; i < 4; i++) servo[i].SetPosition(servo_target[i]);\n    while (millis() < final_time); //pause\n  }\n\n  // final adjustment to the target. if servo speed limiter is turned on, reaching to the goal may take longer than \n  // requested time.\n  bool f = true;\n  while(f) {\n    f = false;\n    for (int i = 0; i < 4; i++) {\n      if (servo_target[i] != servo[i].getPosition()) {\n        f = true;\n        break;\n      }\n    }\n    if (f) {\n      for (int i = 0; i < 4; i++) {\n        servo[i].SetPosition(servo_target[i]);\n      }\n      partial_time = millis() + 10;\n      while (millis() < partial_time); //pause\n    }\n  };\n}\n\nvoid Otto::_moveSingle(int position, int servo_number) {\nif (position > 180) position = 90;\nif (position < 0) position = 90;\n  attachServos();\n  if(getRestState()==true){\n        setRestState(false);\n  }\nint servoNumber = servo_number;\nif (servoNumber == 0){\n  servo[0].SetPosition(position);\n}\nif (servoNumber == 1){\n  servo[1].SetPosition(position);\n}\nif (servoNumber == 2){\n  servo[2].SetPosition(position);\n}\nif (servoNumber == 3){\n  servo[3].SetPosition(position);\n}\n}\n\nvoid Otto::oscillateServos(int A[4], int O[4], int T, double phase_diff[4], float cycle=1){\n\n  for (int i=0; i<4; i++) {\n    servo[i].SetO(O[i]);\n    servo[i].SetA(A[i]);\n    servo[i].SetT(T);\n    servo[i].SetPh(phase_diff[i]);\n  }\n  double ref=millis();\n   for (double x=ref; x<=T*cycle+ref; x=millis()){\n     for (int i=0; i<4; i++){\n        servo[i].refresh();\n     }\n  }\n}\n\nvoid Otto::_execute(int A[4], int O[4], int T, double phase_diff[4], float steps = 1.0){\n\n  attachServos();\n  if(getRestState()==true){\n        setRestState(false);\n  }\n\n\n  int cycles=(int)steps;\n\n  //-- Execute complete cycles\n  if (cycles >= 1)\n    for(int i = 0; i < cycles; i++)\n      oscillateServos(A,O, T, phase_diff);\n\n  //-- Execute the final not complete cycle\n  oscillateServos(A,O, T, phase_diff,(float)steps-cycles);\n}\n\n///////////////////////////////////////////////////////////////////\n//-- HOME = Otto at rest position -------------------------------//\n///////////////////////////////////////////////////////////////////\nvoid Otto::home(){\n\n  if(isOttoResting==false){ //Go to rest position only if necessary\n\n    int homes[4]={90, 90, 90, 90}; //All the servos at rest position\n    _moveServos(500,homes);   //Move the servos in half a second\n\n    detachServos();\n    isOttoResting=true;\n  }\n}\n\nbool Otto::getRestState(){\n    return isOttoResting;\n}\n\nvoid Otto::setRestState(bool state){\n\n    isOttoResting = state;\n}\n\n///////////////////////////////////////////////////////////////////\n//-- PREDETERMINED MOTION SEQUENCES -----------------------------//\n///////////////////////////////////////////////////////////////////\n//-- Otto movement: Jump\n//--  Parameters:\n//--    steps: Number of steps\n//--    T: Period\n//---------------------------------------------------------\nvoid Otto::jump(float steps, int T){\n\n  int up[]={90,90,150,30};\n  _moveServos(T,up);\n  int down[]={90,90,90,90};\n  _moveServos(T,down);\n}\n\n//---------------------------------------------------------\n//-- Otto gait: Walking  (forward or backward)\n//--  Parameters:\n//--    * steps:  Number of steps\n//--    * T : Period\n//--    * Dir: Direction: FORWARD / BACKWARD\n//---------------------------------------------------------\nvoid Otto::walk(float steps, int T, int dir){\n  //-- Oscillator parameters for walking\n  //-- Hip sevos are in phase\n  //-- Feet servos are in phase\n  //-- Hip and feet are 90 degrees out of phase\n  //--      -90 : Walk forward\n  //--       90 : Walk backward\n  //-- Feet servos also have the same offset (for tiptoe a little bit)\n  int A[4]= {30, 30, 20, 20};\n  int O[4] = {0, 0, 4, -4};\n  double phase_diff[4] = {0, 0, DEG2RAD(dir * -90), DEG2RAD(dir * -90)};\n\n  //-- Let's oscillate the servos!\n  _execute(A, O, T, phase_diff, steps);\n}\n\n//---------------------------------------------------------\n//-- Otto gait: Turning (left or right)\n//--  Parameters:\n//--   * Steps: Number of steps\n//--   * T: Period\n//--   * Dir: Direction: LEFT / RIGHT\n//---------------------------------------------------------\nvoid Otto::turn(float steps, int T, int dir){\n\n  //-- Same coordination than for walking (see Otto::walk)\n  //-- The Amplitudes of the hip's oscillators are not igual\n  //-- When the right hip servo amplitude is higher, the steps taken by\n  //--   the right leg are bigger than the left. So, the robot describes an\n  //--   left arc\n  int A[4]= {30, 30, 20, 20};\n  int O[4] = {0, 0, 4, -4};\n  double phase_diff[4] = {0, 0, DEG2RAD(-90), DEG2RAD(-90)};\n\n  if (dir == LEFT) {\n    A[0] = 30; //-- Left hip servo\n    A[1] = 10; //-- Right hip servo\n  }\n  else {\n    A[0] = 10;\n    A[1] = 30;\n  }\n\n  //-- Let's oscillate the servos!\n  _execute(A, O, T, phase_diff, steps);\n}\n\n//---------------------------------------------------------\n//-- Otto gait: Lateral bend\n//--  Parameters:\n//--    steps: Number of bends\n//--    T: Period of one bend\n//--    dir: RIGHT=Right bend LEFT=Left bend\n//---------------------------------------------------------\nvoid Otto::bend (int steps, int T, int dir){\n\n  //Parameters of all the movements. Default: Left bend\n  int bend1[4]={90, 90, 62, 35};\n  int bend2[4]={90, 90, 62, 105};\n  int homes[4]={90, 90, 90, 90};\n\n  //Time of one bend, constrained in order to avoid movements too fast.\n  //T=max(T, 600);\n  //Changes in the parameters if right direction is chosen\n  if(dir==-1)\n  {\n    bend1[2]=180-35;\n    bend1[3]=180-60;  //Not 65. Otto is unbalanced\n    bend2[2]=180-105;\n    bend2[3]=180-60;\n  }\n\n  //Time of the bend movement. Fixed parameter to avoid falls\n  int T2=800;\n\n  //Bend movement\n  for (int i=0;i<steps;i++)\n  {\n    _moveServos(T2/2,bend1);\n    _moveServos(T2/2,bend2);\n    delay(T*0.8);\n    _moveServos(500,homes);\n  }\n\n}\n\n//---------------------------------------------------------\n//-- Otto gait: Shake a leg\n//--  Parameters:\n//--    steps: Number of shakes\n//--    T: Period of one shake\n//--    dir: RIGHT=Right leg LEFT=Left leg\n//---------------------------------------------------------\nvoid Otto::shakeLeg (int steps,int T,int dir){\n\n  //This variable change the amount of shakes\n  int numberLegMoves=2;\n\n  //Parameters of all the movements. Default: Right leg\n  int shake_leg1[4]={90, 90, 58, 35};\n  int shake_leg2[4]={90, 90, 58, 120};\n  int shake_leg3[4]={90, 90, 58, 60};\n  int homes[4]={90, 90, 90, 90};\n\n  //Changes in the parameters if left leg is chosen\n  if(dir==-1)\n  {\n    shake_leg1[2]=180-35;\n    shake_leg1[3]=180-58;\n    shake_leg2[2]=180-120;\n    shake_leg2[3]=180-58;\n    shake_leg3[2]=180-60;\n    shake_leg3[3]=180-58;\n  }\n\n  //Time of the bend movement. Fixed parameter to avoid falls\n  int T2=1000;\n  //Time of one shake, constrained in order to avoid movements too fast.\n  T=T-T2;\n  T=max(T,200*numberLegMoves);\n\n  for (int j=0; j<steps;j++)\n  {\n  //Bend movement\n  _moveServos(T2/2,shake_leg1);\n  _moveServos(T2/2,shake_leg2);\n\n    //Shake movement\n    for (int i=0;i<numberLegMoves;i++)\n    {\n    _moveServos(T/(2*numberLegMoves),shake_leg3);\n    _moveServos(T/(2*numberLegMoves),shake_leg2);\n    }\n    _moveServos(500,homes); //Return to home position\n  }\n\n  delay(T);\n}\n\n//---------------------------------------------------------\n//-- Otto movement: up & down\n//--  Parameters:\n//--    * steps: Number of jumps\n//--    * T: Period\n//--    * h: Jump height: SMALL / MEDIUM / BIG\n//--              (or a number in degrees 0 - 90)\n//---------------------------------------------------------\nvoid Otto::updown(float steps, int T, int h){\n\n  //-- Both feet are 180 degrees out of phase\n  //-- Feet amplitude and offset are the same\n  //-- Initial phase for the right foot is -90, so that it starts\n  //--   in one extreme position (not in the middle)\n  int A[4]= {0, 0, h, h};\n  int O[4] = {0, 0, h, -h};\n  double phase_diff[4] = {0, 0, DEG2RAD(-90), DEG2RAD(90)};\n\n  //-- Let's oscillate the servos!\n  _execute(A, O, T, phase_diff, steps);\n}\n\n//---------------------------------------------------------\n//-- Otto movement: swinging side to side\n//--  Parameters:\n//--     steps: Number of steps\n//--     T : Period\n//--     h : Amount of swing (from 0 to 50 aprox)\n//---------------------------------------------------------\nvoid Otto::swing(float steps, int T, int h){\n\n  //-- Both feets are in phase. The offset is half the amplitude\n  //-- It causes the robot to swing from side to side\n  int A[4]= {0, 0, h, h};\n  int O[4] = {0, 0, h/2, -h/2};\n  double phase_diff[4] = {0, 0, DEG2RAD(0), DEG2RAD(0)};\n\n  //-- Let's oscillate the servos!\n  _execute(A, O, T, phase_diff, steps);\n}\n\n//---------------------------------------------------------\n//-- Otto movement: swinging side to side without touching the floor with the heel\n//--  Parameters:\n//--     steps: Number of steps\n//--     T : Period\n//--     h : Amount of swing (from 0 to 50 aprox)\n//---------------------------------------------------------\nvoid Otto::tiptoeSwing(float steps, int T, int h){\n\n  //-- Both feets are in phase. The offset is not half the amplitude in order to tiptoe\n  //-- It causes the robot to swing from side to side\n  int A[4]= {0, 0, h, h};\n  int O[4] = {0, 0, h, -h};\n  double phase_diff[4] = {0, 0, 0, 0};\n\n  //-- Let's oscillate the servos!\n  _execute(A, O, T, phase_diff, steps);\n}\n\n//---------------------------------------------------------\n//-- Otto gait: Jitter\n//--  Parameters:\n//--    steps: Number of jitters\n//--    T: Period of one jitter\n//--    h: height (Values between 5 - 25)\n//---------------------------------------------------------\nvoid Otto::jitter(float steps, int T, int h){\n\n  //-- Both feet are 180 degrees out of phase\n  //-- Feet amplitude and offset are the same\n  //-- Initial phase for the right foot is -90, so that it starts\n  //--   in one extreme position (not in the middle)\n  //-- h is constrained to avoid hit the feets\n  h=min(25,h);\n  int A[4]= {h, h, 0, 0};\n  int O[4] = {0, 0, 0, 0};\n  double phase_diff[4] = {DEG2RAD(-90), DEG2RAD(90), 0, 0};\n\n  //-- Let's oscillate the servos!\n  _execute(A, O, T, phase_diff, steps);\n}\n\n//---------------------------------------------------------\n//-- Otto gait: Ascending & turn (Jitter while up&down)\n//--  Parameters:\n//--    steps: Number of bends\n//--    T: Period of one bend\n//--    h: height (Values between 5 - 15)\n//---------------------------------------------------------\nvoid Otto::ascendingTurn(float steps, int T, int h){\n\n  //-- Both feet and legs are 180 degrees out of phase\n  //-- Initial phase for the right foot is -90, so that it starts\n  //--   in one extreme position (not in the middle)\n  //-- h is constrained to avoid hit the feets\n  h=min(13,h);\n  int A[4]= {h, h, h, h};\n  int O[4] = {0, 0, h+4, -h+4};\n  double phase_diff[4] = {DEG2RAD(-90), DEG2RAD(90), DEG2RAD(-90), DEG2RAD(90)};\n\n  //-- Let's oscillate the servos!\n  _execute(A, O, T, phase_diff, steps);\n}\n\n//---------------------------------------------------------\n//-- Otto gait: Moonwalker. Otto moves like Michael Jackson\n//--  Parameters:\n//--    Steps: Number of steps\n//--    T: Period\n//--    h: Height. Typical valures between 15 and 40\n//--    dir: Direction: LEFT / RIGHT\n//---------------------------------------------------------\nvoid Otto::moonwalker(float steps, int T, int h, int dir){\n\n  //-- This motion is similar to that of the caterpillar robots: A travelling\n  //-- wave moving from one side to another\n  //-- The two Otto's feet are equivalent to a minimal configuration. It is known\n  //-- that 2 servos can move like a worm if they are 120 degrees out of phase\n  //-- In the example of Otto, the two feet are mirrored so that we have:\n  //--    180 - 120 = 60 degrees. The actual phase difference given to the oscillators\n  //--  is 60 degrees.\n  //--  Both amplitudes are equal. The offset is half the amplitud plus a little bit of\n  //-   offset so that the robot tiptoe lightly\n\n  int A[4]= {0, 0, h, h};\n  int O[4] = {0, 0, h/2+2, -h/2 -2};\n  int phi = -dir * 90;\n  double phase_diff[4] = {0, 0, DEG2RAD(phi), DEG2RAD(-60 * dir + phi)};\n\n  //-- Let's oscillate the servos!\n  _execute(A, O, T, phase_diff, steps);\n}\n\n//----------------------------------------------------------\n//-- Otto gait: Crusaito. A mixture between moonwalker and walk\n//--   Parameters:\n//--     steps: Number of steps\n//--     T: Period\n//--     h: height (Values between 20 - 50)\n//--     dir:  Direction: LEFT / RIGHT\n//-----------------------------------------------------------\nvoid Otto::crusaito(float steps, int T, int h, int dir){\n\n  int A[4]= {25, 25, h, h};\n  int O[4] = {0, 0, h/2+ 4, -h/2 - 4};\n  double phase_diff[4] = {90, 90, DEG2RAD(0), DEG2RAD(-60 * dir)};\n\n  //-- Let's oscillate the servos!\n  _execute(A, O, T, phase_diff, steps);\n}\n\n//---------------------------------------------------------\n//-- Otto gait: Flapping\n//--  Parameters:\n//--    steps: Number of steps\n//--    T: Period\n//--    h: height (Values between 10 - 30)\n//--    dir: direction: FOREWARD, BACKWARD\n//---------------------------------------------------------\nvoid Otto::flapping(float steps, int T, int h, int dir){\n\n  int A[4]= {12, 12, h, h};\n  int O[4] = {0, 0, h - 10, -h + 10};\n  double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180), DEG2RAD(-90 * dir), DEG2RAD(90 * dir)};\n\n  //-- Let's oscillate the servos!\n  _execute(A, O, T, phase_diff, steps);\n}\n\n///////////////////////////////////////////////////////////////////\n//-- MOUTHS & ANIMATIONS ----------------------------------------//\n///////////////////////////////////////////////////////////////////\nvoid Otto::setLed(byte X, byte Y, byte value){\n  ledmatrix.setDot( X,  Y, value);\n}\n\n\n// EXAMPLE putAnimationMouth(dreamMouth,0);\nvoid Otto::putAnimationMouth(unsigned long int aniMouth, int index){\n\nledmatrix.writeFull(PROGMEM_getAnything (&Gesturetable[aniMouth][index]));\n\n}\n\n//EXAMPLE putMouth(smile);\nvoid Otto::putMouth(unsigned long int mouth, bool predefined){\n  if (predefined){\n// Here a direct entry into the Progmem Mouthttable is used!!\n\nledmatrix.writeFull(PROGMEM_getAnything(&Mouthtable[mouth]));\n  }\n  else{\n    ledmatrix.writeFull(mouth);\n  }\n}\n\n\nvoid Otto::clearMouth(){\n\n  ledmatrix.clearMatrix();\n}\n\nvoid Otto::writeText(const char * s, byte scrollspeed){\n int a ;\n int b ;\n  for(a = 0; s[a] != '\\0'; a++){\n    b = a +1 ;\n    if (b > 9 ) b = 9; // only maximum of nine characters allowed\n  }\n  for(int charNUMBER = 0; charNUMBER <b; charNUMBER++){\n      if ((* s < 48) || (* s > 91)) {\n        if (* s == 32){\n          ledmatrix.sendChar (44, charNUMBER, b, scrollspeed);\n        }\n        else\n        {\n          ledmatrix.sendChar (43, charNUMBER, b, scrollspeed);\n        }\n     }\n      else\n      {\n      ledmatrix.sendChar ((* s - 48), charNUMBER, b, scrollspeed);\n     }\n  * s++;\n  }\n\n}\n\n///////////////////////////////////////////////////////////////////\n//-- SOUNDS -----------------------------------------------------//\n///////////////////////////////////////////////////////////////////\n\nvoid Otto::_tone (float noteFrequency, long noteDuration, int silentDuration){\n\n    // tone(10,261,500);\n    // delay(500);\n\n      if(silentDuration==0){silentDuration=1;}\n\n      tone(Otto::pinBuzzer, noteFrequency, noteDuration);\n      delay(noteDuration);       //milliseconds to microseconds\n      //noTone(PIN_Buzzer);\n      delay(silentDuration);\n}\n\nvoid Otto::bendTones (float initFrequency, float finalFrequency, float prop, long noteDuration, int silentDuration){\n\n  //Examples:\n  //  bendTones (880, 2093, 1.02, 18, 1);\n  //  bendTones (note_A5, note_C7, 1.02, 18, 0);\n\n  if(silentDuration==0){silentDuration=1;}\n\n  if(initFrequency < finalFrequency)\n  {\n      for (int i=initFrequency; i<finalFrequency; i=i*prop) {\n          _tone(i, noteDuration, silentDuration);\n      }\n\n  } else{\n\n      for (int i=initFrequency; i>finalFrequency; i=i/prop) {\n          _tone(i, noteDuration, silentDuration);\n      }\n  }\n}\n\nvoid Otto::sing(int songName){\n  switch(songName){\n\n    case S_connection:\n      _tone(note_E5,50,30);\n      _tone(note_E6,55,25);\n      _tone(note_A6,60,10);\n    break;\n\n    case S_disconnection:\n      _tone(note_E5,50,30);\n      _tone(note_A6,55,25);\n      _tone(note_E6,50,10);\n    break;\n\n    case S_buttonPushed:\n      bendTones (note_E6, note_G6, 1.03, 20, 2);\n      delay(30);\n      bendTones (note_E6, note_D7, 1.04, 10, 2);\n    break;\n\n    case S_mode1:\n      bendTones (note_E6, note_A6, 1.02, 30, 10);  //1318.51 to 1760\n    break;\n\n    case S_mode2:\n      bendTones (note_G6, note_D7, 1.03, 30, 10);  //1567.98 to 2349.32\n    break;\n\n    case S_mode3:\n      _tone(note_E6,50,100); //D6\n      _tone(note_G6,50,80);  //E6\n      _tone(note_D7,300,0);  //G6\n    break;\n\n    case S_surprise:\n      bendTones(800, 2150, 1.02, 10, 1);\n      bendTones(2149, 800, 1.03, 7, 1);\n    break;\n\n    case S_OhOoh:\n      bendTones(880, 2000, 1.04, 8, 3); //A5 = 880\n      delay(200);\n\n      for (int i=880; i<2000; i=i*1.04) {\n           _tone(note_B5,5,10);\n      }\n    break;\n\n    case S_OhOoh2:\n      bendTones(1880, 3000, 1.03, 8, 3);\n      delay(200);\n\n      for (int i=1880; i<3000; i=i*1.03) {\n          _tone(note_C6,10,10);\n      }\n    break;\n\n    case S_cuddly:\n      bendTones(700, 900, 1.03, 16, 4);\n      bendTones(899, 650, 1.01, 18, 7);\n    break;\n\n    case S_sleeping:\n      bendTones(100, 500, 1.04, 10, 10);\n      delay(500);\n      bendTones(400, 100, 1.04, 10, 1);\n    break;\n\n    case S_happy:\n      bendTones(1500, 2500, 1.05, 20, 8);\n      bendTones(2499, 1500, 1.05, 25, 8);\n    break;\n\n    case S_superHappy:\n      bendTones(2000, 6000, 1.05, 8, 3);\n      delay(50);\n      bendTones(5999, 2000, 1.05, 13, 2);\n    break;\n\n    case S_happy_short:\n      bendTones(1500, 2000, 1.05, 15, 8);\n      delay(100);\n      bendTones(1900, 2500, 1.05, 10, 8);\n    break;\n\n    case S_sad:\n      bendTones(880, 669, 1.02, 20, 200);\n    break;\n\n    case S_confused:\n      bendTones(1000, 1700, 1.03, 8, 2);\n      bendTones(1699, 500, 1.04, 8, 3);\n      bendTones(1000, 1700, 1.05, 9, 10);\n    break;\n\n    case S_fart1:\n      bendTones(1600, 3000, 1.02, 2, 15);\n    break;\n\n    case S_fart2:\n      bendTones(2000, 6000, 1.02, 2, 20);\n    break;\n\n    case S_fart3:\n      bendTones(1600, 4000, 1.02, 2, 20);\n      bendTones(4000, 3000, 1.02, 2, 20);\n    break;\n\n  }\n}\n\n///////////////////////////////////////////////////////////////////\n//-- GESTURES ---------------------------------------------------//\n///////////////////////////////////////////////////////////////////\n\nvoid Otto::playGesture(int gesture){\n int gesturePOSITION[4];\n  \n  switch(gesture){\n\n    case OttoHappy: \n        _tone(note_E5,50,30);\n        putMouth(smile);\n        sing(S_happy_short);\n        swing(1,800,20); \n        sing(S_happy_short);\n\n        home();\n        putMouth(happyOpen);\n    break;\n\n\n    case OttoSuperHappy:\n        putMouth(happyOpen);\n        sing(S_happy);\n        putMouth(happyClosed);\n        tiptoeSwing(1,500,20);\n        putMouth(happyOpen);\n        sing(S_superHappy);\n        putMouth(happyClosed);\n        tiptoeSwing(1,500,20); \n\n        home();  \n        putMouth(happyOpen);\n    break;\n\n\n    case OttoSad: \n        putMouth(sad);\n        gesturePOSITION[0] = 110;//int sadPos[6]=      {110, 70, 20, 160};\n        gesturePOSITION[1] = 70;\n         gesturePOSITION[2] = 20;\n          gesturePOSITION[3] = 160;\n        _moveServos(700, gesturePOSITION);     \n        bendTones(880, 830, 1.02, 20, 200);\n        putMouth(sadClosed);\n        bendTones(830, 790, 1.02, 20, 200);  \n        putMouth(sadOpen);\n        bendTones(790, 740, 1.02, 20, 200);\n        putMouth(sadClosed);\n        bendTones(740, 700, 1.02, 20, 200);\n        putMouth(sadOpen);\n        bendTones(700, 669, 1.02, 20, 200);\n        putMouth(sad);\n        delay(500);\n\n        home();\n        delay(300);\n        putMouth(happyOpen);\n    break;\n\n\n    case OttoSleeping:\n    gesturePOSITION[0] = 100;//int bedPos[6]=      {100, 80, 60, 120};\n        gesturePOSITION[1] = 80;\n         gesturePOSITION[2] = 60;\n          gesturePOSITION[3] = 120;\n        _moveServos(700, gesturePOSITION);     \n        for(int i=0; i<4;i++){\n          putAnimationMouth(dreamMouth,0);\n          bendTones (100, 200, 1.04, 10, 10);\n          putAnimationMouth(dreamMouth,1);\n          bendTones (200, 300, 1.04, 10, 10);  \n          putAnimationMouth(dreamMouth,2);\n          bendTones (300, 500, 1.04, 10, 10);   \n          delay(500);\n          putAnimationMouth(dreamMouth,1);\n          bendTones (400, 250, 1.04, 10, 1); \n          putAnimationMouth(dreamMouth,0);\n          bendTones (250, 100, 1.04, 10, 1); \n          delay(500);\n        } \n\n        putMouth(lineMouth);\n        sing(S_cuddly);\n\n        home();  \n        putMouth(happyOpen);\n    break;\n\n\n    case OttoFart:\n    gesturePOSITION[0] = 90;// int fartPos_1[6]=   {90, 90, 145, 122};\n        gesturePOSITION[1] = 90;\n         gesturePOSITION[2] = 145;\n          gesturePOSITION[3] = 122;\n        _moveServos(500,gesturePOSITION);\n        delay(300);     \n        putMouth(lineMouth);\n        sing(S_fart1);  \n        putMouth(tongueOut);\n        delay(250);\n        gesturePOSITION[0] = 90;// int fartPos_2[6]=   {90, 90, 80, 122};\n        gesturePOSITION[1] = 90;\n         gesturePOSITION[2] = 80;\n          gesturePOSITION[3] = 122;\n        _moveServos(500,gesturePOSITION);\n        delay(300);\n        putMouth(lineMouth);\n        sing(S_fart2); \n        putMouth(tongueOut);\n        delay(250);\n        gesturePOSITION[0] = 90;// int fartPos_3[6]=   {90, 90, 145, 80};\n        gesturePOSITION[1] = 90;\n         gesturePOSITION[2] = 145;\n          gesturePOSITION[3] = 80;\n        _moveServos(500,gesturePOSITION);\n        delay(300);\n        putMouth(lineMouth);\n        sing(S_fart3);\n        putMouth(tongueOut);    \n        delay(300);\n\n        home(); \n        delay(500); \n        putMouth(happyOpen);\n    break;\n\n\n    case OttoConfused:\n    gesturePOSITION[0] = 110;//int confusedPos[6]= {110, 70, 90, 90};\n        gesturePOSITION[1] = 70;\n         gesturePOSITION[2] = 90;\n          gesturePOSITION[3] = 90;\n        _moveServos(300, gesturePOSITION); \n        putMouth(confused);\n        sing(S_confused);\n        delay(500);\n\n        home();  \n        putMouth(happyOpen);\n    break;\n\n\n    case OttoLove:\n        putMouth(heart);\n        sing(S_cuddly);\n        crusaito(2,1500,15,1);\n\n        home(); \n        sing(S_happy_short);  \n        putMouth(happyOpen);\n    break;\n\n\n    case OttoAngry: \n    gesturePOSITION[0] = 90;//int angryPos[6]=    {90, 90, 70, 110};\n        gesturePOSITION[1] = 90;\n         gesturePOSITION[2] = 70;\n          gesturePOSITION[3] = 110;\n        _moveServos(300, gesturePOSITION); \n        putMouth(angry);\n\n        _tone(note_A5,100,30);\n        bendTones(note_A5, note_D6, 1.02, 7, 4);\n        bendTones(note_D6, note_G6, 1.02, 10, 1);\n        bendTones(note_G6, note_A5, 1.02, 10, 1);\n        delay(15);\n        bendTones(note_A5, note_E5, 1.02, 20, 4);\n        delay(400);\n        gesturePOSITION[0] = 110;//int headLeft[6]=    {110, 110, 90, 90};\n        gesturePOSITION[1] = 110;\n         gesturePOSITION[2] = 90;\n          gesturePOSITION[3] = 90;\n        _moveServos(200, gesturePOSITION); \n        bendTones(note_A5, note_D6, 1.02, 20, 4);\n        gesturePOSITION[0] = 70;//int headRight[6]=   {70, 70, 90, 90};\n        gesturePOSITION[1] = 70;\n         gesturePOSITION[2] = 90;\n          gesturePOSITION[3] = 90;\n        _moveServos(200, gesturePOSITION); \n        bendTones(note_A5, note_E5, 1.02, 20, 4);\n\n        home();  \n        putMouth(happyOpen);\n    break;\n\n\n    case OttoFretful: \n        putMouth(angry);\n        bendTones(note_A5, note_D6, 1.02, 20, 4);\n        bendTones(note_A5, note_E5, 1.02, 20, 4);\n        delay(300);\n        putMouth(lineMouth);\n\n        for(int i=0; i<4; i++){\n          gesturePOSITION[0] = 90;//int fretfulPos[6]=  {90, 90, 90, 110};\n        gesturePOSITION[1] = 90;\n         gesturePOSITION[2] = 90;\n          gesturePOSITION[3] = 110;\n          _moveServos(100, gesturePOSITION);   \n          home();\n        }\n\n        putMouth(angry);\n        delay(500);\n\n        home();  \n        putMouth(happyOpen);\n    break;\n\n\n    case OttoMagic:\n\n        //Initial note frecuency = 400\n        //Final note frecuency = 1000\n        \n        // Reproduce the animation four times\n        for(int i = 0; i<4; i++){ \n\n          int noteM = 400; \n\n            for(int index = 0; index<6; index++){\n              putAnimationMouth(adivinawi,index);\n              bendTones(noteM, noteM+100, 1.04, 10, 10);    //400 -> 1000 \n              noteM+=100;\n            }\n\n            clearMouth();\n            bendTones(noteM-100, noteM+100, 1.04, 10, 10);  //900 -> 1100\n\n            for(int index = 0; index<6; index++){\n              putAnimationMouth(adivinawi,index);\n              bendTones(noteM, noteM+100, 1.04, 10, 10);    //1000 -> 400 \n              noteM-=100;\n            }\n        } \n \n        delay(300);\n        putMouth(happyOpen);\n    break;\n\n\n    case OttoWave:\n        \n        // Reproduce the animation four times\n        for(int i = 0; i<2; i++){ \n\n            int noteW = 500; \n\n            for(int index = 0; index<10; index++){\n              putAnimationMouth(wave,index);\n              bendTones(noteW, noteW+100, 1.02, 10, 10); \n              noteW+=101;\n            }\n            for(int index = 0; index<10; index++){\n              putAnimationMouth(wave,index);\n              bendTones(noteW, noteW+100, 1.02, 10, 10); \n              noteW+=101;\n            }\n            for(int index = 0; index<10; index++){\n              putAnimationMouth(wave,index);\n              bendTones(noteW, noteW-100, 1.02, 10, 10); \n              noteW-=101;\n            }\n            for(int index = 0; index<10; index++){\n              putAnimationMouth(wave,index);\n              bendTones(noteW, noteW-100, 1.02, 10, 10); \n              noteW-=101;\n            }\n        }    \n\n        clearMouth();\n        delay(100);\n        putMouth(happyOpen);\n    break;\n\n    case OttoVictory:\n        \n        putMouth(smallSurprise);\n        //final pos   = {90,90,150,30}\n        for (int i = 0; i < 60; ++i){\n          int pos[]={90,90,90+i,90-i};  \n          _moveServos(10,pos);\n          _tone(1600+i*20,15,1);\n        }\n\n        putMouth(bigSurprise);\n        //final pos   = {90,90,90,90}\n        for (int i = 0; i < 60; ++i){\n          int pos[]={90,90,150-i,30+i};  \n          _moveServos(10,pos);\n          _tone(2800+i*20,15,1);\n        }\n\n        putMouth(happyOpen);\n        //SUPER HAPPY\n        //-----\n        tiptoeSwing(1,500,20);\n        sing(S_superHappy);\n        putMouth(happyClosed);\n        tiptoeSwing(1,500,20); \n        //-----\n\n        home();\n        clearMouth();\n        putMouth(happyOpen);\n\n    break;\n\n    case OttoFail:\n        putMouth(sadOpen);\n         gesturePOSITION[0] = 90;//int bendPos_1[6]=   {90, 90, 70, 35};\n        gesturePOSITION[1] = 90;\n         gesturePOSITION[2] = 70;\n          gesturePOSITION[3] = 35;\n        _moveServos(300,gesturePOSITION);\n        _tone(900,200,1);\n        putMouth(sadClosed);\n        gesturePOSITION[0] = 90;//int bendPos_2[6]=   {90, 90, 55, 35};\n        gesturePOSITION[1] = 90;\n         gesturePOSITION[2] = 55;\n          gesturePOSITION[3] = 35;\n        _moveServos(300,gesturePOSITION);\n        _tone(600,200,1);\n        putMouth(confused);\n        gesturePOSITION[0] = 90;//int bendPos_3[6]=   {90, 90, 42, 35};\n        gesturePOSITION[1] = 90;\n         gesturePOSITION[2] = 42;\n          gesturePOSITION[3] = 35;\n        _moveServos(300,gesturePOSITION);\n        _tone(300,200,1);\n        gesturePOSITION[0] = 90;//int bendPos_4[6]=   {90, 90, 34, 35};\n        gesturePOSITION[1] = 90;\n         gesturePOSITION[2] = 34;\n          gesturePOSITION[3] = 35;\n        _moveServos(300,gesturePOSITION);\n        putMouth(xMouth);\n\n        detachServos();\n        _tone(150,2200,1);\n        \n        delay(600);\n        clearMouth();\n        putMouth(happyOpen);\n        home();\n\n    break;\n\n  }\n} \n\nvoid Otto::enableServoLimit(int diff_limit) {\n  for (int i = 0; i < 4; i++) {\n    servo[i].SetLimiter(diff_limit);\n  }\n}\n\nvoid Otto::disableServoLimit() {\n  for (int i = 0; i < 4; i++) {\n    servo[i].DisableLimiter();\n  }\n}\n"
  },
  {
    "path": "src/Otto.h",
    "content": "#ifndef Otto_h\n#define Otto_h\n\n#ifdef ARDUINO_ARCH_ESP32\n#include <ESP32Servo.h>\n#else\n#include <Servo.h>\n#endif\n#include <Oscillator.h>\n#include <EEPROM.h>\n#include \"Otto_sounds.h\"\n#include \"Otto_gestures.h\"\n#include \"Otto_mouths.h\"\n#include \"Otto_matrix.h\"\n\n//-- Constants\n#define FORWARD     1\n#define BACKWARD    -1\n#define LEFT        1\n#define RIGHT       -1\n#define SMALL       5\n#define MEDIUM      15\n#define BIG         30\n\n// -- Servo delta limit default. degree / sec\n#define SERVO_LIMIT_DEFAULT 240\n\nclass Otto\n{\n  public:\n\n    //-- Otto initialization\n    void init(int YL, int YR, int RL, int RR, bool load_calibration, int Buzzer);\n    //-- Attach & detach functions\n    void attachServos();\n    void detachServos();\n\n    //-- Oscillator Trims\n    void setTrims(int YL, int YR, int RL, int RR);\n    void saveTrimsOnEEPROM();\n\n    //-- Predetermined Motion Functions\n    void _moveServos(int time, int  servo_target[]);\n    void _moveSingle(int position,int  servo_number);\n    void oscillateServos(int A[4], int O[4], int T, double phase_diff[4], float cycle);\n\n    //-- HOME = Otto at rest position\n    void home();\n    bool getRestState();\n    void setRestState(bool state);\n\n    //-- Predetermined Motion Functions\n    void jump(float steps=1, int T = 2000);\n\n    void walk(float steps=4, int T=1000, int dir = FORWARD);\n    void turn(float steps=4, int T=2000, int dir = LEFT);\n    void bend (int steps=1, int T=1400, int dir=LEFT);\n    void shakeLeg (int steps=1, int T = 2000, int dir=RIGHT);\n\n    void updown(float steps=1, int T=1000, int h = 20);\n    void swing(float steps=1, int T=1000, int h=20);\n    void tiptoeSwing(float steps=1, int T=900, int h=20);\n    void jitter(float steps=1, int T=500, int h=20);\n    void ascendingTurn(float steps=1, int T=900, int h=20);\n\n    void moonwalker(float steps=1, int T=900, int h=20, int dir=LEFT);\n    void crusaito(float steps=1, int T=900, int h=20, int dir=FORWARD);\n    void flapping(float steps=1, int T=1000, int h=20, int dir=FORWARD);\n\n    //-- Mouth & Animations\n    void putMouth(unsigned long int mouth, bool predefined = true);\n    void putAnimationMouth(unsigned long int anim, int index);\n    void clearMouth();\n\n    //-- Sounds\n    void _tone (float noteFrequency, long noteDuration, int silentDuration);\n    void bendTones (float initFrequency, float finalFrequency, float prop, long noteDuration, int silentDuration);\n    void sing(int songName);\n\n    //-- Gestures\n    void playGesture(int gesture);\n    void initMATRIX(int DIN, int CS, int CLK, int rotate);\n    void matrixIntensity(int intensity);\n    void setLed(byte X, byte Y, byte value);\n    void writeText (const char * s, byte scrollspeed);\n\n    // -- Servo limiter\n    void enableServoLimit(int speed_limit_degree_per_sec = SERVO_LIMIT_DEFAULT);\n    void disableServoLimit();\n\n  private:\n\n    Oscillator servo[4];\n    Otto_Matrix ledmatrix;\n    int servo_pins[4];\n    int servo_trim[4];\n\n    int pinBuzzer;\n\n    unsigned long final_time;\n    unsigned long partial_time;\n    float increment[4];\n\n    bool isOttoResting;\n\n    unsigned long int getMouthShape(int number);\n    unsigned long int getAnimShape(int anim, int index);\n    void _execute(int A[4], int O[4], int T, double phase_diff[4], float steps);\n\n};\n\n#endif\n"
  },
  {
    "path": "src/Otto_gestures.h",
    "content": "#ifndef Otto_gestures_h\n#define Otto_gestures_h\n\n//***********************************************************************************\n//*********************************GESTURE DEFINES***********************************\n//***********************************************************************************           \n\n#define OttoHappy \t\t0\n#define OttoSuperHappy \t1\n#define OttoSad \t\t2\n#define OttoSleeping \t3\n#define OttoFart \t\t4\n#define OttoConfused \t5\n#define OttoLove \t\t6\n#define OttoAngry \t\t7\n#define OttoFretful \t8\n#define OttoMagic \t\t9\n#define OttoWave \t\t10\n#define OttoVictory \t11\n#define OttoFail \t\t12\n\n//*** MOUTH ANIMATIONS***\n#define littleUuh\t\t0\n#define dreamMouth\t\t1 \t\n#define adivinawi\t\t2\n#define wave \t\t\t3\n\n\n //*** MOUTH ANIMATIONS***\n#define littleUuh   0\n#define dreamMouth    1   \n#define adivinawi   2\n#define wave      3\n#define otto      4 // Wordt niet gebruikt.\n\ntypedef struct \n{\n  uint8_t Character[1];\n  uint8_t data[6];\n}\nLED_Matrix_Font_6x8_TypeDef;\n\n//Terminal\nconst LED_Matrix_Font_6x8_TypeDef Character_font_6x8[] PROGMEM =\n{\n\n    '0',  0x00,0x7C,0x82,0x82,0x7C,0x00,\n    '1',  0x00,0x42,0xFE,0x02,0x00,0x00,\n    '2',  0x00,0x46,0x8A,0x92,0x62,0x00,\n    '3',  0x00,0x44,0x92,0x92,0x6C,0x00,\n    '4',  0x00,0x1C,0x64,0xFE,0x04,0x00,\n    '5',  0x00,0xF2,0x92,0x92,0x8C,0x00,\n    '6',  0x00,0x7C,0x92,0x92,0x4C,0x00,\n    '7',  0x00,0xC0,0x8E,0x90,0xE0,0x00,\n    '8',  0x00,0x6C,0x92,0x92,0x6C,0x00,\n    '9',  0x00,0x64,0x92,0x92,0x7C,0x00,\n    ':',  0x00,0x00,0x14,0x00,0x00,0x00,\n    ';',  0x00,0x02,0x24,0x00,0x00,0x00,\n    '<',  0x00,0x10,0x28,0x44,0x82,0x00, \n    '=',  0x00,0x28,0x28,0x28,0x28,0x00,\n    '>',  0x00,0x82,0x44,0x28,0x10,0x00,\n    '?',  0x00,0x20,0x4a,0x30,0x00,0x00, //\n    '@',  0x00,0x00,0x00,0x00,0x00,0x00,\n    'A',  0x00,0x7E,0x88,0x88,0x7E,0x00,\n    'B',  0x00,0xFE,0x92,0x92,0x6C,0x00,\n    'C',  0x00,0x7C,0x82,0x82,0x44,0x00,\n    'D',  0x00,0xFE,0x82,0x82,0x7C,0x00,\n    'E',  0x00,0xFE,0x92,0x92,0x82,0x00,\n    'F',  0x00,0xFE,0x90,0x90,0x80,0x00,\n    'G',  0x00,0x7C,0x82,0x92,0x5C,0x00,\n    'H',  0x00,0xFE,0x10,0x10,0xFE,0x00,\n    'I',  0x00,0x82,0xFE,0x82,0x00,0x00,\n    'J',  0x00,0x0C,0x02,0x02,0xFC,0x00,\n    'K',  0x00,0xFE,0x10,0x28,0xC6,0x00,\n    'L',  0x00,0xFE,0x02,0x02,0x02,0x00,\n    'M',  0x00,0xFE,0x40,0x30,0x40,0xFE,\n    'N',  0x00,0xFE,0x40,0x30,0x08,0xFE,\n    'O',  0x00,0x7C,0x82,0x82,0x82,0x7C,\n    'P',  0x00,0xFE,0x90,0x90,0x60,0x00,\n    'Q',  0x00,0x7C,0x82,0x8A,0x84,0x7A,\n    'R',  0x00,0xFE,0x98,0x94,0x62,0x00,\n    'S',  0x00,0x64,0x92,0x92,0x4C,0x00,\n    'T',  0x00,0x80,0xFE,0x80,0x80,0x00,\n    'U',  0x00,0xFC,0x02,0x02,0xFC,0x00,\n    'V',  0x00,0xF0,0x0C,0x02,0x0C,0xF0,\n    'W',  0x00,0xFE,0x04,0x38,0x04,0xFE,\n    'X',  0x00,0xC6,0x38,0x38,0xC6,0x00,\n    'Y',  0xC0,0x20,0x1E,0x20,0xC0,0x00,\n    'Z',  0x00,0x86,0x9A,0xB2,0xC2,0x00,\n    '!',  0x00,0x00,0x7a,0x00,0x00,0x00,\n    ' ',  0x00,0x00,0x00,0x00,0x00,0x00,\n    \n};\n \n\nconst unsigned long int Gesturetable[4][10] PROGMEM = {\n  {\n    0b00000000000000001100001100000000, // littleUuh_code1\n    0b00000000000000000110000110000000, // littleUuh_code2\n    0b00000000000000000011000011000000, // littleUuh_code3\n    0b00000000000000000110000110000000, // littleUuh_code4\n    0b00000000000000001100001100000000, // littleUuh_code5\n    0b00000000000000011000011000000000, // littleUuh_code6\n    0b00000000000000110000110000000000, // littleUuh_code7\n    0b00000000000000011000011000000000\n  } // littleUuh_code8\n  ,\n  {\n    0b00000000000000000000110000110000, // dreamMouth_code1\n    0b00000000000000010000101000010000, // dreamMouth_code2\n    0b00000000011000100100100100011000, // dreamMouth_code3\n    0b00000000000000010000101000010000  // dreamMouth_code4\n  } \n  ,\n  {\n    0b00100001000000000000000000100001, // adivinawi_code1\n    0b00010010100001000000100001010010, // adivinawi_code2\n    0b00001100010010100001010010001100, // adivinawi_code3\n    0b00000000001100010010001100000000, // adivinawi_code4\n    0b00000000000000001100000000000000, // adivinawi_code5\n    0b00000000000000000000000000000000  // adivinawi_code6\n  } \n  ,\n  {\n    0b00001100010010100001000000000000, // wave_code1\n    0b00000110001001010000100000000000, // wave_code2\n    0b00000011000100001000010000100000, // wave_code3\n    0b00000001000010000100001000110000, // wave_code4\n    0b00000000000001000010100100011000, // wave_code5\n    0b00000000000000100001010010001100, // wave_code6\n    0b00000000100000010000001001000110, // wave_code7\n    0b00100000010000001000000100000011, // wave_code8\n    0b00110000001000000100000010000001, // wave_code9\n    0b00011000100100000010000001000000  // wave_code10\n  } \n};\n\n//\"PROGMEM_readAnything.h\"   FROM http://www.gammon.com.au/progmem\n// modified for OTTO use by Paul Van De Veen along with all PROGMEM mouths and gestures\n#include <Arduino.h>  // for type definitions\n\ntemplate <typename T> void PROGMEM_readAnything (const T * sce, T& dest)\n  {\n  memcpy_P (&dest, sce, sizeof (T));\n  }\n\ntemplate <typename T> T PROGMEM_getAnything (const T * sce)\n  {\n  static T temp;\n  memcpy_P (&temp, sce, sizeof (T));\n  return temp;\n  }\n\n#endif\n"
  },
  {
    "path": "src/Otto_matrix.cpp",
    "content": "/*\n * MaxMatrix\n * Version 1.0 Feb 2013\n * Copyright 2013 Oscar Kin-Chung Au\n * Adapted for OTTO version 9 use\n */\n\n\n#include \"Arduino.h\"\n#include \"Otto_matrix.h\"\n\nOtto_Matrix::Otto_Matrix() \n{\n\t//data = _data;\n\t//load = _load;\n\t//clock = _clock;\n\t//num = _num;\n}\n\nvoid Otto_Matrix::init(byte _data, byte _load, byte _clock, byte _num, int _rotation)\n{\n  data = _data;\n  load = _load;\n  clock = _clock;\n  num = _num;\n  rotation = _rotation;\n  if ((rotation > 4) || (rotation == 0)) rotation = 1; // we have to have number between 1 and 4\n  for (int i=0; i<8; i++)\n    buffer[i] = 0;\n\n    for (int i=0; i<80; i++)\n    CHARbuffer[i] = 0;\n    \n#if defined(ESP32)\n    SPI.begin ( clock,  -1,  data, load);\n    SPI.setDataMode(SPI_MODE0);\n    SPI.setClockDivider(SPI_CLOCK_DIV128);\n    SPI.setHwCs(true);\n#else\n    pinMode(data,  OUTPUT);\n    pinMode(clock, OUTPUT);\n    pinMode(load, OUTPUT);\n    digitalWrite(clock, HIGH); \n#endif\n\n        setCommand(max7219_reg_scanLimit, 0x07);      \n\tsetCommand(max7219_reg_decodeMode, 0x00);  // using an led matrix (not digits)\n\tsetCommand(max7219_reg_shutdown, 0x01);    // not in shutdown mode\n\tsetCommand(max7219_reg_displayTest, 0x00); // no display test\n\t\n\t// empty registers, turn all LEDs off\n\tclearMatrix();\n\t\n\tsetIntensity(0x0f);    // the first 0x0f is the value you can set\n}\n\nvoid Otto_Matrix::setIntensity(byte intensity)\n{\n\tsetCommand(max7219_reg_intensity, intensity);\n}\n\nvoid Otto_Matrix::clearMatrix()\n{\n\tfor (int i=0; i<8; i++) \n\t\tsetColumnAll(i,0);\n\t\t\n\tfor (int i=0; i<8; i++)\n\t\tbuffer[i] = 0;\n\n    for (int i=0; i<80; i++)\n    CHARbuffer[i] = 0;\n}\n\nvoid Otto_Matrix::setCommand(byte command, byte value)\n{\n#if defined(ESP32)\n    SPI.transfer16(command << 8 | value);\n#else\n\tdigitalWrite(load, LOW);    \n\tfor (int i=0; i<num; i++) \n\t{\n\t\tshiftOut(data, clock, MSBFIRST, command);\n\t\tshiftOut(data, clock, MSBFIRST, value);\n\t}\n\tdigitalWrite(load, LOW);\n\tdigitalWrite(load, HIGH);\n#endif\n}\n\n\nvoid Otto_Matrix::setColumn(byte col, byte value)\n{\n\tint n = col / 8;\n\tint c = col % 8;\n#if defined(ESP32)\n    for (int i=0; i<num; i++)\n    {\n\tif (i == n)\n        {\n\t    SPI.transfer16((c + 1) << 8 | value);\n\t}\n\t//else\n\t//{\n\t//    SPI.transfer16(0);\n\t//}\n    }\n#else\n\tdigitalWrite(load, LOW);    \n        for (int i=0; i<num; i++) \n\t{\n\t\tif (i == n)\n\t\t{\n\t\t\tshiftOut(data, clock, MSBFIRST, c + 1);\n\t\t\tshiftOut(data, clock, MSBFIRST, value);\n\t\t}\n\t\t//else\n\t\t//{\n\t\t\t//shiftOut(data, clock, MSBFIRST, 0);\n\t\t\t//shiftOut(data, clock, MSBFIRST, 0);\n\t\t//}\n\t}\n\tdigitalWrite(load, LOW);\n\tdigitalWrite(load, HIGH);\n#endif\n\t\n\tbuffer[col] = value;\n}\n\nvoid Otto_Matrix::setColumnAll(byte col, byte value)\n{\n#if defined(ESP32)\n    for (int i=0; i<num; i++) \n    {\n\tSPI.transfer16((col + 1) << 8 | value);\n\tbuffer[col * i] = value;\n    }\n#else\n\tdigitalWrite(load, LOW);    \n\tfor (int i=0; i<num; i++) \n\t{\n\t\tshiftOut(data, clock, MSBFIRST, col + 1);\n\t\tshiftOut(data, clock, MSBFIRST, value);\n\t\tbuffer[col * i] = value;\n\t}\n\tdigitalWrite(load, LOW);\n\tdigitalWrite(load, HIGH);\n#endif\n}\n\nvoid Otto_Matrix::setDot(byte col, byte row, byte value)\n{\n    bitWrite(buffer[col], row, value);\n\n\tint n = col / 8;\n\tint c = col % 8;\n#if defined(ESP32)\n    for (int i=0; i<num; i++) \n    {\n\tif (i == n)\n\t{\n\t    SPI.transfer16((c + 1) << 8 | buffer[col]);\n\t}\n\telse\n\t{\n\t    SPI.transfer16(0);\n\t}\n    }\n#else\n\tdigitalWrite(load, LOW);    \n        for (int i=0; i<num; i++) \n\t{\n\t\tif (i == n)\n\t\t{\n\t\t\tshiftOut(data, clock, MSBFIRST, c + 1);\n\t\t\tshiftOut(data, clock, MSBFIRST, buffer[col]);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tshiftOut(data, clock, MSBFIRST, 0);\n\t\t\tshiftOut(data, clock, MSBFIRST, 0);\n\t\t}\n\t}\n\tdigitalWrite(load, LOW);\n\tdigitalWrite(load, HIGH);\n#endif\n}\n\n// routine for OTTO and ZOWI, for the 6 x 5 matrix\nvoid Otto_Matrix::writeFull(unsigned long value) {\n  if (rotation == 1) {\n\tfor (int r=0; r<5;r++){\n            for (int c=0; c<6; c++){\n                setDot(6-c,7-r,(1L & (value >> r*6+c)));\n                }\n            }\n  }\nif (rotation == 2) {\n  for (int r=0; r<5;r++){\n            for (int c=0; c<6; c++){\n                //setDot(6-c,7-r,(1L & (value >> r*6+c)));\n                setDot(1+c,r,    (1L & (value >> r*6+c)));\n                }\n            }\n  }\n  if (rotation == 3) {\n  for (int r=0; r<5;r++){\n            for (int c=0; c<6; c++){\n                //setDot(6-c,7-r,(1L & (value >> r*6+c)));\n                setDot(r,6-c,    (1L & (value >> r*6+c)));\n                }\n            }\n  }\n  if (rotation == 4) {\n  for (int r=0; r<5;r++){\n            for (int c=0; c<6; c++){\n                //setDot(6-c,7-r,(1L & (value >> r*6+c)));\n                setDot(7-r,1+c, (1L & (value >> r*6+c)));  \n                }\n            }\n  }\n}\n\nvoid Otto_Matrix::sendChar (const byte data, byte pos, byte number, byte scrollspeed){\n  if (scrollspeed < 50 ) scrollspeed = 50;\n   if (scrollspeed > 150 ) scrollspeed = 150;\n  int charPos;\ncharPos = pos * 8;\n//Serial.print (\"sendchar  \");\n//Serial.print (pos);\n//Serial.print (\" -  \");\n//Serial.print (number);\n//Serial.print (\" -  \");\n//Serial.print (charPos);\n//Serial.print (\" -  \");\n//Serial.println (data);\n//we need to add 8 for each character\n  CHARbuffer[0 + charPos] = 0;\n  CHARbuffer[1 + charPos] = pgm_read_byte(&Character_font_6x8[data].data[0]);\n  CHARbuffer[2 + charPos] = pgm_read_byte(&Character_font_6x8[data].data[1]);\n  CHARbuffer[3 + charPos] = pgm_read_byte(&Character_font_6x8[data].data[2]);\n  CHARbuffer[4 + charPos] = pgm_read_byte(&Character_font_6x8[data].data[3]);\n  CHARbuffer[5 + charPos] = pgm_read_byte(&Character_font_6x8[data].data[4]);\n  CHARbuffer[6 + charPos] = pgm_read_byte(&Character_font_6x8[data].data[5]);\n  CHARbuffer[7 + charPos] = 0;\n\n if (number == (pos + 1)){ // last character so display the total text\n// we need to display first character and scroll left until each charater is shown.\n    for (int c=0; c<8;c++){ // show first character\n         byte value = CHARbuffer[c];\n            for (int r=0; r<8; r++){\n              if (rotation == 1) {\n                setDot(c,7-r,(0b00000001 & (value >> r)));//       \n                }\n                if (rotation == 2) {\n                 setDot(7-c,r,(0b00000001 & (value >> r)));//  \n                }\n                if (rotation == 3) {\n                 //setDot(r,c,(1));// top LH corner\n                 setDot(r,c,(0b00000001 & (value >> r)));//  \n                }\n                if (rotation == 4) {\n                 setDot(7-r,7-c,(0b00000001 & (value >> r)));//  \n                }\n           }\n      }\n      delay(500); // show first digit for longer\n      for (int i=0; i<((number*8)-1); i++){   // shift buffer the correct number of characters (8 lines per character)\n        CHARbuffer[i] = CHARbuffer[i+1];\n         for (int c=0; c<8;c++){ // \n             byte value = CHARbuffer[(1+c)+i];\n                for (int r=0; r<8; r++){\n                  if (rotation == 1) {\n                  setDot(c,7-r,(0b00000001 & (value >> r)));//       \n                   }\n                  if (rotation == 2) {\n                  setDot(7-c,r,(0b00000001 & (value >> r)));//  \n                  }\n                  if (rotation == 3) {\n                   setDot(r,c,(0b00000001 & (value >> r)));//  \n                 }\n                  if (rotation == 4) {\n                 setDot(7-r,7-c,(0b00000001 & (value >> r)));//  \n                }\n              }\n        }\n     delay(scrollspeed);// this sets the scroll speed\n  \n      }\n      clearMatrix();\n }   \n}\n\n\n"
  },
  {
    "path": "src/Otto_matrix.h",
    "content": "/*\n * MaxMatrix\n * Version 1.0 Feb 2013\n * Copyright 2013 Oscar Kin-Chung Au\n * Adapted for OTTO version 9 use\n */\n\n#ifndef _Otto_matrix_H_\n#define _Otto_matrix_H_\n\n#include \"Arduino.h\"\n#include \"Otto_gestures.h\"\n\n#if defined(ESP32)\n# include <SPI.h>\n#endif\n\n#define max7219_reg_noop        0x00\n#define max7219_reg_digit0      0x01\n#define max7219_reg_digit1      0x02\n#define max7219_reg_digit2      0x03\n#define max7219_reg_digit3      0x04\n#define max7219_reg_digit4      0x05\n#define max7219_reg_digit5      0x06\n#define max7219_reg_digit6      0x07\n#define max7219_reg_digit7      0x08\n#define max7219_reg_decodeMode  0x09\n#define max7219_reg_intensity   0x0a\n#define max7219_reg_scanLimit   0x0b\n#define max7219_reg_shutdown    0x0c\n#define max7219_reg_displayTest 0x0f\n\nclass Otto_Matrix\n{\n  private:\n    byte data;\n    byte load;\n    byte clock;\n    byte num;\n    byte buffer[8];\n    byte CHARbuffer[80];\n    int  rotation;\n    void reload();\n    char rotation2;\n    \n  public:\n    Otto_Matrix();\n    \n    void init(byte data, byte load, byte clock, byte num, int rotation);\n    void clearMatrix();\n    void setCommand(byte command, byte value);\n    void setIntensity(byte intensity);\n    void setColumn(byte col, byte value);\n    void setColumnAll(byte col, byte value);\n    void setDot(byte col, byte row, byte value);\n    void writeFull(unsigned long value);\n    void sendChar ( const byte data, byte pos, byte number, byte scrollspeed);\n};\n\n#endif\n"
  },
  {
    "path": "src/Otto_mouths.h",
    "content": "#ifndef Otto_mouths_h\n#define Otto_mouths_h\n\n\n//***********************************************************************************\n//*********************************MOUTHS DEFINES************************************\n//***********************************************************************************\nconst int NUMBER_OF_ELEMENTS = 31;\nconst unsigned long int Mouthtable[NUMBER_OF_ELEMENTS] PROGMEM = {\n  0b00001100010010010010010010001100, //zero_code\n  0b00000100001100000100000100001110, //one_code\n  0b00001100010010000100001000011110, //two_code\n  0b00001100010010000100010010001100, //three_code\n  0b00010010010010011110000010000010, //four_code\n  0b00011110010000011100000010011100, //five_code\n  0b00000100001000011100010010001100, //six_code\n  0b00011110000010000100001000010000, //seven_code\n  0b00001100010010001100010010001100, //eight_code\n  0b00001100010010001110000010001110, //nine_code\n  0b00000000100001010010001100000000, //smile_code\n  0b00000000111111010010001100000000, //happyOpen_code\n  0b00000000111111011110000000000000, //happyClosed_code\n  0b00010010101101100001010010001100, //heart_code\n  0b00001100010010100001010010001100, //bigSurprise_code\n  0b00000000000000001100001100000000, //smallSurprise_code\n  0b00111111001001001001000110000000, //tongueOut_code\n  0b00111111101101101101010010000000, //vamp1_code\n  0b00111111101101010010000000000000, //vamp2_code\n  0b00000000000000111111000000000000, //lineMouth_code\n  0b00000000001000010101100010000000, //confused_code\n  0b00100000010000001000000100000010, //diagonal_code\n  0b00000000001100010010100001000000, //sad_code\n  0b00000000001100010010111111000000, //sadOpen_code\n  0b00000000001100011110110011000000, //sadClosed_code\n  0b00000001000010010100001000000000, //okMouth_code\n  0b00100001010010001100010010100001, //xMouth_code\n  0b00001100010010000100000100000100, //interrogation_code\n  0b00000100001000011100001000010000, //thunder_code\n  0b00000000100001101101010010000000, //culito_code\n  0b00000000011110100001100001000000  //angry_code\n} ;\n\n//Mouths sorted by numbers, and after, by happy to sad mouths\n#define zero \t\t\t\t0\n#define one  \t\t\t\t1                \n#define two     \t\t\t      2               \n#define three                    3  \n#define four                     4\n#define five                     5 \n#define six                      6 \n#define seven                    7  \n#define eight                    8 \n#define nine   \t\t\t\t9\n#define smile                    10                  \n#define happyOpen      \t\t11  \n#define happyClosed \t           12  \n#define heart      \t\t\t13\n#define bigSurprise              14  \n#define smallSurprise \t\t15\n#define tongueOut \t\t\t16\n#define vamp1                    17  \n#define vamp2                    18  \n#define lineMouth        \t      19\n#define confused                 20  \n#define diagonal       \t\t21          \n#define sad         \t\t     \t22\n#define sadOpen \t                \t23 \n#define sadClosed \t\t  \t24\n#define okMouth                 25 \n#define xMouth                  26\n#define interrogation           27\n#define thunder\t\t      \t28\n#define culito       \t\t    \t29\n#define angry \t\t\t\t30  \n               \n#endif"
  },
  {
    "path": "src/Otto_sounds.h",
    "content": "#ifndef Otto_sounds_h\n#define Otto_sounds_h\n\n// Reference:  This list was adapted from the table located here:\n//    http://www.phy.mtu.edu/~suits/notefreqs.html\n#define  note_C0  16.35  //C0\n#define  note_Db0 17.32  //C#0/Db0\n#define  note_D0  18.35  //D0\n#define  note_Eb0 19.45 //D#0/Eb0\n#define  note_E0  20.6  //E0\n#define  note_F0  21.83  //F0\n#define  note_Gb0 23.12  //F#0/Gb0\n#define  note_G0  24.5  //G0\n#define  note_Ab0 25.96  //G#0/Ab0\n#define  note_A0  27.5  //A0\n#define  note_Bb0 29.14  //A#0/Bb0\n#define  note_B0  30.87  //B0\n#define  note_C1  32.7  //C1\n#define  note_Db1 34.65  //C#1/Db1\n#define  note_D1  36.71  //D1\n#define  note_Eb1 38.89  //D#1/Eb1\n#define  note_E1  41.2  //E1\n#define  note_F1  43.65  //F1\n#define  note_Gb1 46.25  //F#1/Gb1\n#define  note_G1  49 //G1\n#define  note_Ab1 51.91  //G#1/Ab1\n#define  note_A1  55  //A1\n#define  note_Bb1 58.27  //A#1/Bb1\n#define  note_B1  61.74  //B1\n#define  note_C2  65.41  //C2 (Middle C)\n#define  note_Db2 69.3  //C#2/Db2\n#define  note_D2  73.42  //D2\n#define  note_Eb2 77.78  //D#2/Eb2\n#define  note_E2  82.41  //E2\n#define  note_F2  87.31  //F2\n#define  note_Gb2 92.5  //F#2/Gb2\n#define  note_G2  98  //G2\n#define  note_Ab2 103.83  //G#2/Ab2\n#define  note_A2  110  //A2\n#define  note_Bb2 116.54  //A#2/Bb2\n#define  note_B2  123.47  //B2\n#define  note_C3  130.81  //C3\n#define  note_Db3 138.59  //C#3/Db3\n#define  note_D3  146.83  //D3\n#define  note_Eb3 155.56  //D#3/Eb3\n#define  note_E3  164.81  //E3\n#define  note_F3  174.61  //F3\n#define  note_Gb3 185  //F#3/Gb3\n#define  note_G3  196  //G3\n#define  note_Ab3 207.65  //G#3/Ab3\n#define  note_A3  220  //A3\n#define  note_Bb3 233.08  //A#3/Bb3\n#define  note_B3  246.94  //B3\n#define  note_C4  261.63  //C4\n#define  note_Db4 277.18  //C#4/Db4\n#define  note_D4  293.66  //D4\n#define  note_Eb4 311.13  //D#4/Eb4\n#define  note_E4  329.63  //E4\n#define  note_F4  349.23  //F4\n#define  note_Gb4 369.99  //F#4/Gb4\n#define  note_G4  392  //G4\n#define  note_Ab4 415.3  //G#4/Ab4\n#define  note_A4  440  //A4\n#define  note_Bb4 466.16  //A#4/Bb4\n#define  note_B4  493.88  //B4\n#define  note_C5  523.25  //C5\n#define  note_Db5 554.37  //C#5/Db5\n#define  note_D5  587.33  //D5\n#define  note_Eb5 622.25  //D#5/Eb5\n#define  note_E5  659.26  //E5\n#define  note_F5  698.46  //F5\n#define  note_Gb5 739.99  //F#5/Gb5\n#define  note_G5  783.99  //G5\n#define  note_Ab5 830.61  //G#5/Ab5\n#define  note_A5  880  //A5\n#define  note_Bb5 932.33  //A#5/Bb5\n#define  note_B5  987.77  //B5\n#define  note_C6  1046.5  //C6\n#define  note_Db6 1108.73  //C#6/Db6\n#define  note_D6  1174.66  //D6\n#define  note_Eb6 1244.51  //D#6/Eb6\n#define  note_E6  1318.51  //E6\n#define  note_F6  1396.91  //F6\n#define  note_Gb6 1479.98  //F#6/Gb6\n#define  note_G6  1567.98  //G6\n#define  note_Ab6 1661.22  //G#6/Ab6\n#define  note_A6  1760  //A6\n#define  note_Bb6 1864.66  //A#6/Bb6\n#define  note_B6  1975.53  //B6\n#define  note_C7  2093  //C7\n#define  note_Db7 2217.46  //C#7/Db7\n#define  note_D7  2349.32  //D7\n#define  note_Eb7 2489.02  //D#7/Eb7\n#define  note_E7  2637.02  //E7\n#define  note_F7  2793.83  //F7\n#define  note_Gb7 2959.96  //F#7/Gb7\n#define  note_G7  3135.96  //G7\n#define  note_Ab7 3322.44  //G#7/Ab7\n#define  note_A7  3520  //A7\n#define  note_Bb7 3729.31  //A#7/Bb7\n#define  note_B7  3951.07  //B7\n#define  note_C8  4186.01  //C8\n#define  note_Db8 4434.92  //C#8/Db8\n#define  note_D8  4698.64  //D8\n#define  note_Eb8 4978.03  //D#8/Eb8\n\n#define S_connection \t0\n#define S_disconnection 1\n#define S_buttonPushed \t2\n#define S_mode1 \t\t3\n#define S_mode2 \t\t4\n#define S_mode3 \t\t5\n#define S_surprise \t\t6\n#define S_OhOoh \t\t7\n#define S_OhOoh2 \t\t8\n#define S_cuddly \t\t9\n#define S_sleeping \t\t10\n#define S_happy \t\t11\n#define S_superHappy \t12\n#define S_happy_short \t13\n#define S_sad \t\t\t14\n#define S_confused \t\t15\n#define S_fart1\t\t\t16\n#define S_fart2\t\t\t17\n#define S_fart3\t\t\t18\n\n#endif\n"
  },
  {
    "path": "src/SerialCommand.cpp",
    "content": "/******************************************************************************* \nSerialCommand - An Arduino library to tokenize and parse commands received over\na serial port. \nCopyright (C) 2011-2013 Steven Cogswell  <steven.cogswell@gmail.com>\nhttp://awtfy.com\n\nSee SerialCommand.h for version history. \n\nThis library is free software; you can redistribute it and/or\nmodify it under the terms of the GNU Lesser General Public\nLicense as published by the Free Software Foundation; either\nversion 2.1 of the License, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n***********************************************************************************/\n\n#if defined(ARDUINO) && ARDUINO >= 100\n#include \"Arduino.h\"\n#else\n#include \"WProgram.h\"\n#endif\n\n#include \"SerialCommand.h\"\n\n\n#include <string.h>\n#ifndef SERIALCOMMAND_HARDWAREONLY\n#include <SoftwareSerial.h>\n#endif\n\n// Constructor makes sure some things are set. \nSerialCommand::SerialCommand()\n{\n\tusingSoftwareSerial=0;\n\tstrncpy(delim,\" \",MAXDELIMETER);  // strtok_r needs a null-terminated string\n\tterm='\\r';   // return character, default terminator for commands\n\tnumCommand=0;    // Number of callback handlers installed\n\tclearBuffer(); \n}\n\n#ifndef SERIALCOMMAND_HARDWAREONLY\n// Constructor to use a SoftwareSerial object\nSerialCommand::SerialCommand(Stream &_ser)\n{\n\tusingSoftwareSerial=1; \n\t_serialPort = &_ser;\n\tstrncpy(delim,\" \",MAXDELIMETER);  // strtok_r needs a null-terminated string\n\tterm='\\r';   // return character, default terminator for commands\n\tnumCommand=0;    // Number of callback handlers installed\n\tclearBuffer(); \n}\n#endif\n\n\n//\n// Initialize the command buffer being processed to all null characters\n//\nvoid SerialCommand::clearBuffer()\n{\n\tfor (int i=0; i<SERIALCOMMANDBUFFER; i++) \n\t{\n\t\tbuffer[i]='\\0';\n\t}\n\tbufPos=0; \n}\n\n// Retrieve the next token (\"word\" or \"argument\") from the Command buffer.  \n// returns a NULL if no more tokens exist.   \nchar *SerialCommand::next() \n{\n\tchar *nextToken;\n\tnextToken = strtok_r(NULL, delim, &last); \n\treturn nextToken; \n}\n\n// This checks the Serial stream for characters, and assembles them into a buffer.  \n// When the terminator character (default '\\r') is seen, it starts parsing the \n// buffer for a prefix command, and calls handlers setup by addCommand() member\nvoid SerialCommand::readSerial() \n{\n\t// If we're using the Hardware port, check it.   Otherwise check the user-created SoftwareSerial Port\n\t#ifdef SERIALCOMMAND_HARDWAREONLY\n\twhile (Serial.available() > 0) \n\t#else\n\twhile ((usingSoftwareSerial==0 && Serial.available() > 0) || (usingSoftwareSerial==1 && _serialPort->available() > 0) )\n\t#endif\n\t{\n\t\tint i; \n\t\tboolean matched; \n\t\tif (usingSoftwareSerial==0) {\n\t\t\t// Hardware serial port\n\t\t\tinChar=Serial.read();   // Read single available character, there may be more waiting\n\t\t} else {\n\t\t\t#ifndef SERIALCOMMAND_HARDWAREONLY\n\t\t\t// SoftwareSerial port\n\t\t\tinChar = _serialPort->read();   // Read single available character, there may be more waiting\n\t\t\t#endif\n\t\t}\n\t\t#ifdef SERIALCOMMANDDEBUG\n\t\tSerial.print(inChar);   // Echo back to serial stream\n\t\t#endif\n\t\tif (inChar==term) {     // Check for the terminator (default '\\r') meaning end of command\n\t\t\t#ifdef SERIALCOMMANDDEBUG\n\t\t\tSerial.print(\"Received: \"); \n\t\t\tSerial.println(buffer);\n\t\t    #endif\n\t\t\tbufPos=0;           // Reset to start of buffer\n\t\t\ttoken = strtok_r(buffer,delim,&last);   // Search for command at start of buffer\n\t\t\tif (token == NULL) return; \n\t\t\tmatched=false; \n\t\t\tfor (i=0; i<numCommand; i++) {\n\t\t\t\t#ifdef SERIALCOMMANDDEBUG\n\t\t\t\tSerial.print(\"Comparing [\"); \n\t\t\t\tSerial.print(token); \n\t\t\t\tSerial.print(\"] to [\");\n\t\t\t\tSerial.print(CommandList[i].command);\n\t\t\t\tSerial.println(\"]\");\n\t\t\t\t#endif\n\t\t\t\t// Compare the found command against the list of known commands for a match\n\t\t\t\tif (strncmp(token,CommandList[i].command,MAXDELIMETER) == 0) \n\t\t\t\t{\n\t\t\t\t\t#ifdef SERIALCOMMANDDEBUG\n\t\t\t\t\tSerial.print(\"Matched Command: \"); \n\t\t\t\t\tSerial.println(token);\n\t\t\t\t\t#endif\n\t\t\t\t\t// Execute the stored handler function for the command\n\t\t\t\t\t(*CommandList[i].function)(); \n\t\t\t\t\tclearBuffer(); \n\t\t\t\t\tmatched=true; \n\t\t\t\t\tbreak; \n\t\t\t\t}\n\t\t\t}\n\t\t\tif (matched==false) {\n\t\t\t\t(*defaultHandler)(); \n\t\t\t\tclearBuffer(); \n\t\t\t}\n\n\t\t}\n\t\tif (isprint(inChar))   // Only printable characters into the buffer\n\t\t{\n\t\t\tbuffer[bufPos++]=inChar;   // Put character into buffer\n\t\t\tbuffer[bufPos]='\\0';  // Null terminate\n\t\t\tif (bufPos > SERIALCOMMANDBUFFER-1) bufPos=0; // wrap buffer around if full  \n\t\t}\n\t}\n}\n\n// Adds a \"command\" and a handler function to the list of available commands.  \n// This is used for matching a found token in the buffer, and gives the pointer\n// to the handler function to deal with it. \nvoid SerialCommand::addCommand(const char *command, void (*function)())\n{\n\tif (numCommand < MAXSERIALCOMMANDS) {\n\t\t#ifdef SERIALCOMMANDDEBUG\n\t\tSerial.print(numCommand); \n\t\tSerial.print(\"-\"); \n\t\tSerial.print(\"Adding command for \"); \n\t\tSerial.println(command); \n\t\t#endif\n\t\t\n\t\tstrncpy(CommandList[numCommand].command,command,MAXDELIMETER); \n\t\tCommandList[numCommand].function = function; \n\t\tnumCommand++; \n\t} else {\n\t\t// In this case, you tried to push more commands into the buffer than it is compiled to hold.  \n\t\t// Not much we can do since there is no real visible error assertion, we just ignore adding\n\t\t// the command\n\t\t#ifdef SERIALCOMMANDDEBUG\n\t\tSerial.println(\"Too many handlers - recompile changing MAXSERIALCOMMANDS\"); \n\t\t#endif \n\t}\n}\n\n// This sets up a handler to be called in the event that the receveived command string\n// isn't in the list of things with handlers.\nvoid SerialCommand::addDefaultHandler(void (*function)())\n{\n\tdefaultHandler = function;\n}"
  },
  {
    "path": "src/SerialCommand.h",
    "content": "/******************************************************************************* \nSerialCommand - An Arduino library to tokenize and parse commands received over\na serial port. \nCopyright (C) 2011-2013 Steven Cogswell  <steven.cogswell@gmail.com>\nhttp://awtfy.com\n\nVersion 20131021A.   \n\nVersion History:\nMay 11 2011 - Initial version\nMay 13 2011 -\tPrevent overwriting bounds of SerialCommandCallback[] array in addCommand()\n\t\t\tdefaultHandler() for non-matching commands\nMar 2012 - Some const char * changes to make compiler happier about deprecated warnings.  \n           Arduino 1.0 compatibility (Arduino.h header) \nOct 2013 - SerialCommand object can be created using a SoftwareSerial object, for SoftwareSerial\n           support.  Requires #include <SoftwareSerial.h> in your sketch even if you don't use \n           a SoftwareSerial port in the project.  sigh.   See Example Sketch for usage. \nOct 2013 - Conditional compilation for the SoftwareSerial support, in case you really, really\n           hate it and want it removed.  \nJun 2022 - Using MAXDELIMETER as maximum length of serial command added when calling addCommand\n\t\t   order to reduce the usage of dynamic memory/RAM footprint.\n\nThis library is free software; you can redistribute it and/or\nmodify it under the terms of the GNU Lesser General Public\nLicense as published by the Free Software Foundation; either\nversion 2.1 of the License, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n***********************************************************************************/\n#ifndef SerialCommand_h\n#define SerialCommand_h\n\n#if defined(ARDUINO) && ARDUINO >= 100\n#include \"Arduino.h\"\n#else\n#include \"WProgram.h\"\n#endif\n\n// If you want to use SerialCommand with the hardware serial port only, and want to disable\n// SoftwareSerial support, and thus don't have to use \"#include <SoftwareSerial.h>\" in your\n// sketches, then uncomment this define for SERIALCOMMAND_HARDWAREONLY, and comment out the \n// corresponding #undef line.  \n//\n// You don't have to use SoftwareSerial features if this is not defined, you can still only use \n// the Hardware serial port, just that this way lets you get out of having to include \n// the SoftwareSerial.h header. \n//#define SERIALCOMMAND_HARDWAREONLY 1\n#undef SERIALCOMMAND_HARDWAREONLY\n\n#ifdef SERIALCOMMAND_HARDWAREONLY\n#warning \"Warning: Building SerialCommand without SoftwareSerial Support\"\n#endif\n\n#ifndef SERIALCOMMAND_HARDWAREONLY \n#include <SoftwareSerial.h>  \n#endif\n\n#include <string.h>\n\n#define SERIALCOMMANDBUFFER 35\n#define MAXSERIALCOMMANDS\t16\n#define MAXDELIMETER 2\n\n#define SERIALCOMMANDDEBUG 1\n#undef SERIALCOMMANDDEBUG      // Comment this out to run the library in debug mode (verbose messages)\n\nclass SerialCommand\n{\n\tpublic:\n\t\tSerialCommand();      // Constructor\n\t\t#ifndef SERIALCOMMAND_HARDWAREONLY\n\t\tSerialCommand(Stream &SoftSer);  // Constructor for using SoftwareSerial objects\n\t\t#endif\n\n\t\tvoid clearBuffer();   // Sets the command buffer to all '\\0' (nulls)\n\t\tchar *next();         // returns pointer to next token found in command buffer (for getting arguments to commands)\n\t\tvoid readSerial();    // Main entry point.  \n\t\tvoid addCommand(const char *, void(*)());   // Add commands to processing dictionary\n\t\tvoid addDefaultHandler(void (*function)());    // A handler to call when no valid command received. \n\t\n\tprivate:\n\t\tchar inChar;          // A character read from the serial stream \n\t\tchar buffer[SERIALCOMMANDBUFFER];   // Buffer of stored characters while waiting for terminator character\n\t\tint  bufPos;                        // Current position in the buffer\n\t\tchar delim[MAXDELIMETER];           // null-terminated list of character to be used as delimeters for tokenizing (default \" \")\n\t\tchar term;                          // Character that signals end of command (default '\\r')\n\t\tchar *token;                        // Returned token from the command buffer as returned by strtok_r\n\t\tchar *last;                         // State variable used by strtok_r during processing\n\t\ttypedef struct _callback {\n\t\t\tchar command[MAXDELIMETER];\n\t\t\tvoid (*function)();\n\t\t} SerialCommandCallback;            // Data structure to hold Command/Handler function key-value pairs\n\t\tint numCommand;\n\t\tSerialCommandCallback CommandList[MAXSERIALCOMMANDS];   // Actual definition for command/handler array\n\t\tvoid (*defaultHandler)();           // Pointer to the default handler function \n\t\tint usingSoftwareSerial;            // Used as boolean to see if we're using SoftwareSerial object or not\n\t\t#ifndef SERIALCOMMAND_HARDWAREONLY \n\t\tStream *_serialPort;         // Pointer to a user-created SoftwareSerial object\n\t\t#endif\n};\n\n#endif //SerialCommand_h"
  }
]