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