├── .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 /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Otto DIY Robot Arduino Libraries 2 | 3 | [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) 4 | ![version](https://img.shields.io/badge/version-13.0-blue) 5 | 6 | This repository has the main [Otto DIY robot](https://www.ottodiy.com/) libraries for Arduino compatible boards. 7 | 8 | ## Compatible Hardware 9 | 10 | - Designed to work mainly with Arduino Nano boards, but most of the code could be adapted to other microcontrollers. 11 | - Arduino Nano family 12 | - Arduino Uno 13 | - Arduino Micro 14 | - Arduino Mega 15 | - Arduino Mini 16 | - Arduino Leonardo 17 | - ESP8266 18 | - ESP32 (in development) 19 | 20 | :star: Star us on GitHub, it helps! 21 | 22 | ## Installation: 23 | 24 | You will need the [Arduino IDE on your computer](https://www.arduino.cc/en/software) 25 | You can find this library in the Arduino Manager as `OttoDIYLib` by Otto DIY, for quick installation or manually: 26 | 27 | 1. [Download Otto DIY libraries here](https://github.com/OttoDIY/OttoDIYLib/archive/master.zip) 28 | 2. Open the Arduino IDE and navigate to Sketch > Include Library > Add .ZIP Library... 29 | 3. Navigate to .zip file location that you just downloaded and open it. 30 | 4. You will see in the bottom black area a message that it has been installed.  31 | 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. 32 | 33 | *For more details or other ways to [install libraries, visit this link](https://www.arduino.cc/en/Guide/Libraries)  34 | 35 | ## Examples: 36 | 37 | You can find codes in File > Examples > OttoDIYLib. 38 | 39 | * `Otto_allmoves.ino` great code for testing all dance movements, sounds and gestures. 40 | * `Otto_APP.ino` this code is meant to work with the Bluetooth mobile app and module. 41 | * `Otto_touchmodes.ino` use a touch sensor or button to demo multiple modes. 42 | * `Otto_avoid.ino` uses the ultrasonic sensor to avoid obstacles. 43 | * `Otto_CalibrationWalk.ino` simple calibration for the servos. 44 | * `Otto_happybirthday.ino` plays a melody. 45 | 46 | * `Otto_singleladies.ino` dance according to the song. 47 | * `Otto_smoothcriminal.ino` dance according to the song. 48 | * `Otto_testSensor.ino` reads data from any analog sensor. 49 | * `Otto_photoresistor.ino` test light sensor. 50 | 51 | ## Library Structure 52 | 53 | Base set of libraries for any biped robot that uses 4 motors in the legs, like Otto. 54 | 55 | * `Otto.h` and `Otto.cpp` contain all the main functions. 56 | * `Otto_gestures.h` contain all the gesture functions. 57 | * `Otto_mouths.h` contains all the mouth functions. 58 | * `Otto_sounds.h` contains all the sound functions. 59 | * `Otto_matrix.h` contains all the matrix functions. 60 | * `Oscillator.h` is the main algorithm for the servo's "smooth" movement. 61 | * `SerialCommand.c` is for Bluetooth communication via software serial 62 | 63 | ### Adding libraries 64 | 65 | ```cpp 66 | #include 67 | Otto Otto; 68 | ``` 69 | 70 | ### Pins declaration 71 | 72 | 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. 73 | 74 | ```cpp 75 | #define LeftLeg 2 // left leg pin 76 | #define RightLeg 3 // right leg pin 77 | #define LeftFoot 4 // left foot pin 78 | #define RightFoot 5 // right foot pin 79 | #define Buzzer 13 //buzzer pin 80 | ``` 81 | 82 | ### Initialization 83 | 84 | When starting the program, the 'init' function must be called with the use of servo motor calibration as a parameter.
85 | It is best to place the servo motors in their home position after initialization with the 'home' function. 86 | 87 | ```cpp 88 | void setup() { 89 | Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer); 90 | Otto.home(); 91 | } 92 | ``` 93 | The `home()` function makes the servos move to the center position, with Otto standing in the neutral position. 94 | 95 | ## Predetermined Functions: 96 | Many preconfigured movements are available in the library: 97 | 98 | ### Movements: 99 | 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. 100 | 101 | #### Walk function 102 | 103 | ```cpp 104 | Otto.walk(steps, time, dir); 105 | ``` 106 | - `steps` are just how many times you want to repeat that movement without the need for further coding or adding additional rows. 107 | - `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. 108 | - `dir` is the direction: `1` for forward or `-1` backward 109 | 110 | Example: 111 | ```cpp 112 | Otto.walk(2, 1000, 1); 113 | ``` 114 | In this example, `2` is the number of steps, `1000` is "TIME" in milliseconds, and it will walk forward. 115 | 116 | Try changing T value: Slow=2000 Normal=1000 Fast= 500 117 | 118 | ```cpp 119 | Otto.turn(steps, T, dir); 120 | ``` 121 | (# of steps, T, to the left or -1 to the right) 122 | 123 | ```cpp 124 | Otto.bend (steps, T, dir); 125 | ``` 126 | 127 | (# of steps, T, 1 bends to the left or -1 to the right) 128 | 129 | ```cpp 130 | Otto.shakeLeg (steps, T, dir); 131 | ``` 132 | (# of steps, T, 1 bends to the left or -1 to the right) 133 | 134 | ```cpp 135 | Otto.jump(steps, T); 136 | ``` 137 | (# of steps up, T) This one does not have a dir parameter. 138 | Otto doesn't really jump. 😜 139 | 140 | ### Dances: 141 | 142 | 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. 143 | 144 | ```cpp 145 | Otto.moonwalker(steps, T, h, dir); 146 | ``` 147 | (# of steps, T, h, 1 to the left or -1 to the right) 148 | 149 | `h`: Try changing between 15 and 40. 150 | 151 | 152 | Example: 153 | ```cpp 154 | Otto.moonwalker(3, 1000, 25,1); 155 | ``` 156 | 157 | ```cpp 158 | Otto.crusaito(steps, T, h, dir); 159 | ``` 160 | (# of steps, T, h, 1 to the left or -1 to the right) 161 | 162 | `h`: Try changing between 20 and 50. 163 | 164 | ```cpp 165 | Otto.flapping(steps, T, h, dir); 166 | ``` 167 | (# of steps, T, h, 1 to the front or -1 to the back) 168 | 169 | `h`: Try changing between 10 and 30. 170 | 171 | ```cpp 172 | Otto.swing(steps, T, h); 173 | ``` 174 | `h`: Try changing between 0 and 50. 175 | 176 | ```cpp 177 | Otto.tiptoeSwing(steps, T, h); 178 | ``` 179 | `h`: Try changing between 0 and 50. 180 | 181 | ```cpp 182 | Otto.jitter(steps, T, h); 183 | ``` 184 | `h`: Try changing between 5 and 25. 185 | 186 | ```cpp 187 | Otto.updown(steps, T, h); 188 | ``` 189 | `h`: Try changing between 0 and 90. 190 | 191 | ```cpp 192 | Otto.ascendingTurn(steps, T, h); 193 | ``` 194 | `h`: Try changing between 5 and 15. 195 | 196 | ### Sounds: 197 | 198 | ``` 199 | Otto.sing(songName); 200 | ``` 201 | By just changing what is inside the () we can change the sounds easily to 19 different ones. 202 | It's as simple as copying and pasting in a new row to make the sounds as many times as you like. 203 | 204 | - S_connection 205 | - S_disconnection 206 | - S_buttonPushed 207 | - S_mode1 208 | - S_mode2 209 | - S_mode3 210 | - S_surprise 211 | - S_OhOoh 212 | - S_OhOoh2 213 | - S_cuddly 214 | - S_sleeping 215 | - S_happy 216 | - S_superHappy 217 | - S_happy_short 218 | - S_sad 219 | - S_confused 220 | - S_fart1 221 | - S_fart2 222 | - S_fart3 223 | 224 | Otto can emit several sounds with the 'sing' function: 225 | ```cpp 226 | Otto._tone(10, 3, 1); 227 | ``` 228 | 229 | (noteFrequency, noteDuration, silentDuration) 230 | 231 | ```cpp 232 | Otto.bendTones (100, 200, 1.04, 10, 10); 233 | ``` 234 | (initFrequency, finalFrequency, prop, noteDuration, silentDuration) 235 | 236 | 237 | ### Gestures: 238 | Finally, our favorite. This is a combination of the 2 previous functions we learned: sing + walk 239 | 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! 240 | 241 | ```cpp 242 | Otto.playGesture(gesture); 243 | ``` 244 | - `Otto.playGesture(OttoHappy);` 245 | - `Otto.playGesture(OttoSuperHappy);` 246 | - `Otto.playGesture(OttoSad);` 247 | - `Otto.playGesture(OttoVictory);` 248 | - `Otto.playGesture(OttoAngry);` 249 | - `Otto.playGesture(OttoSleeping);` 250 | - `Otto.playGesture(OttoFretful);` 251 | - `Otto.playGesture(OttoLove);` 252 | - `Otto.playGesture(OttoConfused);` 253 | - `Otto.playGesture(OttoFart);` 254 | - `Otto.playGesture(OttoWave);` 255 | - `Otto.playGesture(OttoMagic);` 256 | - `Otto.playGesture(OttoFail);` 257 | 258 | As you see, it’s very simple, but what it does is quite advanced. 259 | 260 | ## How to Contribute: 261 | Contributing to this software is warmly welcomed. 262 | 1. Test it, and if you find any problems, then post an issue. 263 | 2. Help us solve the issues or other bugs. 264 | 3. Improve and optimize the current libraries. 265 | 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).  266 | 267 | Welcome to the Otto DIY community. 268 | 269 | 270 | 271 | ## License 272 | 273 | The OttoDIYLib is licensed under the terms of the GPL Open Source 274 | license and is available for free. 275 | 276 | ## License: CC-BY-SA 277 | 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. 278 | 279 | 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. 280 | 281 | Big thanks to all our contributors: 282 | - @JavierIH 283 | - @Obijuan 284 | - @jarsoftelectrical 285 | - @stembotvn 286 | - @sfranzyshen 287 | - @tehniq3 288 | - @logix5 289 | - @DiegoSSJ 290 | - @loreman 291 | - @justinotherguy 292 | - @bhm93 293 | - @wendtbw 294 | - @agomezgar 295 | - @BodoMinea 296 | - @chico 297 | - @PinkDev1 298 | - @MXZZ 299 | - @Pawka 300 | - @per1234 301 | - @FedericoBusero 302 | - @hulkco 303 | - @mishafarms 304 | - @nisha-appanah 305 | - @pabloevaristo 306 | - @ProgrammerBruce 307 | - @Nca78 308 | - @dleval 309 | - @coliss86 310 | - @namepatrik 311 | -------------------------------------------------------------------------------- /examples/Otto_APP/Otto_APP.ino: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------------------------------------------------------------------------------------- 2 | //-- Otto DIY App Firmware Version 13 with standard baudrate of 9600 for Bluetooth BLE modules. 3 | //-- Otto DIY invests time and resources providing open source code and hardware, 4 | //-- please support by purchasing kits from (https://www.ottodiy.com) 5 | //-- Make sure to have installed all libraries: https://github.com/OttoDIY/OttoDIYLib 6 | //----------------------------------------------------------------- 7 | //-- 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 8 | //-- in accordance with the GPL when your application is distributed. See http://www.gnu.org/copyleft/gpl.html 9 | //--------------------- 10 | #include 11 | SoftwareSerial BTserial = SoftwareSerial(11,12); // RX pin to 12 and TX pin to 11 on the board 12 | SerialCommand SCmd(BTserial); 13 | #include 14 | Otto Otto; 15 | 16 | #define LeftLeg 2 17 | #define RightLeg 3 18 | #define LeftFoot 4 19 | #define RightFoot 5 20 | #define Buzzer 13 21 | #define DIN A3 // Data In pin 22 | #define CS A2 // Chip Select pin 23 | #define CLK A1 // Clock pin 24 | #define Orientation 1 // 8x8 LED Matrix orientation Top = 1, Bottom = 2, Left = 3, Right = 4 25 | #define PIN_Button A0 26 | #define PIN_ASSEMBLY 10 27 | 28 | int T = 1000; 29 | int moveId = 0; 30 | int moveSize = 15; 31 | volatile bool buttonPushed=false; 32 | unsigned long int matrix; 33 | void receiveStop() 34 | { sendAck(); Otto.home(); sendFinalAck(); } 35 | void receiveLED() 36 | { 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(); } 37 | void recieveBuzzer() 38 | { 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(); } 39 | void receiveTrims() 40 | { 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(); } 41 | void receiveServo() 42 | { 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(); } 43 | void receiveMovement() 44 | { 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; } 45 | void move(int moveId) 46 | { 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(); } 47 | void receiveGesture() 48 | { 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(); } 49 | void receiveSing() 50 | { 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(); } 51 | void sendAck() 52 | { delay(30); Serial.print(F("&&")); Serial.print(F("A")); Serial.println(F("%%")); Serial.flush(); } 53 | void sendFinalAck() 54 | { delay(30); Serial.print(F("&&")); Serial.print(F("F")); Serial.println(F("%%")); Serial.flush(); } 55 | void ButtonPushed() 56 | { if(!buttonPushed){ buttonPushed=true; Otto.putMouth(smallSurprise); } } 57 | 58 | void setup() { 59 | Serial.begin(9600); 60 | BTserial.begin(9600); 61 | Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer); //Set the servo pins and Buzzer pin 62 | Otto.initMATRIX( DIN, CS, CLK, Orientation); 63 | Otto.matrixIntensity(7); 64 | pinMode(PIN_ASSEMBLY, INPUT_PULLUP); 65 | pinMode(PIN_Button, INPUT); 66 | 67 | SCmd.addCommand("S", receiveStop); 68 | SCmd.addCommand("L", receiveLED); 69 | SCmd.addCommand("T", recieveBuzzer); 70 | SCmd.addCommand("M", receiveMovement); 71 | SCmd.addCommand("H", receiveGesture); 72 | SCmd.addCommand("K", receiveSing); 73 | SCmd.addCommand("C", receiveTrims); 74 | SCmd.addCommand("G", receiveServo); 75 | SCmd.addDefaultHandler(receiveStop); 76 | 77 | Otto.sing(S_connection); 78 | Otto.home(); 79 | for (int i = 0; i < 2; i++) { 80 | for (int i = 0; i < 8; i++) { 81 | Otto.putAnimationMouth(littleUuh, i); 82 | delay(150); 83 | } 84 | } 85 | Otto.putMouth(smile); 86 | Otto.sing(S_happy); 87 | delay(200); 88 | Otto.putMouth(happyOpen); 89 | 90 | while (digitalRead(PIN_ASSEMBLY) == LOW) { 91 | Otto.home(); 92 | Otto.sing(S_happy_short); // sing every 5 seconds so we know OTTO is still working 93 | delay(5000);} 94 | } 95 | 96 | void loop() { 97 | SCmd.readSerial(); 98 | if (Otto.getRestState()==false){ move(moveId); } 99 | } 100 | -------------------------------------------------------------------------------- /examples/Otto_CalibrationWalk/Otto_CalibrationWalk.ino: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------- 2 | //-- Otto DIY invests time and resources providing open source code and hardware, 3 | //-- please support by purchasing kits from https://www.ottodiy.com/ 4 | //-- Make sure to have installed all libraries: https://github.com/OttoDIY/OttoDIYLib 5 | //----------------------------------------------------------------- 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include //-- Otto Library 11 | Otto Otto; //This is Otto! 12 | 13 | #define LeftLeg 2 14 | #define RightLeg 3 15 | #define LeftFoot 4 16 | #define RightFoot 5 17 | #define Buzzer 13 18 | 19 | double angle_rad = PI/180.0; 20 | double angle_deg = 180.0/PI; 21 | int YL; 22 | int YR; 23 | int RL; 24 | int RR; 25 | 26 | void setup(){ 27 | Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer); //Set the servo pins and Buzzer pin 28 | Serial.begin(9600); 29 | YL = EEPROM.read(0); 30 | if (YL > 128) YL -= 256; 31 | YR = EEPROM.read(1); 32 | if (YR > 128) YR -= 256; 33 | RL = EEPROM.read(2); 34 | if (RL > 128) RL -= 256; 35 | RR = EEPROM.read(3); 36 | if (RR > 128) RR -= 256; 37 | Otto.home(); 38 | Serial.println("OTTO CALIBRATION PROGRAM"); 39 | Serial.println("PRESS a or z for adjusting Left Leg"); 40 | Serial.println("PRESS s or x for adjusting Left Foot"); 41 | Serial.println("PRESS k or m for adjusting Right Leg"); 42 | Serial.println("PRESS j or n for adjusting Right Foot"); 43 | Serial.println(); 44 | Serial.println("PRESS f to test Otto walking"); 45 | Serial.println("PRESS h to return servos to home position"); 46 | } 47 | 48 | void loop(){ 49 | int charRead = 0; 50 | 51 | if((Serial.available()) > (0)){ 52 | charRead = Serial.read(); 53 | } 54 | if(((charRead)==('a' ))){ 55 | YL++; 56 | Otto.setTrims(YL,YR,RL,RR); 57 | calib_homePos(); 58 | Otto.saveTrimsOnEEPROM(); 59 | }else{ 60 | if(((charRead)==( 'z' ))){ 61 | YL--; 62 | Otto.setTrims(YL,YR,RL,RR); 63 | calib_homePos(); 64 | Otto.saveTrimsOnEEPROM(); 65 | }else{ 66 | if(((charRead)==( 's' ))){ 67 | RL++; 68 | Otto.setTrims(YL,YR,RL,RR); 69 | calib_homePos(); 70 | Otto.saveTrimsOnEEPROM(); 71 | }else{ 72 | if(((charRead)==( 'x' ))){ 73 | RL--; 74 | Otto.setTrims(YL,YR,RL,RR); 75 | calib_homePos(); 76 | Otto.saveTrimsOnEEPROM(); 77 | }else{ 78 | if(((charRead)==( 'k' ))){ 79 | YR++; 80 | Otto.setTrims(YL,YR,RL,RR); 81 | calib_homePos(); 82 | Otto.saveTrimsOnEEPROM(); 83 | }else{ 84 | if(((charRead)==( 'm' ))){ 85 | YR--; 86 | Otto.setTrims(YL,YR,RL,RR); 87 | calib_homePos(); 88 | Otto.saveTrimsOnEEPROM(); 89 | }else{ 90 | if(((charRead)==( 'j' ))){ 91 | RR++; 92 | Otto.setTrims(YL,YR,RL,RR); 93 | calib_homePos(); 94 | Otto.saveTrimsOnEEPROM(); 95 | }else{ 96 | if(((charRead)==( 'n' ))){ 97 | RR--; 98 | Otto.setTrims(YL,YR,RL,RR); 99 | calib_homePos(); 100 | Otto.saveTrimsOnEEPROM(); 101 | }else{ 102 | if(((charRead)==( 'f' ))){ 103 | Otto.walk(1,1000,1); 104 | }else{ 105 | if(((charRead)==( 'h' ))){ 106 | Otto.home(); 107 | }else{ 108 | } 109 | } 110 | } 111 | } 112 | } 113 | } 114 | } 115 | } 116 | } 117 | } 118 | } 119 | 120 | void calib_homePos() { 121 | int servoPos[4]; 122 | servoPos[0]=90; 123 | servoPos[1]=90; 124 | servoPos[2]=90; 125 | servoPos[3]=90; 126 | Otto._moveServos(500, servoPos); 127 | Otto.detachServos(); 128 | } 129 | -------------------------------------------------------------------------------- /examples/Otto_allmoves/Otto_allmoves.ino: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------- 2 | //-- Otto All moves test 3 | //-- Otto DIY invests time and resources providing open source code and hardware, 4 | //-- please support by purchasing kits from https://www.ottodiy.com/ 5 | //-- Make sure to have installed all libraries: https://github.com/OttoDIY/OttoDIYLib 6 | //----------------------------------------------------------------- 7 | #include 8 | Otto Otto; //This is Otto! 9 | 10 | #define LeftLeg 2 11 | #define RightLeg 3 12 | #define LeftFoot 4 13 | #define RightFoot 5 14 | #define Buzzer 13 15 | #define DIN A3 // Data In pin 16 | #define CS A2 // Chip Select pin 17 | #define CLK A1 // Clock pin 18 | #define Orientation 1 // 8x8 LED Matrix orientation Top = 1, Bottom = 2, Left = 3, Right = 4 19 | 20 | /////////////////////////////////////////////////////////////////// 21 | //-- Setup ------------------------------------------------------// 22 | /////////////////////////////////////////////////////////////////// 23 | void setup(){ 24 | Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer); //Set the servo pins and Buzzer pin 25 | Otto.initMATRIX( DIN, CS, CLK, Orientation); 26 | Otto.sing(S_connection); //Otto wake up! 27 | Otto.home(); 28 | delay(50); 29 | Otto.playGesture(OttoHappy); 30 | } 31 | 32 | /////////////////////////////////////////////////////////////////// 33 | //-- Principal Loop ---------------------------------------------// 34 | /////////////////////////////////////////////////////////////////// 35 | void loop() { 36 | Otto.walk(2,1000,1); //2 steps, "TIME". IF HIGHER THE VALUE THEN SLOWER (from 600 to 1400), 1 FORWARD 37 | Otto.walk(2,1000,-1); //2 steps, T, -1 BACKWARD 38 | Otto.turn(2,1000,1);//3 steps turning LEFT 39 | Otto._tone(10, 3, 1); 40 | Otto.bendTones (100, 200, 1.04, 10, 10); 41 | Otto.home(); 42 | delay(100); 43 | Otto.turn(2,1000,-1);//3 steps turning RIGHT 44 | Otto.bend (1,500,1); //usually steps =1, T=2000 45 | Otto.bend (1,2000,-1); 46 | Otto.shakeLeg (1,1500, 1); 47 | Otto.home(); 48 | delay(100); 49 | Otto.shakeLeg (1,2000,-1); 50 | Otto.moonwalker(3, 1000, 25,1); //LEFT 51 | Otto.moonwalker(3, 1000, 25,-1); //RIGHT 52 | Otto.crusaito(2, 1000, 20,1); 53 | Otto.crusaito(2, 1000, 20,-1); 54 | delay(100); 55 | Otto.flapping(2, 1000, 20,1); 56 | Otto.flapping(2, 1000, 20,-1); 57 | delay(100); 58 | Otto.swing(2, 1000, 20); 59 | Otto.tiptoeSwing(2, 1000, 20); 60 | Otto.jitter(2, 1000, 20); //(small T) 61 | Otto.updown(2, 1500, 20); // 20 = H "HEIGHT of movement"T 62 | Otto.ascendingTurn(2, 1000, 50); 63 | Otto.jump(1,500); // It doesn't really jumpl ;P 64 | Otto.home(); 65 | delay(100); 66 | Otto.sing(S_cuddly); 67 | Otto.sing(S_OhOoh); 68 | Otto.sing(S_OhOoh2); 69 | Otto.sing(S_surprise); 70 | Otto.sing(S_buttonPushed); 71 | Otto.sing(S_mode1); 72 | Otto.sing(S_mode2); 73 | Otto.sing(S_mode3); 74 | Otto.sing(S_sleeping); 75 | Otto.sing(S_fart1); 76 | Otto.sing(S_fart2); 77 | Otto.sing(S_fart3); 78 | Otto.sing(S_happy); 79 | Otto.sing(S_happy_short); 80 | Otto.sing(S_superHappy); 81 | Otto.sing(S_sad); 82 | Otto.sing(S_confused); 83 | Otto.sing(S_disconnection); 84 | delay(100); 85 | Otto.playGesture(OttoHappy); 86 | Otto.playGesture(OttoSuperHappy); 87 | Otto.playGesture(OttoSad); 88 | Otto.playGesture(OttoVictory); 89 | Otto.playGesture(OttoAngry); 90 | Otto.playGesture(OttoSleeping); 91 | Otto.playGesture(OttoFretful); 92 | Otto.playGesture(OttoLove); 93 | Otto.playGesture(OttoConfused); 94 | Otto.playGesture(OttoFart); 95 | Otto.playGesture(OttoWave); 96 | Otto.playGesture(OttoMagic); 97 | Otto.playGesture(OttoFail); 98 | Otto.home(); 99 | delay(100); 100 | Otto.putMouth(zero); 101 | delay(100); 102 | Otto.putMouth(one); 103 | delay(100); 104 | Otto.putMouth(two); 105 | delay(100); 106 | Otto.putMouth(three); 107 | delay(100); 108 | Otto.putMouth(four); 109 | delay(100); 110 | Otto.putMouth(five); 111 | delay(100); 112 | Otto.putMouth(6); 113 | delay(100); 114 | Otto.putMouth(7); 115 | delay(100); 116 | Otto.putMouth(8); 117 | delay(100); 118 | Otto.putMouth(9); 119 | delay(100); 120 | Otto.putMouth(smile); 121 | delay(100); 122 | Otto.putMouth(happyOpen); 123 | delay(100); 124 | Otto.putMouth(happyClosed); 125 | delay(100); 126 | Otto.putMouth(heart); 127 | delay(100); 128 | Otto.putMouth(angry); 129 | delay(100); 130 | Otto.putMouth(smallSurprise); 131 | delay(100); 132 | Otto.putMouth(bigSurprise); 133 | delay(100); 134 | Otto.putMouth(tongueOut); 135 | delay(100); 136 | Otto.putMouth(confused); 137 | delay(100); 138 | Otto.putMouth(21); //diagonal 139 | delay(100); 140 | Otto.putMouth(27); //interrogation 141 | delay(100); 142 | Otto.putMouth(23); //sad open 143 | delay(100); 144 | Otto.putMouth(24); //sad closed 145 | delay(100); 146 | Otto.putMouth(vamp1); 147 | delay(100); 148 | Otto.putMouth(vamp2); 149 | delay(100); 150 | Otto.putMouth(xMouth); 151 | delay(100); 152 | Otto.putMouth(okMouth); 153 | delay(100); 154 | Otto.putMouth(thunder); 155 | delay(100); 156 | Otto.putMouth(lineMouth); 157 | delay(100); 158 | Otto.putMouth(culito); 159 | delay(100); 160 | Otto.putAnimationMouth(littleUuh,0); 161 | delay(1000); 162 | Otto.putAnimationMouth(dreamMouth, 0); 163 | delay(1000); 164 | Otto.putAnimationMouth(dreamMouth, 1); 165 | delay(1000); 166 | Otto.putAnimationMouth(dreamMouth, 2); 167 | delay(1000); 168 | } 169 | -------------------------------------------------------------------------------- /examples/Otto_avoid/Otto_avoid.ino: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------------------------------------------------------------------------------------------------- 2 | // Otto avoid obstacles with ultrasonic sensor sample sketch code 3 | //-- Otto DIY invests time and resources providing open source code and hardware, 4 | //-- please support by purchasing kits from https://www.ottodiy.com/ 5 | //-- Make sure to have installed all libraries: https://github.com/OttoDIY/OttoDIYLib 6 | //-------------------------------------------------------------------------------------------------------------------------------------------------------------------- 7 | #include 8 | Otto Otto; //This is Otto! 9 | //---------------------------------------------------------------------- 10 | #define LeftLeg 2 11 | #define RightLeg 3 12 | #define LeftFoot 4 13 | #define RightFoot 5 14 | #define Buzzer 13 15 | #define Trigger 8 // ultrasonic sensor trigger pin 16 | #define Echo 9 // ultrasonic sensor echo pin 17 | 18 | long ultrasound() { 19 | long duration, distance; 20 | digitalWrite(Trigger,LOW); 21 | delayMicroseconds(2); 22 | digitalWrite(Trigger, HIGH); 23 | delayMicroseconds(10); 24 | digitalWrite(Trigger, LOW); 25 | duration = pulseIn(Echo, HIGH); 26 | distance = duration/58; 27 | return distance; 28 | } 29 | 30 | 31 | void setup() { 32 | Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer); //Set the servo pins and Buzzer pin 33 | pinMode(Trigger, OUTPUT); 34 | pinMode(Echo, INPUT); 35 | 36 | } 37 | 38 | void loop() { 39 | if (ultrasound() <= 15) { 40 | Otto.sing(S_surprise); 41 | Otto.playGesture(OttoConfused); 42 | Otto.walk(2,1000,-1); // BACKWARD x2 43 | Otto.turn(3,1000,1); // LEFT x3 44 | } 45 | Otto.walk(1,1000,1); // FORWARD x1 46 | 47 | } 48 | -------------------------------------------------------------------------------- /examples/Otto_happybirthday/Otto_happybirthday.ino: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------- 2 | //-- Otto Happy Birthday 3 | //-- With this code Otto will walk 5 steps and then sing the happy birthday 4 | //-- Otto DIY invests time and resources providing open source code and hardware, 5 | //-- please support by purchasing kits from https://www.ottodiy.com/ 6 | //-- Make sure to have installed all libraries: https://github.com/OttoDIY/OttoDIYLib 7 | //----------------------------------------------------------------- 8 | #include 9 | Otto Otto; 10 | 11 | #define LeftLeg 2 12 | #define RightLeg 3 13 | #define LeftFoot 4 14 | #define RightFoot 5 15 | #define Buzzer 13 16 | 17 | int speakerPin = 13; 18 | int length = 28; // the number of notes 19 | char notes[] = "GGAGcB GGAGdc GGxecBA yyecdc"; 20 | 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 }; 21 | int tempo = 150; 22 | 23 | void playTone(int tone, int duration) { 24 | 25 | for (long i = 0; i < duration * 1000L; i += tone * 2) { 26 | digitalWrite(speakerPin, HIGH); 27 | delayMicroseconds(tone); 28 | digitalWrite(speakerPin, LOW); 29 | delayMicroseconds(tone); 30 | } 31 | } 32 | void playNote(char note, int duration) { 33 | 34 | char names[] = {'C', 'D', 'E', 'F', 'G', 'A', 'B', 35 | 36 | 'c', 'd', 'e', 'f', 'g', 'a', 'b', 37 | 38 | 'x', 'y' }; 39 | 40 | int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 41 | 42 | 956, 834, 765, 593, 468, 346, 224, 43 | 44 | 655 , 715 }; 45 | 46 | int SPEE = 5; // play the tone corresponding to the note name 47 | 48 | /* 49 | * Fix for => replace 17 by the size of names array 50 | */ 51 | for (int i = 0; i < sizeof(names); i++) { 52 | if (names[i] == note) { 53 | int newduration = duration/SPEE; 54 | playTone(tones[i], newduration); 55 | } 56 | } 57 | } 58 | 59 | void setup() { 60 | Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer); //Set the servo pins and Buzzer pin 61 | pinMode(speakerPin, OUTPUT); 62 | } 63 | 64 | void loop() { 65 | Otto.walk(5,1300,1); 66 | Otto.playGesture(OttoSuperHappy); 67 | for (int i = 0; i < length; i++) { 68 | if (notes[i] == ' ') { 69 | delay(beats[i] * tempo); // rest 70 | } else { 71 | playNote(notes[i], beats[i] * tempo); 72 | } 73 | // pause between notes 74 | delay(tempo); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /examples/Otto_photoresistorTest/Otto_photoresistorTest.ino: -------------------------------------------------------------------------------- 1 | // Define the pin to which the photoresistor is connected 2 | const int photoresistorPin = A0; 3 | int voltage_intensity = 0; 4 | int light_perc = 0; 5 | int sensorValue = 0; 6 | 7 | void setup() { 8 | // Initialize Serial communication 9 | Serial.begin(9600); 10 | } 11 | 12 | void loop() { 13 | // Read the analog value from the photoresistor 14 | sensorValue = 1023. - analogRead(photoresistorPin); 15 | voltage_intensity = (5.0/1023.) * sensorValue; 16 | light_perc = (voltage_intensity/5.0)*100.0; //converting values to percentages 17 | 18 | // Print the sensor value to the Serial Monitor 19 | Serial.print("Light Percentage: "); 20 | Serial.print(light_perc); 21 | Serial.println("%"); 22 | 23 | // Wait for a short delay 24 | delay(500); 25 | } 26 | -------------------------------------------------------------------------------- /examples/Otto_singleladies/Otto_singleladies.ino: -------------------------------------------------------------------------------- 1 | //---------------------------------------------------------------- 2 | //-- Otto Dance single ladies 3 | //-- This code will make Otto dance play the by Beyonce song at the same time and see it in action 4 | //-- Otto DIY invests time and resources providing open source code and hardware, 5 | //-- please support by purchasing kits from https://www.ottodiy.com/ 6 | //-- Make sure to have installed all libraries: https://github.com/OttoDIY/OttoDIYLib 7 | //----------------------------------------------------------------- 8 | #include 9 | #include 10 | #include 11 | 12 | #define N_SERVOS 4 13 | #define EEPROM_TRIM false //Activate for calibration with serial 14 | 15 | #define TRIM_RR 18 16 | #define TRIM_RL 18 17 | #define TRIM_YR 26 18 | #define TRIM_YL 18 19 | 20 | #define PIN_RL 2 21 | #define PIN_RR 3 22 | #define PIN_YR 4 23 | #define PIN_YL 5 24 | 25 | #define INTERVALTIME 10.0 26 | 27 | Oscillator servo[N_SERVOS]; 28 | 29 | void drunk (int tempo); 30 | void kickLeft(int tempo); 31 | void kickRight(int tempo); 32 | void pasitos(int steps, int tempo); 33 | void run(int steps, int T=500); 34 | void walk(int steps, int T=1000); 35 | void backyard(int steps, int T=3000); 36 | void moonWalkLeft(int steps, int T=1000); 37 | void moonWalkRight(int steps, int T=1000); 38 | void crusaito(int steps, int T=1000); 39 | void swing(int steps, int T=1000); 40 | void upDown(int steps, int tempo); 41 | void flapping(int steps, int T=1000); 42 | 43 | void setup() 44 | { 45 | Serial.begin(19200); 46 | 47 | servo[0].attach(PIN_RR); 48 | servo[1].attach(PIN_RL); 49 | servo[2].attach(PIN_YR); 50 | servo[3].attach(PIN_YL); 51 | 52 | int trim; 53 | 54 | if(EEPROM_TRIM){ 55 | for(int x=0;x<4;x++){ 56 | trim=EEPROM.read(x); 57 | if(trim>128)trim=trim-256; 58 | Serial.print("TRIM "); 59 | Serial.print(x); 60 | Serial.print(" en "); 61 | Serial.println(trim); 62 | servo[x].SetTrim(trim); 63 | } 64 | } 65 | else{ 66 | servo[0].SetTrim(TRIM_RR); 67 | servo[1].SetTrim(TRIM_RL); 68 | servo[2].SetTrim(TRIM_YR); 69 | servo[3].SetTrim(TRIM_YL); 70 | } 71 | 72 | for(int i=0;i<4;i++) servo[i].SetPosition(90); 73 | 74 | } 75 | 76 | // TEMPO: 97 BPM 77 | int t=620; 78 | double pause=0; 79 | 80 | void loop() { 81 | 82 | pasitos(8,t*2); 83 | crusaito(1,t); 84 | patada(t); 85 | delay(t); 86 | twist(2,t); 87 | twist(3,t/2); 88 | upDown(1,t*2); 89 | patada(t*2); 90 | drunk(t*2); 91 | flapping(1,t*2); 92 | walk(2,t); 93 | walk(1,t*2); 94 | backyard(2,t); 95 | patada(t*2); 96 | flapping(1,t*2); 97 | patada(t*2); 98 | twist(8,t/2); 99 | moonWalkLeft(2,t); 100 | crusaito(1,t*2); 101 | 102 | for(int i=0; i<2 ;i++){ 103 | lateral_fuerte(0,t); 104 | lateral_fuerte(1,t); 105 | upDown(1,t*2); 106 | } 107 | 108 | saludo(1,t*2); 109 | saludo(1,t); 110 | delay(t); 111 | swing(3,t); 112 | for(int i=0;i<4;i++) servo[i].SetPosition(90); 113 | delay(t); 114 | 115 | lateral_fuerte(0,t); 116 | lateral_fuerte(1,t); 117 | lateral_fuerte(0,t/2); 118 | lateral_fuerte(1,t/2); 119 | lateral_fuerte(0,t/2); 120 | delay(t/2); 121 | lateral_fuerte(0,t); 122 | lateral_fuerte(1,t); 123 | lateral_fuerte(0,t/2); 124 | lateral_fuerte(1,t/2); 125 | delay(t); 126 | 127 | pasitos(1,t*2); 128 | pasitos(1,t); 129 | delay(t/2); 130 | pasitos(1,t*2); 131 | pasitos(1,t); 132 | delay(t/2); 133 | 134 | crusaito(2,t); 135 | crusaito(1,t*2); 136 | crusaito(2,t); 137 | crusaito(1,t*2); 138 | crusaito(2,t); 139 | crusaito(1,t*2); 140 | 141 | upDown(2,t); 142 | crusaito(1,t*2); 143 | for(int i=0;i<4;i++) servo[i].SetPosition(90); 144 | delay(t/2); 145 | pasitos(2,t*2); 146 | pasitos(2,t); 147 | flapping(1,t*2); 148 | upDown(2,t); 149 | upDown(1,t*2); 150 | 151 | for (int i=0; i<4; i++){ 152 | pasitos(1,t); 153 | delay(t); 154 | } 155 | reverencia1(1,t*4); 156 | reverencia2(1,t*4); 157 | upDown(1,t); 158 | run(2,t/2); 159 | patada(t*2); 160 | 161 | lateral_fuerte(0,t); 162 | lateral_fuerte(1,t); 163 | upDown(2,t); 164 | lateral_fuerte(0,t); 165 | lateral_fuerte(1,t); 166 | upDown(2,t); 167 | pasitos(4,t); 168 | lateral_fuerte(0,t); 169 | lateral_fuerte(1,t); 170 | upDown(2,t); 171 | 172 | patada(t*2); 173 | pasitos(2,t); 174 | patada(t*2); 175 | pasitos(2,t); 176 | swing(2,t*2); 177 | pasitos(4,t); 178 | 179 | for (int i=0; i<4; i++){ 180 | lateral_fuerte(0,t); 181 | lateral_fuerte(1,t); 182 | lateral_fuerte(0,t/2); 183 | lateral_fuerte(1,t/2); 184 | lateral_fuerte(0,t/2); 185 | delay(t/2); 186 | } 187 | 188 | pasitos(6,t); 189 | delay(t); 190 | pasitos(1,t); 191 | delay(t/2); 192 | pasitos(3,t); 193 | delay(t/2); 194 | swing(4,t); 195 | 196 | twist(2,t/2); 197 | delay(t/2); 198 | twist(2,t/2); 199 | delay(t/2); 200 | 201 | drunk(t*2); 202 | drunk(t/2); 203 | drunk(t*2); 204 | delay(t/2); 205 | walk(1,t); 206 | backyard(1,t); 207 | 208 | servo[0].SetPosition(110); 209 | servo[1].SetPosition(130); 210 | delay(t); 211 | 212 | crusaito(3,t); 213 | crusaito(1,2*t); 214 | upDown(1,t*2); 215 | upDown(2,t/2); 216 | 217 | kickLeft(t/2); 218 | kickRight(t/2); 219 | moonWalkLeft(1,t*2); 220 | moonWalkLeft(2,t); 221 | moonWalkRight(1,t*2); 222 | moonWalkRight(2,t); 223 | 224 | walk(4,t); 225 | backyard(4,t); 226 | 227 | lateral_fuerte(0,t); 228 | lateral_fuerte(0,t); 229 | lateral_fuerte(1,t); 230 | lateral_fuerte(1,t); 231 | walk(2,t); 232 | backyard(2,t); 233 | 234 | pasitos(6,t*2); 235 | swing(1,t); 236 | upDown(1,t); 237 | delay(t); 238 | upDown(6,t); 239 | delay(t); 240 | 241 | for (int i=0;i<4;i++){ 242 | lateral_fuerte(0,t); 243 | lateral_fuerte(1,t); 244 | } 245 | 246 | delay(t); 247 | for (int i=0;i<7;i++){ 248 | pasitos(2,t); 249 | swing(2,t); 250 | } 251 | 252 | pasitos(1,t); 253 | crusaito(1,t*2); 254 | upDown(1,t); 255 | 256 | delay(2000); 257 | 258 | 259 | } 260 | //////////////////////////////////CONTROL FUNCTIONS////////////////////////////////// 261 | void oscillate(int A[N_SERVOS], int O[N_SERVOS], int T, double phase_diff[N_SERVOS]){ 262 | for (int i=0; i<4; i++) { 263 | servo[i].SetO(O[i]); 264 | servo[i].SetA(A[i]); 265 | servo[i].SetT(T); 266 | servo[i].SetPh(phase_diff[i]); 267 | } 268 | double ref=millis(); 269 | for (double x=ref; x 7 | #include 8 | #include 9 | #define N_SERVOS 4 10 | //-- Make sure the servos are in the right pin 11 | /* -------- 12 | | O O | 13 | |--------| 14 | RIGHT LEG (YR) 3 | | LEFT LEG 2 (YL) 15 | -------- 16 | || || 17 | RIGHT FOOT (RR) 5 |--- ---| LEFT FOOT 4 (RL) 18 | */ 19 | #define EEPROM_TRIM false 20 | // Activate to take callibration data from internal memory 21 | #define TRIM_RR 7 22 | #define TRIM_RL 4 23 | #define TRIM_YR 4 24 | #define TRIM_YL -7 25 | //OTTO.setTrims(-7,-4,-4,7); 26 | 27 | #define PIN_RR 5 28 | #define PIN_RL 4 29 | #define PIN_YR 3 30 | #define PIN_YL 2 31 | 32 | #define INTERVALTIME 10.0 33 | 34 | Oscillator servo[N_SERVOS]; 35 | 36 | void goingUp(int tempo); 37 | void drunk (int tempo); 38 | void noGravity(int tempo); 39 | void kickLeft(int tempo); 40 | void kickRight(int tempo); 41 | void run(int steps, int T=500); 42 | void walk(int steps, int T=1000); 43 | void backyard(int steps, int T=3000); 44 | void backyardSlow(int steps, int T=5000); 45 | void turnLeft(int steps, int T=3000); 46 | void turnRight(int steps, int T=3000); 47 | void moonWalkLeft(int steps, int T=1000); 48 | void moonWalkRight(int steps, int T=1000); 49 | void crusaito(int steps, int T=1000); 50 | void swing(int steps, int T=1000); 51 | void upDown(int steps, int T=1000); 52 | void flapping(int steps, int T=1000); 53 | 54 | void setup() 55 | { 56 | Serial.begin(19200); 57 | 58 | servo[0].attach(PIN_RR); 59 | servo[1].attach(PIN_RL); 60 | servo[2].attach(PIN_YR); 61 | servo[3].attach(PIN_YL); 62 | 63 | //EEPROM.write(0,TRIM_RR); 64 | //EEPROM.write(1,TRIM_RL); 65 | //EEPROM.write(2,TRIM_YR); 66 | //EEPROM.write(3,TRIM_YL); 67 | 68 | int trim; 69 | 70 | if(EEPROM_TRIM){ 71 | for(int x=0;x<4;x++){ 72 | trim=EEPROM.read(x); 73 | if(trim>128)trim=trim-256; 74 | Serial.print("TRIM "); 75 | Serial.print(x); 76 | Serial.print(" en "); 77 | Serial.println(trim); 78 | servo[x].SetTrim(trim); 79 | } 80 | } 81 | else{ 82 | servo[0].SetTrim(TRIM_RR); 83 | servo[1].SetTrim(TRIM_RL); 84 | servo[2].SetTrim(TRIM_YR); 85 | servo[3].SetTrim(TRIM_YL); 86 | } 87 | 88 | for(int i=0;i<4;i++) servo[i].SetPosition(90); 89 | } 90 | 91 | // TEMPO: 121 BPM 92 | int t=495; 93 | double pause=0; 94 | 95 | void loop() 96 | { 97 | // if(Serial.available()){ 98 | // char init = Serial.read(); 99 | // if (init=='X'){ 100 | // delay(4000); //3000 - 4500 101 | 102 | dance(); 103 | 104 | //for(int i=0;i<4;i++) servo[i].SetPosition(90); 105 | 106 | for(int i=0;i<4;i++) servo[i].SetPosition(90); 107 | // } 108 | // } 109 | } 110 | 111 | void dance(){ 112 | primera_parte(); segunda_parte(); 113 | moonWalkLeft(4,t*2); moonWalkRight(4,t*2); moonWalkLeft(4,t*2); moonWalkRight(4,t*2); 114 | primera_parte(); 115 | crusaito(1,t*8); crusaito(1,t*7); 116 | for (int i=0; i<16; i++){ flapping(1,t/4); delay(3*t/4); } 117 | moonWalkRight(4,t*2); moonWalkLeft(4,t*2); moonWalkRight(4,t*2); moonWalkLeft(4,t*2); 118 | drunk(t*4);drunk(t*4); drunk(t*4); drunk(t*4); 119 | kickLeft(t); kickRight(t); 120 | drunk(t*8); drunk(t*4);drunk(t/2); 121 | delay(t*4); 122 | drunk(t/2); 123 | delay(t*4); 124 | walk(2,t*2); 125 | backyard(2,t*2); 126 | goingUp(t*2); goingUp(t*1); 127 | noGravity(t*2); 128 | crusaito(1,t*2); crusaito(1,t*8); crusaito(1,t*2); crusaito(1,t*8); crusaito(1,t*2); crusaito(1,t*3); 129 | delay(t); 130 | primera_parte(); 131 | for (int i=0; i<32; i++){ flapping(1,t/2); delay(t/2); } 132 | for(int i=0;i<4;i++) servo[i].SetPosition(90);} 133 | 134 | //////////////////////////////////CONTROL FUNCTIONS////////////////////////////////// 135 | 136 | void oscillate(int A[N_SERVOS], int O[N_SERVOS], int T, double phase_diff[N_SERVOS]){ 137 | for (int i=0; i<4; i++) { 138 | servo[i].SetO(O[i]); 139 | servo[i].SetA(A[i]); 140 | servo[i].SetT(T); 141 | servo[i].SetPh(phase_diff[i]); 142 | } 143 | double ref=millis(); 144 | for (double x=ref; x 11 | Otto Otto; //This is Otto! 12 | //--------------------------------------------------------- 13 | //-- First step: Make sure the pins for servos are in the right position 14 | /* -------- 15 | | O O | 16 | |--------| 17 | RIGHT LEG 3 | | LEFT LEG 2 18 | -------- 19 | || || 20 | RIGHT FOOT 5 |--- ---| LEFT FOOT 4 21 | */ 22 | #define LeftLeg 2 23 | #define RightLeg 3 24 | #define LeftFoot 4 25 | #define RightFoot 5 26 | #define Buzzer 13 27 | #define Trigger 8 // ultrasonic sensor trigger pin 28 | #define Echo 9 // ultrasonic sensor echo pin 29 | 30 | const int sensorPin = A0; 31 | 32 | long ultrasound() { 33 | long duration, distance; 34 | digitalWrite(Trigger,LOW); 35 | delayMicroseconds(2); 36 | digitalWrite(Trigger, HIGH); 37 | delayMicroseconds(10); 38 | digitalWrite(Trigger, LOW); 39 | duration = pulseIn(Echo, HIGH); 40 | distance = duration/58; 41 | return distance; 42 | } 43 | int movement = 0; 44 | boolean izqder = true; // TEMPO: 97 BPM 45 | bool obstacleDetected = false; 46 | /////////////////////////////////////////////////////////////////// 47 | //-- Setup ------------------------------------------------------// 48 | /////////////////////////////////////////////////////////////////// 49 | void setup(){ 50 | Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer); //Set the servo pins and Buzzer pin 51 | pinMode(sensorPin, INPUT); 52 | pinMode(Trigger, OUTPUT); 53 | pinMode(Echo, INPUT); 54 | Otto.home(); 55 | Otto.sing(S_happy); // a happy Otto :) 56 | } 57 | // touch sensor is in "toggle mode", initial value LOW 58 | // program expects HIGH value for first touch 59 | // and then expects LOW value for second touch 60 | // and then again HIGH and LOW etc. 61 | // 62 | int estado = HIGH; //first expected touch value 63 | 64 | /////////////////////////////////////////////////////////////////// 65 | //-- Principal Loop ---------------------------------------------// 66 | /////////////////////////////////////////////////////////////////// 67 | void loop() { 68 | 69 | if (digitalRead(sensorPin) == estado) 70 | { 71 | if (estado == HIGH) 72 | { 73 | estado = LOW; //toggle expect value 74 | } 75 | else 76 | { 77 | estado = HIGH; //toggle expect value 78 | } 79 | Otto.sing(S_buttonPushed); 80 | movement = movement + 1; 81 | delay(500); 82 | } 83 | if (movement == 1) 84 | { 85 | if(obstacleDetected){ 86 | Serial.println("OBJETO DETECTADO"); 87 | Otto.sing(S_OhOoh); 88 | 89 | if (izqder == true) 90 | { 91 | Otto.walk(2,1000,-1); 92 | Otto.turn(2,1000,1);//2 steps turning RIGHT 93 | izqder = false; 94 | } 95 | else 96 | { 97 | Otto.walk(2,1000,-1); 98 | Otto.turn(2,1000,-1);//2 steps turning LEFT 99 | izqder = true; 100 | } 101 | 102 | //Otto.home(); 103 | delay(50); 104 | obstacleDetector(); 105 | } 106 | else 107 | { 108 | Otto.walk(1,500,1); 109 | delay(50); 110 | //Otto.home(); 111 | obstacleDetector(); 112 | } 113 | } 114 | 115 | if (movement == 2) 116 | { 117 | if(obstacleDetected){ 118 | Serial.println("Object detected"); 119 | Otto.walk(2,1000,1); 120 | Otto.home(); 121 | //delay(60); 122 | obstacleDetector(); 123 | //delay(10) ; 124 | } 125 | else{ 126 | obstacleDetector(); 127 | } 128 | } 129 | 130 | if (movement == 3) 131 | { 132 | Otto.jitter(10,500,40); 133 | Otto.home(); 134 | Otto.moonwalker(2,1000,30,1); 135 | Otto.home(); 136 | Otto.ascendingTurn(2,500,50); 137 | Otto.home(); 138 | Otto.tiptoeSwing(2,1000,30); 139 | Otto.home(); 140 | Otto.flapping(2,500,40,1); 141 | Otto.home(); 142 | Otto.crusaito(2,3000,40,1); 143 | Otto.home(); 144 | Otto.shakeLeg(2,1000,1); 145 | Otto.home(); 146 | Otto.sing(S_disconnection); 147 | movement = 0; 148 | } 149 | } 150 | 151 | /////////////////////////////////////////////////////////////////// 152 | //-- Function to read distance sensor & to update obstacleDetected variable 153 | void obstacleDetector(){ 154 | int distance = ultrasound(); 155 | if(distance<15){ 156 | obstacleDetected = true; 157 | }else{ 158 | obstacleDetected = false; 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For OttoDIYLib 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | Otto KEYWORD1 9 | ####################################### 10 | # Methods and Functions (KEYWORD2) 11 | ####################################### 12 | init KEYWORD2 13 | initDC KEYWORD2 14 | initMATRIX KEYWORD2 15 | home KEYWORD2 16 | putMouth KEYWORD2 17 | writeText KEYWORD2 18 | clearMouth KEYWORD2 19 | sing KEYWORD2 20 | walk KEYWORD2 21 | playGesture KEYWORD2 22 | ####################################### 23 | # Instances (KEYWORD2) 24 | ####################################### 25 | 26 | ####################################### 27 | # Constants (LITERAL1) 28 | ####################################### 29 | FORWARD LITERAL1 30 | BACKWARD LITERAL1 31 | LEFT LITERAL1 32 | RIGHT LITERAL1 33 | SMALL LITERAL1 34 | MEDIUM LITERAL1 35 | BIG LITERAL1 36 | 37 | S_connection LITERAL1 38 | S_disconnection LITERAL1 39 | S_buttonPushed LITERAL1 40 | S_mode1 LITERAL1 41 | S_mode2 LITERAL1 42 | S_mode3 LITERAL1 43 | S_surprise LITERAL1 44 | S_OhOoh LITERAL1 45 | S_OhOoh2 LITERAL1 46 | S_cuddly LITERAL1 47 | S_sleeping LITERAL1 48 | S_happy LITERAL1 49 | S_superHappy LITERAL1 50 | S_happy_short LITERAL1 51 | S_sad LITERAL1 52 | S_confused LITERAL1 53 | S_fart1 LITERAL1 54 | S_fart2 LITERAL1 55 | S_fart3 LITERAL1 56 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "OttoDIYLib", 3 | "version": "13.0.0", 4 | "description": "Official Arduino library for controlling original Otto DIY bipedal robots", 5 | "keywords": "otto, ottodiy, robot, servo", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/OttoDIY/OttoDIYLib" 9 | }, 10 | "authors": [ 11 | { 12 | "name": "Otto DIY community", 13 | "url": "https://github.com/OttoDIY", 14 | "maintainer": true 15 | } 16 | ], 17 | "license": "GPL-3.0-or-later", 18 | "frameworks": "arduino", 19 | "platforms": "atmelavr" 20 | } 21 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=OttoDIYLib 2 | version=13.0.0 3 | author=Otto DIY, Camilo Parra Palacio 4 | maintainer=@cparrapa 5 | sentence=Otto DIY official Arduino Libraries. 6 | paragraph=OttoDIYLib contains all the main Otto robot libraries to program Arduino avr, ESP8266 or ESP32 compatible boards. 7 | category=Device Control 8 | url=https://www.ottodiy.com/ 9 | architectures=avr, esp8266, esp32 10 | includes=Otto.h 11 | -------------------------------------------------------------------------------- /src/Oscillator.cpp: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------- 2 | //-- Oscillator.pde 3 | //-- Generate sinusoidal oscillations in the servos 4 | //-------------------------------------------------------------- 5 | //-- (c) Juan Gonzalez-Gomez (Obijuan), Dec 2011 6 | //-- GPL license 7 | //-------------------------------------------------------------- 8 | #if defined(ARDUINO) && ARDUINO >= 100 9 | #include "Arduino.h" 10 | #else 11 | #include "WProgram.h" 12 | #include 13 | #endif 14 | #include "Oscillator.h" 15 | 16 | //-- This function returns true if another sample 17 | //-- should be taken (i.e. the TS time has passed since 18 | //-- the last sample was taken 19 | bool Oscillator::next_sample() 20 | { 21 | 22 | //-- Read current time 23 | _currentMillis = millis(); 24 | 25 | //-- Check if the timeout has passed 26 | if(_currentMillis - _previousMillis > _samplingPeriod) { 27 | _previousMillis = _currentMillis; 28 | 29 | return true; 30 | } 31 | 32 | return false; 33 | } 34 | 35 | //-- Attach an oscillator to a servo 36 | //-- Input: pin is the arduino pin were the servo 37 | //-- is connected 38 | void Oscillator::attach(int pin, bool rev) 39 | { 40 | //-- If the oscillator is detached, attach it. 41 | if(!_servo.attached()){ 42 | 43 | //-- Attach the servo and move it to the home position 44 | _servo.attach(pin); 45 | _pos = 90; 46 | _servo.write(90); 47 | _previousServoCommandMillis = millis(); 48 | 49 | //-- Initialization of oscilaltor parameters 50 | _samplingPeriod=30; 51 | _period=2000; 52 | _numberSamples = _period/_samplingPeriod; 53 | _inc = 2*M_PI/_numberSamples; 54 | 55 | _previousMillis=0; 56 | 57 | //-- Default parameters 58 | _amplitude=45; 59 | _phase=0; 60 | _phase0=0; 61 | _offset=0; 62 | _stop=false; 63 | 64 | //-- Reverse mode 65 | _rev = rev; 66 | } 67 | 68 | } 69 | 70 | //-- Detach an oscillator from his servo 71 | void Oscillator::detach() 72 | { 73 | //-- If the oscillator is attached, detach it. 74 | if(_servo.attached()) 75 | _servo.detach(); 76 | 77 | } 78 | 79 | /*************************************/ 80 | /* Set the oscillator period, in ms */ 81 | /*************************************/ 82 | void Oscillator::SetT(unsigned int T) 83 | { 84 | //-- Assign the new period 85 | _period=T; 86 | 87 | //-- Recalculate the parameters 88 | _numberSamples = _period/_samplingPeriod; 89 | _inc = 2*M_PI/_numberSamples; 90 | }; 91 | 92 | /*******************************/ 93 | /* Manual set of the position */ 94 | /******************************/ 95 | 96 | void Oscillator::SetPosition(int position) 97 | { 98 | write(position); 99 | }; 100 | 101 | 102 | /*******************************************************************/ 103 | /* This function should be periodically called */ 104 | /* in order to maintain the oscillations. It calculates */ 105 | /* if another sample should be taken and position the servo if so */ 106 | /*******************************************************************/ 107 | void Oscillator::refresh() 108 | { 109 | 110 | //-- Only When TS milliseconds have passed, the new sample is obtained 111 | if (next_sample()) { 112 | 113 | //-- If the oscillator is not stopped, calculate the servo position 114 | if (!_stop) { 115 | //-- Sample the sine function and set the servo pos 116 | int pos = round(_amplitude * sin(_phase + _phase0) + _offset); 117 | if (_rev) pos=-pos; 118 | write(pos+90); 119 | } 120 | 121 | //-- Increment the phase 122 | //-- It is always increased, even when the oscillator is stop 123 | //-- so that the coordination is always kept 124 | _phase = _phase + _inc; 125 | 126 | } 127 | } 128 | 129 | void Oscillator::write(int position) 130 | { 131 | long currentMillis = millis(); 132 | if (_diff_limit > 0) { 133 | int limit = max(1,(((int)(currentMillis - _previousServoCommandMillis)) * _diff_limit) / 1000); 134 | if (abs(position - _pos) > limit) { 135 | _pos += position < _pos ? -limit : limit; 136 | } else { 137 | _pos = position; 138 | } 139 | } 140 | else { 141 | _pos = position; 142 | } 143 | _previousServoCommandMillis = currentMillis; 144 | _servo.write(_pos + _trim); 145 | } 146 | -------------------------------------------------------------------------------- /src/Oscillator.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------- 2 | //-- Oscillator.pde 3 | //-- Generate sinusoidal oscillations in the servos 4 | //-------------------------------------------------------------- 5 | //-- (c) Juan Gonzalez-Gomez (Obijuan), Dec 2011 6 | //-- GPL license 7 | //-------------------------------------------------------------- 8 | #ifndef Oscillator_h 9 | #define Oscillator_h 10 | 11 | #ifdef ARDUINO_ARCH_ESP32 12 | #include 13 | #else 14 | #include 15 | #endif 16 | 17 | //-- Macro for converting from degrees to radians 18 | #ifndef DEG2RAD 19 | #define DEG2RAD(g) ((g)*M_PI)/180 20 | #endif 21 | 22 | class Oscillator 23 | { 24 | public: 25 | Oscillator(int trim=0) {_trim=trim; _diff_limit = 0; }; 26 | void attach(int pin, bool rev =false); 27 | void detach(); 28 | 29 | void SetA(unsigned int amplitude) {_amplitude=amplitude;}; 30 | void SetO(int offset) {_offset=offset;}; 31 | void SetPh(double Ph) {_phase0=Ph;}; 32 | void SetT(unsigned int period); 33 | void SetTrim(int trim){_trim=trim;}; 34 | void SetLimiter(int diff_limit) { _diff_limit = diff_limit; }; 35 | void DisableLimiter() { _diff_limit = 0; }; 36 | int getTrim() {return _trim;}; 37 | void SetPosition(int position); 38 | void Stop() {_stop=true;}; 39 | void Play() {_stop=false;}; 40 | void Reset() {_phase=0;}; 41 | void refresh(); 42 | int getPosition() { return _pos;} 43 | 44 | private: 45 | bool next_sample(); 46 | void write(int position); 47 | 48 | private: 49 | //-- Servo that is attached to the oscillator 50 | Servo _servo; 51 | 52 | //-- Oscillators parameters 53 | unsigned int _amplitude; //-- Amplitude (degrees) 54 | int _offset; //-- Offset (degrees) 55 | unsigned int _period; //-- Period (miliseconds) 56 | double _phase0; //-- Phase (radians) 57 | 58 | //-- Internal variables 59 | int _pos; //-- Current servo pos 60 | int _trim; //-- Calibration offset 61 | double _phase; //-- Current phase 62 | double _inc; //-- Increment of phase 63 | double _numberSamples; //-- Number of samples 64 | unsigned int _samplingPeriod; //-- sampling period (ms) 65 | 66 | long _previousMillis; 67 | long _currentMillis; 68 | 69 | //-- Oscillation mode. If true, the servo is stopped 70 | bool _stop; 71 | 72 | //-- Reverse mode 73 | bool _rev; 74 | 75 | // -- Limit of the angle delta send to servos 76 | // This is for smooth movement and preventing Ardino to crash 77 | // because of the high current consumed by servo motors. 78 | // set 0 for disabling the limiter 79 | int _diff_limit; 80 | long _previousServoCommandMillis; 81 | }; 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /src/Otto.cpp: -------------------------------------------------------------------------------- 1 | #if defined(ARDUINO) && ARDUINO >= 100 2 | #include "Arduino.h" 3 | #else 4 | #include "WProgram.h" 5 | #include 6 | #endif 7 | #include "Otto.h" 8 | #include 9 | 10 | void Otto::init(int YL, int YR, int RL, int RR, bool load_calibration, int Buzzer) { 11 | 12 | servo_pins[0] = YL; 13 | servo_pins[1] = YR; 14 | servo_pins[2] = RL; 15 | servo_pins[3] = RR; 16 | 17 | attachServos(); 18 | isOttoResting=false; 19 | 20 | if (load_calibration) { 21 | for (int i = 0; i < 4; i++) { 22 | int servo_trim = EEPROM.read(i); 23 | if (servo_trim > 128) servo_trim -= 256; 24 | servo[i].SetTrim(servo_trim); 25 | } 26 | } 27 | 28 | //Buzzer pin: 29 | pinBuzzer = Buzzer; 30 | pinMode(Buzzer,OUTPUT); 31 | 32 | } 33 | /////////////////////////////////////////////////////// 34 | void Otto::initMATRIX(int DIN, int CS, int CLK, int rotate){ 35 | ledmatrix.init( DIN, CS, CLK, 1, rotate); // set up Matrix display 36 | } 37 | void Otto::matrixIntensity(int intensity){ 38 | ledmatrix.setIntensity(intensity); 39 | } 40 | 41 | /////////////////////////////////////////////////////////////////// 42 | //-- ATTACH & DETACH FUNCTIONS ----------------------------------// 43 | /////////////////////////////////////////////////////////////////// 44 | void Otto::attachServos(){ 45 | servo[0].attach(servo_pins[0]); 46 | servo[1].attach(servo_pins[1]); 47 | servo[2].attach(servo_pins[2]); 48 | servo[3].attach(servo_pins[3]); 49 | } 50 | 51 | void Otto::detachServos(){ 52 | servo[0].detach(); 53 | servo[1].detach(); 54 | servo[2].detach(); 55 | servo[3].detach(); 56 | } 57 | 58 | /////////////////////////////////////////////////////////////////// 59 | //-- OSCILLATORS TRIMS ------------------------------------------// 60 | /////////////////////////////////////////////////////////////////// 61 | void Otto::setTrims(int YL, int YR, int RL, int RR) { 62 | servo[0].SetTrim(YL); 63 | servo[1].SetTrim(YR); 64 | servo[2].SetTrim(RL); 65 | servo[3].SetTrim(RR); 66 | } 67 | 68 | void Otto::saveTrimsOnEEPROM() { 69 | 70 | for (int i = 0; i < 4; i++){ 71 | EEPROM.write(i, servo[i].getTrim()); 72 | } 73 | } 74 | 75 | /////////////////////////////////////////////////////////////////// 76 | //-- BASIC MOTION FUNCTIONS -------------------------------------// 77 | /////////////////////////////////////////////////////////////////// 78 | void Otto::_moveServos(int time, int servo_target[]) { 79 | 80 | attachServos(); 81 | if(getRestState()==true){ 82 | setRestState(false); 83 | } 84 | 85 | final_time = millis() + time; 86 | if(time>10){ 87 | for (int i = 0; i < 4; i++) increment[i] = (servo_target[i] - servo[i].getPosition()) / (time / 10.0); 88 | 89 | for (int iteration = 1; millis() < final_time; iteration++) { 90 | partial_time = millis() + 10; 91 | for (int i = 0; i < 4; i++) servo[i].SetPosition(servo[i].getPosition() + increment[i]); 92 | while (millis() < partial_time); //pause 93 | } 94 | } 95 | else{ 96 | for (int i = 0; i < 4; i++) servo[i].SetPosition(servo_target[i]); 97 | while (millis() < final_time); //pause 98 | } 99 | 100 | // final adjustment to the target. if servo speed limiter is turned on, reaching to the goal may take longer than 101 | // requested time. 102 | bool f = true; 103 | while(f) { 104 | f = false; 105 | for (int i = 0; i < 4; i++) { 106 | if (servo_target[i] != servo[i].getPosition()) { 107 | f = true; 108 | break; 109 | } 110 | } 111 | if (f) { 112 | for (int i = 0; i < 4; i++) { 113 | servo[i].SetPosition(servo_target[i]); 114 | } 115 | partial_time = millis() + 10; 116 | while (millis() < partial_time); //pause 117 | } 118 | }; 119 | } 120 | 121 | void Otto::_moveSingle(int position, int servo_number) { 122 | if (position > 180) position = 90; 123 | if (position < 0) position = 90; 124 | attachServos(); 125 | if(getRestState()==true){ 126 | setRestState(false); 127 | } 128 | int servoNumber = servo_number; 129 | if (servoNumber == 0){ 130 | servo[0].SetPosition(position); 131 | } 132 | if (servoNumber == 1){ 133 | servo[1].SetPosition(position); 134 | } 135 | if (servoNumber == 2){ 136 | servo[2].SetPosition(position); 137 | } 138 | if (servoNumber == 3){ 139 | servo[3].SetPosition(position); 140 | } 141 | } 142 | 143 | void Otto::oscillateServos(int A[4], int O[4], int T, double phase_diff[4], float cycle=1){ 144 | 145 | for (int i=0; i<4; i++) { 146 | servo[i].SetO(O[i]); 147 | servo[i].SetA(A[i]); 148 | servo[i].SetT(T); 149 | servo[i].SetPh(phase_diff[i]); 150 | } 151 | double ref=millis(); 152 | for (double x=ref; x<=T*cycle+ref; x=millis()){ 153 | for (int i=0; i<4; i++){ 154 | servo[i].refresh(); 155 | } 156 | } 157 | } 158 | 159 | void Otto::_execute(int A[4], int O[4], int T, double phase_diff[4], float steps = 1.0){ 160 | 161 | attachServos(); 162 | if(getRestState()==true){ 163 | setRestState(false); 164 | } 165 | 166 | 167 | int cycles=(int)steps; 168 | 169 | //-- Execute complete cycles 170 | if (cycles >= 1) 171 | for(int i = 0; i < cycles; i++) 172 | oscillateServos(A,O, T, phase_diff); 173 | 174 | //-- Execute the final not complete cycle 175 | oscillateServos(A,O, T, phase_diff,(float)steps-cycles); 176 | } 177 | 178 | /////////////////////////////////////////////////////////////////// 179 | //-- HOME = Otto at rest position -------------------------------// 180 | /////////////////////////////////////////////////////////////////// 181 | void Otto::home(){ 182 | 183 | if(isOttoResting==false){ //Go to rest position only if necessary 184 | 185 | int homes[4]={90, 90, 90, 90}; //All the servos at rest position 186 | _moveServos(500,homes); //Move the servos in half a second 187 | 188 | detachServos(); 189 | isOttoResting=true; 190 | } 191 | } 192 | 193 | bool Otto::getRestState(){ 194 | return isOttoResting; 195 | } 196 | 197 | void Otto::setRestState(bool state){ 198 | 199 | isOttoResting = state; 200 | } 201 | 202 | /////////////////////////////////////////////////////////////////// 203 | //-- PREDETERMINED MOTION SEQUENCES -----------------------------// 204 | /////////////////////////////////////////////////////////////////// 205 | //-- Otto movement: Jump 206 | //-- Parameters: 207 | //-- steps: Number of steps 208 | //-- T: Period 209 | //--------------------------------------------------------- 210 | void Otto::jump(float steps, int T){ 211 | 212 | int up[]={90,90,150,30}; 213 | _moveServos(T,up); 214 | int down[]={90,90,90,90}; 215 | _moveServos(T,down); 216 | } 217 | 218 | //--------------------------------------------------------- 219 | //-- Otto gait: Walking (forward or backward) 220 | //-- Parameters: 221 | //-- * steps: Number of steps 222 | //-- * T : Period 223 | //-- * Dir: Direction: FORWARD / BACKWARD 224 | //--------------------------------------------------------- 225 | void Otto::walk(float steps, int T, int dir){ 226 | //-- Oscillator parameters for walking 227 | //-- Hip sevos are in phase 228 | //-- Feet servos are in phase 229 | //-- Hip and feet are 90 degrees out of phase 230 | //-- -90 : Walk forward 231 | //-- 90 : Walk backward 232 | //-- Feet servos also have the same offset (for tiptoe a little bit) 233 | int A[4]= {30, 30, 20, 20}; 234 | int O[4] = {0, 0, 4, -4}; 235 | double phase_diff[4] = {0, 0, DEG2RAD(dir * -90), DEG2RAD(dir * -90)}; 236 | 237 | //-- Let's oscillate the servos! 238 | _execute(A, O, T, phase_diff, steps); 239 | } 240 | 241 | //--------------------------------------------------------- 242 | //-- Otto gait: Turning (left or right) 243 | //-- Parameters: 244 | //-- * Steps: Number of steps 245 | //-- * T: Period 246 | //-- * Dir: Direction: LEFT / RIGHT 247 | //--------------------------------------------------------- 248 | void Otto::turn(float steps, int T, int dir){ 249 | 250 | //-- Same coordination than for walking (see Otto::walk) 251 | //-- The Amplitudes of the hip's oscillators are not igual 252 | //-- When the right hip servo amplitude is higher, the steps taken by 253 | //-- the right leg are bigger than the left. So, the robot describes an 254 | //-- left arc 255 | int A[4]= {30, 30, 20, 20}; 256 | int O[4] = {0, 0, 4, -4}; 257 | double phase_diff[4] = {0, 0, DEG2RAD(-90), DEG2RAD(-90)}; 258 | 259 | if (dir == LEFT) { 260 | A[0] = 30; //-- Left hip servo 261 | A[1] = 10; //-- Right hip servo 262 | } 263 | else { 264 | A[0] = 10; 265 | A[1] = 30; 266 | } 267 | 268 | //-- Let's oscillate the servos! 269 | _execute(A, O, T, phase_diff, steps); 270 | } 271 | 272 | //--------------------------------------------------------- 273 | //-- Otto gait: Lateral bend 274 | //-- Parameters: 275 | //-- steps: Number of bends 276 | //-- T: Period of one bend 277 | //-- dir: RIGHT=Right bend LEFT=Left bend 278 | //--------------------------------------------------------- 279 | void Otto::bend (int steps, int T, int dir){ 280 | 281 | //Parameters of all the movements. Default: Left bend 282 | int bend1[4]={90, 90, 62, 35}; 283 | int bend2[4]={90, 90, 62, 105}; 284 | int homes[4]={90, 90, 90, 90}; 285 | 286 | //Time of one bend, constrained in order to avoid movements too fast. 287 | //T=max(T, 600); 288 | //Changes in the parameters if right direction is chosen 289 | if(dir==-1) 290 | { 291 | bend1[2]=180-35; 292 | bend1[3]=180-60; //Not 65. Otto is unbalanced 293 | bend2[2]=180-105; 294 | bend2[3]=180-60; 295 | } 296 | 297 | //Time of the bend movement. Fixed parameter to avoid falls 298 | int T2=800; 299 | 300 | //Bend movement 301 | for (int i=0;i 9 ) b = 9; // only maximum of nine characters allowed 573 | } 574 | for(int charNUMBER = 0; charNUMBER 91)) { 576 | if (* s == 32){ 577 | ledmatrix.sendChar (44, charNUMBER, b, scrollspeed); 578 | } 579 | else 580 | { 581 | ledmatrix.sendChar (43, charNUMBER, b, scrollspeed); 582 | } 583 | } 584 | else 585 | { 586 | ledmatrix.sendChar ((* s - 48), charNUMBER, b, scrollspeed); 587 | } 588 | * s++; 589 | } 590 | 591 | } 592 | 593 | /////////////////////////////////////////////////////////////////// 594 | //-- SOUNDS -----------------------------------------------------// 595 | /////////////////////////////////////////////////////////////////// 596 | 597 | void Otto::_tone (float noteFrequency, long noteDuration, int silentDuration){ 598 | 599 | // tone(10,261,500); 600 | // delay(500); 601 | 602 | if(silentDuration==0){silentDuration=1;} 603 | 604 | tone(Otto::pinBuzzer, noteFrequency, noteDuration); 605 | delay(noteDuration); //milliseconds to microseconds 606 | //noTone(PIN_Buzzer); 607 | delay(silentDuration); 608 | } 609 | 610 | void Otto::bendTones (float initFrequency, float finalFrequency, float prop, long noteDuration, int silentDuration){ 611 | 612 | //Examples: 613 | // bendTones (880, 2093, 1.02, 18, 1); 614 | // bendTones (note_A5, note_C7, 1.02, 18, 0); 615 | 616 | if(silentDuration==0){silentDuration=1;} 617 | 618 | if(initFrequency < finalFrequency) 619 | { 620 | for (int i=initFrequency; ifinalFrequency; i=i/prop) { 627 | _tone(i, noteDuration, silentDuration); 628 | } 629 | } 630 | } 631 | 632 | void Otto::sing(int songName){ 633 | switch(songName){ 634 | 635 | case S_connection: 636 | _tone(note_E5,50,30); 637 | _tone(note_E6,55,25); 638 | _tone(note_A6,60,10); 639 | break; 640 | 641 | case S_disconnection: 642 | _tone(note_E5,50,30); 643 | _tone(note_A6,55,25); 644 | _tone(note_E6,50,10); 645 | break; 646 | 647 | case S_buttonPushed: 648 | bendTones (note_E6, note_G6, 1.03, 20, 2); 649 | delay(30); 650 | bendTones (note_E6, note_D7, 1.04, 10, 2); 651 | break; 652 | 653 | case S_mode1: 654 | bendTones (note_E6, note_A6, 1.02, 30, 10); //1318.51 to 1760 655 | break; 656 | 657 | case S_mode2: 658 | bendTones (note_G6, note_D7, 1.03, 30, 10); //1567.98 to 2349.32 659 | break; 660 | 661 | case S_mode3: 662 | _tone(note_E6,50,100); //D6 663 | _tone(note_G6,50,80); //E6 664 | _tone(note_D7,300,0); //G6 665 | break; 666 | 667 | case S_surprise: 668 | bendTones(800, 2150, 1.02, 10, 1); 669 | bendTones(2149, 800, 1.03, 7, 1); 670 | break; 671 | 672 | case S_OhOoh: 673 | bendTones(880, 2000, 1.04, 8, 3); //A5 = 880 674 | delay(200); 675 | 676 | for (int i=880; i<2000; i=i*1.04) { 677 | _tone(note_B5,5,10); 678 | } 679 | break; 680 | 681 | case S_OhOoh2: 682 | bendTones(1880, 3000, 1.03, 8, 3); 683 | delay(200); 684 | 685 | for (int i=1880; i<3000; i=i*1.03) { 686 | _tone(note_C6,10,10); 687 | } 688 | break; 689 | 690 | case S_cuddly: 691 | bendTones(700, 900, 1.03, 16, 4); 692 | bendTones(899, 650, 1.01, 18, 7); 693 | break; 694 | 695 | case S_sleeping: 696 | bendTones(100, 500, 1.04, 10, 10); 697 | delay(500); 698 | bendTones(400, 100, 1.04, 10, 1); 699 | break; 700 | 701 | case S_happy: 702 | bendTones(1500, 2500, 1.05, 20, 8); 703 | bendTones(2499, 1500, 1.05, 25, 8); 704 | break; 705 | 706 | case S_superHappy: 707 | bendTones(2000, 6000, 1.05, 8, 3); 708 | delay(50); 709 | bendTones(5999, 2000, 1.05, 13, 2); 710 | break; 711 | 712 | case S_happy_short: 713 | bendTones(1500, 2000, 1.05, 15, 8); 714 | delay(100); 715 | bendTones(1900, 2500, 1.05, 10, 8); 716 | break; 717 | 718 | case S_sad: 719 | bendTones(880, 669, 1.02, 20, 200); 720 | break; 721 | 722 | case S_confused: 723 | bendTones(1000, 1700, 1.03, 8, 2); 724 | bendTones(1699, 500, 1.04, 8, 3); 725 | bendTones(1000, 1700, 1.05, 9, 10); 726 | break; 727 | 728 | case S_fart1: 729 | bendTones(1600, 3000, 1.02, 2, 15); 730 | break; 731 | 732 | case S_fart2: 733 | bendTones(2000, 6000, 1.02, 2, 20); 734 | break; 735 | 736 | case S_fart3: 737 | bendTones(1600, 4000, 1.02, 2, 20); 738 | bendTones(4000, 3000, 1.02, 2, 20); 739 | break; 740 | 741 | } 742 | } 743 | 744 | /////////////////////////////////////////////////////////////////// 745 | //-- GESTURES ---------------------------------------------------// 746 | /////////////////////////////////////////////////////////////////// 747 | 748 | void Otto::playGesture(int gesture){ 749 | int gesturePOSITION[4]; 750 | 751 | switch(gesture){ 752 | 753 | case OttoHappy: 754 | _tone(note_E5,50,30); 755 | putMouth(smile); 756 | sing(S_happy_short); 757 | swing(1,800,20); 758 | sing(S_happy_short); 759 | 760 | home(); 761 | putMouth(happyOpen); 762 | break; 763 | 764 | 765 | case OttoSuperHappy: 766 | putMouth(happyOpen); 767 | sing(S_happy); 768 | putMouth(happyClosed); 769 | tiptoeSwing(1,500,20); 770 | putMouth(happyOpen); 771 | sing(S_superHappy); 772 | putMouth(happyClosed); 773 | tiptoeSwing(1,500,20); 774 | 775 | home(); 776 | putMouth(happyOpen); 777 | break; 778 | 779 | 780 | case OttoSad: 781 | putMouth(sad); 782 | gesturePOSITION[0] = 110;//int sadPos[6]= {110, 70, 20, 160}; 783 | gesturePOSITION[1] = 70; 784 | gesturePOSITION[2] = 20; 785 | gesturePOSITION[3] = 160; 786 | _moveServos(700, gesturePOSITION); 787 | bendTones(880, 830, 1.02, 20, 200); 788 | putMouth(sadClosed); 789 | bendTones(830, 790, 1.02, 20, 200); 790 | putMouth(sadOpen); 791 | bendTones(790, 740, 1.02, 20, 200); 792 | putMouth(sadClosed); 793 | bendTones(740, 700, 1.02, 20, 200); 794 | putMouth(sadOpen); 795 | bendTones(700, 669, 1.02, 20, 200); 796 | putMouth(sad); 797 | delay(500); 798 | 799 | home(); 800 | delay(300); 801 | putMouth(happyOpen); 802 | break; 803 | 804 | 805 | case OttoSleeping: 806 | gesturePOSITION[0] = 100;//int bedPos[6]= {100, 80, 60, 120}; 807 | gesturePOSITION[1] = 80; 808 | gesturePOSITION[2] = 60; 809 | gesturePOSITION[3] = 120; 810 | _moveServos(700, gesturePOSITION); 811 | for(int i=0; i<4;i++){ 812 | putAnimationMouth(dreamMouth,0); 813 | bendTones (100, 200, 1.04, 10, 10); 814 | putAnimationMouth(dreamMouth,1); 815 | bendTones (200, 300, 1.04, 10, 10); 816 | putAnimationMouth(dreamMouth,2); 817 | bendTones (300, 500, 1.04, 10, 10); 818 | delay(500); 819 | putAnimationMouth(dreamMouth,1); 820 | bendTones (400, 250, 1.04, 10, 1); 821 | putAnimationMouth(dreamMouth,0); 822 | bendTones (250, 100, 1.04, 10, 1); 823 | delay(500); 824 | } 825 | 826 | putMouth(lineMouth); 827 | sing(S_cuddly); 828 | 829 | home(); 830 | putMouth(happyOpen); 831 | break; 832 | 833 | 834 | case OttoFart: 835 | gesturePOSITION[0] = 90;// int fartPos_1[6]= {90, 90, 145, 122}; 836 | gesturePOSITION[1] = 90; 837 | gesturePOSITION[2] = 145; 838 | gesturePOSITION[3] = 122; 839 | _moveServos(500,gesturePOSITION); 840 | delay(300); 841 | putMouth(lineMouth); 842 | sing(S_fart1); 843 | putMouth(tongueOut); 844 | delay(250); 845 | gesturePOSITION[0] = 90;// int fartPos_2[6]= {90, 90, 80, 122}; 846 | gesturePOSITION[1] = 90; 847 | gesturePOSITION[2] = 80; 848 | gesturePOSITION[3] = 122; 849 | _moveServos(500,gesturePOSITION); 850 | delay(300); 851 | putMouth(lineMouth); 852 | sing(S_fart2); 853 | putMouth(tongueOut); 854 | delay(250); 855 | gesturePOSITION[0] = 90;// int fartPos_3[6]= {90, 90, 145, 80}; 856 | gesturePOSITION[1] = 90; 857 | gesturePOSITION[2] = 145; 858 | gesturePOSITION[3] = 80; 859 | _moveServos(500,gesturePOSITION); 860 | delay(300); 861 | putMouth(lineMouth); 862 | sing(S_fart3); 863 | putMouth(tongueOut); 864 | delay(300); 865 | 866 | home(); 867 | delay(500); 868 | putMouth(happyOpen); 869 | break; 870 | 871 | 872 | case OttoConfused: 873 | gesturePOSITION[0] = 110;//int confusedPos[6]= {110, 70, 90, 90}; 874 | gesturePOSITION[1] = 70; 875 | gesturePOSITION[2] = 90; 876 | gesturePOSITION[3] = 90; 877 | _moveServos(300, gesturePOSITION); 878 | putMouth(confused); 879 | sing(S_confused); 880 | delay(500); 881 | 882 | home(); 883 | putMouth(happyOpen); 884 | break; 885 | 886 | 887 | case OttoLove: 888 | putMouth(heart); 889 | sing(S_cuddly); 890 | crusaito(2,1500,15,1); 891 | 892 | home(); 893 | sing(S_happy_short); 894 | putMouth(happyOpen); 895 | break; 896 | 897 | 898 | case OttoAngry: 899 | gesturePOSITION[0] = 90;//int angryPos[6]= {90, 90, 70, 110}; 900 | gesturePOSITION[1] = 90; 901 | gesturePOSITION[2] = 70; 902 | gesturePOSITION[3] = 110; 903 | _moveServos(300, gesturePOSITION); 904 | putMouth(angry); 905 | 906 | _tone(note_A5,100,30); 907 | bendTones(note_A5, note_D6, 1.02, 7, 4); 908 | bendTones(note_D6, note_G6, 1.02, 10, 1); 909 | bendTones(note_G6, note_A5, 1.02, 10, 1); 910 | delay(15); 911 | bendTones(note_A5, note_E5, 1.02, 20, 4); 912 | delay(400); 913 | gesturePOSITION[0] = 110;//int headLeft[6]= {110, 110, 90, 90}; 914 | gesturePOSITION[1] = 110; 915 | gesturePOSITION[2] = 90; 916 | gesturePOSITION[3] = 90; 917 | _moveServos(200, gesturePOSITION); 918 | bendTones(note_A5, note_D6, 1.02, 20, 4); 919 | gesturePOSITION[0] = 70;//int headRight[6]= {70, 70, 90, 90}; 920 | gesturePOSITION[1] = 70; 921 | gesturePOSITION[2] = 90; 922 | gesturePOSITION[3] = 90; 923 | _moveServos(200, gesturePOSITION); 924 | bendTones(note_A5, note_E5, 1.02, 20, 4); 925 | 926 | home(); 927 | putMouth(happyOpen); 928 | break; 929 | 930 | 931 | case OttoFretful: 932 | putMouth(angry); 933 | bendTones(note_A5, note_D6, 1.02, 20, 4); 934 | bendTones(note_A5, note_E5, 1.02, 20, 4); 935 | delay(300); 936 | putMouth(lineMouth); 937 | 938 | for(int i=0; i<4; i++){ 939 | gesturePOSITION[0] = 90;//int fretfulPos[6]= {90, 90, 90, 110}; 940 | gesturePOSITION[1] = 90; 941 | gesturePOSITION[2] = 90; 942 | gesturePOSITION[3] = 110; 943 | _moveServos(100, gesturePOSITION); 944 | home(); 945 | } 946 | 947 | putMouth(angry); 948 | delay(500); 949 | 950 | home(); 951 | putMouth(happyOpen); 952 | break; 953 | 954 | 955 | case OttoMagic: 956 | 957 | //Initial note frecuency = 400 958 | //Final note frecuency = 1000 959 | 960 | // Reproduce the animation four times 961 | for(int i = 0; i<4; i++){ 962 | 963 | int noteM = 400; 964 | 965 | for(int index = 0; index<6; index++){ 966 | putAnimationMouth(adivinawi,index); 967 | bendTones(noteM, noteM+100, 1.04, 10, 10); //400 -> 1000 968 | noteM+=100; 969 | } 970 | 971 | clearMouth(); 972 | bendTones(noteM-100, noteM+100, 1.04, 10, 10); //900 -> 1100 973 | 974 | for(int index = 0; index<6; index++){ 975 | putAnimationMouth(adivinawi,index); 976 | bendTones(noteM, noteM+100, 1.04, 10, 10); //1000 -> 400 977 | noteM-=100; 978 | } 979 | } 980 | 981 | delay(300); 982 | putMouth(happyOpen); 983 | break; 984 | 985 | 986 | case OttoWave: 987 | 988 | // Reproduce the animation four times 989 | for(int i = 0; i<2; i++){ 990 | 991 | int noteW = 500; 992 | 993 | for(int index = 0; index<10; index++){ 994 | putAnimationMouth(wave,index); 995 | bendTones(noteW, noteW+100, 1.02, 10, 10); 996 | noteW+=101; 997 | } 998 | for(int index = 0; index<10; index++){ 999 | putAnimationMouth(wave,index); 1000 | bendTones(noteW, noteW+100, 1.02, 10, 10); 1001 | noteW+=101; 1002 | } 1003 | for(int index = 0; index<10; index++){ 1004 | putAnimationMouth(wave,index); 1005 | bendTones(noteW, noteW-100, 1.02, 10, 10); 1006 | noteW-=101; 1007 | } 1008 | for(int index = 0; index<10; index++){ 1009 | putAnimationMouth(wave,index); 1010 | bendTones(noteW, noteW-100, 1.02, 10, 10); 1011 | noteW-=101; 1012 | } 1013 | } 1014 | 1015 | clearMouth(); 1016 | delay(100); 1017 | putMouth(happyOpen); 1018 | break; 1019 | 1020 | case OttoVictory: 1021 | 1022 | putMouth(smallSurprise); 1023 | //final pos = {90,90,150,30} 1024 | for (int i = 0; i < 60; ++i){ 1025 | int pos[]={90,90,90+i,90-i}; 1026 | _moveServos(10,pos); 1027 | _tone(1600+i*20,15,1); 1028 | } 1029 | 1030 | putMouth(bigSurprise); 1031 | //final pos = {90,90,90,90} 1032 | for (int i = 0; i < 60; ++i){ 1033 | int pos[]={90,90,150-i,30+i}; 1034 | _moveServos(10,pos); 1035 | _tone(2800+i*20,15,1); 1036 | } 1037 | 1038 | putMouth(happyOpen); 1039 | //SUPER HAPPY 1040 | //----- 1041 | tiptoeSwing(1,500,20); 1042 | sing(S_superHappy); 1043 | putMouth(happyClosed); 1044 | tiptoeSwing(1,500,20); 1045 | //----- 1046 | 1047 | home(); 1048 | clearMouth(); 1049 | putMouth(happyOpen); 1050 | 1051 | break; 1052 | 1053 | case OttoFail: 1054 | putMouth(sadOpen); 1055 | gesturePOSITION[0] = 90;//int bendPos_1[6]= {90, 90, 70, 35}; 1056 | gesturePOSITION[1] = 90; 1057 | gesturePOSITION[2] = 70; 1058 | gesturePOSITION[3] = 35; 1059 | _moveServos(300,gesturePOSITION); 1060 | _tone(900,200,1); 1061 | putMouth(sadClosed); 1062 | gesturePOSITION[0] = 90;//int bendPos_2[6]= {90, 90, 55, 35}; 1063 | gesturePOSITION[1] = 90; 1064 | gesturePOSITION[2] = 55; 1065 | gesturePOSITION[3] = 35; 1066 | _moveServos(300,gesturePOSITION); 1067 | _tone(600,200,1); 1068 | putMouth(confused); 1069 | gesturePOSITION[0] = 90;//int bendPos_3[6]= {90, 90, 42, 35}; 1070 | gesturePOSITION[1] = 90; 1071 | gesturePOSITION[2] = 42; 1072 | gesturePOSITION[3] = 35; 1073 | _moveServos(300,gesturePOSITION); 1074 | _tone(300,200,1); 1075 | gesturePOSITION[0] = 90;//int bendPos_4[6]= {90, 90, 34, 35}; 1076 | gesturePOSITION[1] = 90; 1077 | gesturePOSITION[2] = 34; 1078 | gesturePOSITION[3] = 35; 1079 | _moveServos(300,gesturePOSITION); 1080 | putMouth(xMouth); 1081 | 1082 | detachServos(); 1083 | _tone(150,2200,1); 1084 | 1085 | delay(600); 1086 | clearMouth(); 1087 | putMouth(happyOpen); 1088 | home(); 1089 | 1090 | break; 1091 | 1092 | } 1093 | } 1094 | 1095 | void Otto::enableServoLimit(int diff_limit) { 1096 | for (int i = 0; i < 4; i++) { 1097 | servo[i].SetLimiter(diff_limit); 1098 | } 1099 | } 1100 | 1101 | void Otto::disableServoLimit() { 1102 | for (int i = 0; i < 4; i++) { 1103 | servo[i].DisableLimiter(); 1104 | } 1105 | } 1106 | -------------------------------------------------------------------------------- /src/Otto.h: -------------------------------------------------------------------------------- 1 | #ifndef Otto_h 2 | #define Otto_h 3 | 4 | #ifdef ARDUINO_ARCH_ESP32 5 | #include 6 | #else 7 | #include 8 | #endif 9 | #include 10 | #include 11 | #include "Otto_sounds.h" 12 | #include "Otto_gestures.h" 13 | #include "Otto_mouths.h" 14 | #include "Otto_matrix.h" 15 | 16 | //-- Constants 17 | #define FORWARD 1 18 | #define BACKWARD -1 19 | #define LEFT 1 20 | #define RIGHT -1 21 | #define SMALL 5 22 | #define MEDIUM 15 23 | #define BIG 30 24 | 25 | // -- Servo delta limit default. degree / sec 26 | #define SERVO_LIMIT_DEFAULT 240 27 | 28 | class Otto 29 | { 30 | public: 31 | 32 | //-- Otto initialization 33 | void init(int YL, int YR, int RL, int RR, bool load_calibration, int Buzzer); 34 | //-- Attach & detach functions 35 | void attachServos(); 36 | void detachServos(); 37 | 38 | //-- Oscillator Trims 39 | void setTrims(int YL, int YR, int RL, int RR); 40 | void saveTrimsOnEEPROM(); 41 | 42 | //-- Predetermined Motion Functions 43 | void _moveServos(int time, int servo_target[]); 44 | void _moveSingle(int position,int servo_number); 45 | void oscillateServos(int A[4], int O[4], int T, double phase_diff[4], float cycle); 46 | 47 | //-- HOME = Otto at rest position 48 | void home(); 49 | bool getRestState(); 50 | void setRestState(bool state); 51 | 52 | //-- Predetermined Motion Functions 53 | void jump(float steps=1, int T = 2000); 54 | 55 | void walk(float steps=4, int T=1000, int dir = FORWARD); 56 | void turn(float steps=4, int T=2000, int dir = LEFT); 57 | void bend (int steps=1, int T=1400, int dir=LEFT); 58 | void shakeLeg (int steps=1, int T = 2000, int dir=RIGHT); 59 | 60 | void updown(float steps=1, int T=1000, int h = 20); 61 | void swing(float steps=1, int T=1000, int h=20); 62 | void tiptoeSwing(float steps=1, int T=900, int h=20); 63 | void jitter(float steps=1, int T=500, int h=20); 64 | void ascendingTurn(float steps=1, int T=900, int h=20); 65 | 66 | void moonwalker(float steps=1, int T=900, int h=20, int dir=LEFT); 67 | void crusaito(float steps=1, int T=900, int h=20, int dir=FORWARD); 68 | void flapping(float steps=1, int T=1000, int h=20, int dir=FORWARD); 69 | 70 | //-- Mouth & Animations 71 | void putMouth(unsigned long int mouth, bool predefined = true); 72 | void putAnimationMouth(unsigned long int anim, int index); 73 | void clearMouth(); 74 | 75 | //-- Sounds 76 | void _tone (float noteFrequency, long noteDuration, int silentDuration); 77 | void bendTones (float initFrequency, float finalFrequency, float prop, long noteDuration, int silentDuration); 78 | void sing(int songName); 79 | 80 | //-- Gestures 81 | void playGesture(int gesture); 82 | void initMATRIX(int DIN, int CS, int CLK, int rotate); 83 | void matrixIntensity(int intensity); 84 | void setLed(byte X, byte Y, byte value); 85 | void writeText (const char * s, byte scrollspeed); 86 | 87 | // -- Servo limiter 88 | void enableServoLimit(int speed_limit_degree_per_sec = SERVO_LIMIT_DEFAULT); 89 | void disableServoLimit(); 90 | 91 | private: 92 | 93 | Oscillator servo[4]; 94 | Otto_Matrix ledmatrix; 95 | int servo_pins[4]; 96 | int servo_trim[4]; 97 | 98 | int pinBuzzer; 99 | 100 | unsigned long final_time; 101 | unsigned long partial_time; 102 | float increment[4]; 103 | 104 | bool isOttoResting; 105 | 106 | unsigned long int getMouthShape(int number); 107 | unsigned long int getAnimShape(int anim, int index); 108 | void _execute(int A[4], int O[4], int T, double phase_diff[4], float steps); 109 | 110 | }; 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /src/Otto_gestures.h: -------------------------------------------------------------------------------- 1 | #ifndef Otto_gestures_h 2 | #define Otto_gestures_h 3 | 4 | //*********************************************************************************** 5 | //*********************************GESTURE DEFINES*********************************** 6 | //*********************************************************************************** 7 | 8 | #define OttoHappy 0 9 | #define OttoSuperHappy 1 10 | #define OttoSad 2 11 | #define OttoSleeping 3 12 | #define OttoFart 4 13 | #define OttoConfused 5 14 | #define OttoLove 6 15 | #define OttoAngry 7 16 | #define OttoFretful 8 17 | #define OttoMagic 9 18 | #define OttoWave 10 19 | #define OttoVictory 11 20 | #define OttoFail 12 21 | 22 | //*** MOUTH ANIMATIONS*** 23 | #define littleUuh 0 24 | #define dreamMouth 1 25 | #define adivinawi 2 26 | #define wave 3 27 | 28 | 29 | //*** MOUTH ANIMATIONS*** 30 | #define littleUuh 0 31 | #define dreamMouth 1 32 | #define adivinawi 2 33 | #define wave 3 34 | #define otto 4 // Wordt niet gebruikt. 35 | 36 | typedef struct 37 | { 38 | uint8_t Character[1]; 39 | uint8_t data[6]; 40 | } 41 | LED_Matrix_Font_6x8_TypeDef; 42 | 43 | //Terminal 44 | const LED_Matrix_Font_6x8_TypeDef Character_font_6x8[] PROGMEM = 45 | { 46 | 47 | '0', 0x00,0x7C,0x82,0x82,0x7C,0x00, 48 | '1', 0x00,0x42,0xFE,0x02,0x00,0x00, 49 | '2', 0x00,0x46,0x8A,0x92,0x62,0x00, 50 | '3', 0x00,0x44,0x92,0x92,0x6C,0x00, 51 | '4', 0x00,0x1C,0x64,0xFE,0x04,0x00, 52 | '5', 0x00,0xF2,0x92,0x92,0x8C,0x00, 53 | '6', 0x00,0x7C,0x92,0x92,0x4C,0x00, 54 | '7', 0x00,0xC0,0x8E,0x90,0xE0,0x00, 55 | '8', 0x00,0x6C,0x92,0x92,0x6C,0x00, 56 | '9', 0x00,0x64,0x92,0x92,0x7C,0x00, 57 | ':', 0x00,0x00,0x14,0x00,0x00,0x00, 58 | ';', 0x00,0x02,0x24,0x00,0x00,0x00, 59 | '<', 0x00,0x10,0x28,0x44,0x82,0x00, 60 | '=', 0x00,0x28,0x28,0x28,0x28,0x00, 61 | '>', 0x00,0x82,0x44,0x28,0x10,0x00, 62 | '?', 0x00,0x20,0x4a,0x30,0x00,0x00, // 63 | '@', 0x00,0x00,0x00,0x00,0x00,0x00, 64 | 'A', 0x00,0x7E,0x88,0x88,0x7E,0x00, 65 | 'B', 0x00,0xFE,0x92,0x92,0x6C,0x00, 66 | 'C', 0x00,0x7C,0x82,0x82,0x44,0x00, 67 | 'D', 0x00,0xFE,0x82,0x82,0x7C,0x00, 68 | 'E', 0x00,0xFE,0x92,0x92,0x82,0x00, 69 | 'F', 0x00,0xFE,0x90,0x90,0x80,0x00, 70 | 'G', 0x00,0x7C,0x82,0x92,0x5C,0x00, 71 | 'H', 0x00,0xFE,0x10,0x10,0xFE,0x00, 72 | 'I', 0x00,0x82,0xFE,0x82,0x00,0x00, 73 | 'J', 0x00,0x0C,0x02,0x02,0xFC,0x00, 74 | 'K', 0x00,0xFE,0x10,0x28,0xC6,0x00, 75 | 'L', 0x00,0xFE,0x02,0x02,0x02,0x00, 76 | 'M', 0x00,0xFE,0x40,0x30,0x40,0xFE, 77 | 'N', 0x00,0xFE,0x40,0x30,0x08,0xFE, 78 | 'O', 0x00,0x7C,0x82,0x82,0x82,0x7C, 79 | 'P', 0x00,0xFE,0x90,0x90,0x60,0x00, 80 | 'Q', 0x00,0x7C,0x82,0x8A,0x84,0x7A, 81 | 'R', 0x00,0xFE,0x98,0x94,0x62,0x00, 82 | 'S', 0x00,0x64,0x92,0x92,0x4C,0x00, 83 | 'T', 0x00,0x80,0xFE,0x80,0x80,0x00, 84 | 'U', 0x00,0xFC,0x02,0x02,0xFC,0x00, 85 | 'V', 0x00,0xF0,0x0C,0x02,0x0C,0xF0, 86 | 'W', 0x00,0xFE,0x04,0x38,0x04,0xFE, 87 | 'X', 0x00,0xC6,0x38,0x38,0xC6,0x00, 88 | 'Y', 0xC0,0x20,0x1E,0x20,0xC0,0x00, 89 | 'Z', 0x00,0x86,0x9A,0xB2,0xC2,0x00, 90 | '!', 0x00,0x00,0x7a,0x00,0x00,0x00, 91 | ' ', 0x00,0x00,0x00,0x00,0x00,0x00, 92 | 93 | }; 94 | 95 | 96 | const unsigned long int Gesturetable[4][10] PROGMEM = { 97 | { 98 | 0b00000000000000001100001100000000, // littleUuh_code1 99 | 0b00000000000000000110000110000000, // littleUuh_code2 100 | 0b00000000000000000011000011000000, // littleUuh_code3 101 | 0b00000000000000000110000110000000, // littleUuh_code4 102 | 0b00000000000000001100001100000000, // littleUuh_code5 103 | 0b00000000000000011000011000000000, // littleUuh_code6 104 | 0b00000000000000110000110000000000, // littleUuh_code7 105 | 0b00000000000000011000011000000000 106 | } // littleUuh_code8 107 | , 108 | { 109 | 0b00000000000000000000110000110000, // dreamMouth_code1 110 | 0b00000000000000010000101000010000, // dreamMouth_code2 111 | 0b00000000011000100100100100011000, // dreamMouth_code3 112 | 0b00000000000000010000101000010000 // dreamMouth_code4 113 | } 114 | , 115 | { 116 | 0b00100001000000000000000000100001, // adivinawi_code1 117 | 0b00010010100001000000100001010010, // adivinawi_code2 118 | 0b00001100010010100001010010001100, // adivinawi_code3 119 | 0b00000000001100010010001100000000, // adivinawi_code4 120 | 0b00000000000000001100000000000000, // adivinawi_code5 121 | 0b00000000000000000000000000000000 // adivinawi_code6 122 | } 123 | , 124 | { 125 | 0b00001100010010100001000000000000, // wave_code1 126 | 0b00000110001001010000100000000000, // wave_code2 127 | 0b00000011000100001000010000100000, // wave_code3 128 | 0b00000001000010000100001000110000, // wave_code4 129 | 0b00000000000001000010100100011000, // wave_code5 130 | 0b00000000000000100001010010001100, // wave_code6 131 | 0b00000000100000010000001001000110, // wave_code7 132 | 0b00100000010000001000000100000011, // wave_code8 133 | 0b00110000001000000100000010000001, // wave_code9 134 | 0b00011000100100000010000001000000 // wave_code10 135 | } 136 | }; 137 | 138 | //"PROGMEM_readAnything.h" FROM http://www.gammon.com.au/progmem 139 | // modified for OTTO use by Paul Van De Veen along with all PROGMEM mouths and gestures 140 | #include // for type definitions 141 | 142 | template void PROGMEM_readAnything (const T * sce, T& dest) 143 | { 144 | memcpy_P (&dest, sce, sizeof (T)); 145 | } 146 | 147 | template T PROGMEM_getAnything (const T * sce) 148 | { 149 | static T temp; 150 | memcpy_P (&temp, sce, sizeof (T)); 151 | return temp; 152 | } 153 | 154 | #endif 155 | -------------------------------------------------------------------------------- /src/Otto_matrix.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * MaxMatrix 3 | * Version 1.0 Feb 2013 4 | * Copyright 2013 Oscar Kin-Chung Au 5 | * Adapted for OTTO version 9 use 6 | */ 7 | 8 | 9 | #include "Arduino.h" 10 | #include "Otto_matrix.h" 11 | 12 | Otto_Matrix::Otto_Matrix() 13 | { 14 | //data = _data; 15 | //load = _load; 16 | //clock = _clock; 17 | //num = _num; 18 | } 19 | 20 | void Otto_Matrix::init(byte _data, byte _load, byte _clock, byte _num, int _rotation) 21 | { 22 | data = _data; 23 | load = _load; 24 | clock = _clock; 25 | num = _num; 26 | rotation = _rotation; 27 | if ((rotation > 4) || (rotation == 0)) rotation = 1; // we have to have number between 1 and 4 28 | for (int i=0; i<8; i++) 29 | buffer[i] = 0; 30 | 31 | for (int i=0; i<80; i++) 32 | CHARbuffer[i] = 0; 33 | 34 | #if defined(ESP32) 35 | SPI.begin ( clock, -1, data, load); 36 | SPI.setDataMode(SPI_MODE0); 37 | SPI.setClockDivider(SPI_CLOCK_DIV128); 38 | SPI.setHwCs(true); 39 | #else 40 | pinMode(data, OUTPUT); 41 | pinMode(clock, OUTPUT); 42 | pinMode(load, OUTPUT); 43 | digitalWrite(clock, HIGH); 44 | #endif 45 | 46 | setCommand(max7219_reg_scanLimit, 0x07); 47 | setCommand(max7219_reg_decodeMode, 0x00); // using an led matrix (not digits) 48 | setCommand(max7219_reg_shutdown, 0x01); // not in shutdown mode 49 | setCommand(max7219_reg_displayTest, 0x00); // no display test 50 | 51 | // empty registers, turn all LEDs off 52 | clearMatrix(); 53 | 54 | setIntensity(0x0f); // the first 0x0f is the value you can set 55 | } 56 | 57 | void Otto_Matrix::setIntensity(byte intensity) 58 | { 59 | setCommand(max7219_reg_intensity, intensity); 60 | } 61 | 62 | void Otto_Matrix::clearMatrix() 63 | { 64 | for (int i=0; i<8; i++) 65 | setColumnAll(i,0); 66 | 67 | for (int i=0; i<8; i++) 68 | buffer[i] = 0; 69 | 70 | for (int i=0; i<80; i++) 71 | CHARbuffer[i] = 0; 72 | } 73 | 74 | void Otto_Matrix::setCommand(byte command, byte value) 75 | { 76 | #if defined(ESP32) 77 | SPI.transfer16(command << 8 | value); 78 | #else 79 | digitalWrite(load, LOW); 80 | for (int i=0; i> r*6+c))); 194 | } 195 | } 196 | } 197 | if (rotation == 2) { 198 | for (int r=0; r<5;r++){ 199 | for (int c=0; c<6; c++){ 200 | //setDot(6-c,7-r,(1L & (value >> r*6+c))); 201 | setDot(1+c,r, (1L & (value >> r*6+c))); 202 | } 203 | } 204 | } 205 | if (rotation == 3) { 206 | for (int r=0; r<5;r++){ 207 | for (int c=0; c<6; c++){ 208 | //setDot(6-c,7-r,(1L & (value >> r*6+c))); 209 | setDot(r,6-c, (1L & (value >> r*6+c))); 210 | } 211 | } 212 | } 213 | if (rotation == 4) { 214 | for (int r=0; r<5;r++){ 215 | for (int c=0; c<6; c++){ 216 | //setDot(6-c,7-r,(1L & (value >> r*6+c))); 217 | setDot(7-r,1+c, (1L & (value >> r*6+c))); 218 | } 219 | } 220 | } 221 | } 222 | 223 | void Otto_Matrix::sendChar (const byte data, byte pos, byte number, byte scrollspeed){ 224 | if (scrollspeed < 50 ) scrollspeed = 50; 225 | if (scrollspeed > 150 ) scrollspeed = 150; 226 | int charPos; 227 | charPos = pos * 8; 228 | //Serial.print ("sendchar "); 229 | //Serial.print (pos); 230 | //Serial.print (" - "); 231 | //Serial.print (number); 232 | //Serial.print (" - "); 233 | //Serial.print (charPos); 234 | //Serial.print (" - "); 235 | //Serial.println (data); 236 | //we need to add 8 for each character 237 | CHARbuffer[0 + charPos] = 0; 238 | CHARbuffer[1 + charPos] = pgm_read_byte(&Character_font_6x8[data].data[0]); 239 | CHARbuffer[2 + charPos] = pgm_read_byte(&Character_font_6x8[data].data[1]); 240 | CHARbuffer[3 + charPos] = pgm_read_byte(&Character_font_6x8[data].data[2]); 241 | CHARbuffer[4 + charPos] = pgm_read_byte(&Character_font_6x8[data].data[3]); 242 | CHARbuffer[5 + charPos] = pgm_read_byte(&Character_font_6x8[data].data[4]); 243 | CHARbuffer[6 + charPos] = pgm_read_byte(&Character_font_6x8[data].data[5]); 244 | CHARbuffer[7 + charPos] = 0; 245 | 246 | if (number == (pos + 1)){ // last character so display the total text 247 | // we need to display first character and scroll left until each charater is shown. 248 | for (int c=0; c<8;c++){ // show first character 249 | byte value = CHARbuffer[c]; 250 | for (int r=0; r<8; r++){ 251 | if (rotation == 1) { 252 | setDot(c,7-r,(0b00000001 & (value >> r)));// 253 | } 254 | if (rotation == 2) { 255 | setDot(7-c,r,(0b00000001 & (value >> r)));// 256 | } 257 | if (rotation == 3) { 258 | //setDot(r,c,(1));// top LH corner 259 | setDot(r,c,(0b00000001 & (value >> r)));// 260 | } 261 | if (rotation == 4) { 262 | setDot(7-r,7-c,(0b00000001 & (value >> r)));// 263 | } 264 | } 265 | } 266 | delay(500); // show first digit for longer 267 | for (int i=0; i<((number*8)-1); i++){ // shift buffer the correct number of characters (8 lines per character) 268 | CHARbuffer[i] = CHARbuffer[i+1]; 269 | for (int c=0; c<8;c++){ // 270 | byte value = CHARbuffer[(1+c)+i]; 271 | for (int r=0; r<8; r++){ 272 | if (rotation == 1) { 273 | setDot(c,7-r,(0b00000001 & (value >> r)));// 274 | } 275 | if (rotation == 2) { 276 | setDot(7-c,r,(0b00000001 & (value >> r)));// 277 | } 278 | if (rotation == 3) { 279 | setDot(r,c,(0b00000001 & (value >> r)));// 280 | } 281 | if (rotation == 4) { 282 | setDot(7-r,7-c,(0b00000001 & (value >> r)));// 283 | } 284 | } 285 | } 286 | delay(scrollspeed);// this sets the scroll speed 287 | 288 | } 289 | clearMatrix(); 290 | } 291 | } 292 | 293 | 294 | -------------------------------------------------------------------------------- /src/Otto_matrix.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MaxMatrix 3 | * Version 1.0 Feb 2013 4 | * Copyright 2013 Oscar Kin-Chung Au 5 | * Adapted for OTTO version 9 use 6 | */ 7 | 8 | #ifndef _Otto_matrix_H_ 9 | #define _Otto_matrix_H_ 10 | 11 | #include "Arduino.h" 12 | #include "Otto_gestures.h" 13 | 14 | #if defined(ESP32) 15 | # include 16 | #endif 17 | 18 | #define max7219_reg_noop 0x00 19 | #define max7219_reg_digit0 0x01 20 | #define max7219_reg_digit1 0x02 21 | #define max7219_reg_digit2 0x03 22 | #define max7219_reg_digit3 0x04 23 | #define max7219_reg_digit4 0x05 24 | #define max7219_reg_digit5 0x06 25 | #define max7219_reg_digit6 0x07 26 | #define max7219_reg_digit7 0x08 27 | #define max7219_reg_decodeMode 0x09 28 | #define max7219_reg_intensity 0x0a 29 | #define max7219_reg_scanLimit 0x0b 30 | #define max7219_reg_shutdown 0x0c 31 | #define max7219_reg_displayTest 0x0f 32 | 33 | class Otto_Matrix 34 | { 35 | private: 36 | byte data; 37 | byte load; 38 | byte clock; 39 | byte num; 40 | byte buffer[8]; 41 | byte CHARbuffer[80]; 42 | int rotation; 43 | void reload(); 44 | char rotation2; 45 | 46 | public: 47 | Otto_Matrix(); 48 | 49 | void init(byte data, byte load, byte clock, byte num, int rotation); 50 | void clearMatrix(); 51 | void setCommand(byte command, byte value); 52 | void setIntensity(byte intensity); 53 | void setColumn(byte col, byte value); 54 | void setColumnAll(byte col, byte value); 55 | void setDot(byte col, byte row, byte value); 56 | void writeFull(unsigned long value); 57 | void sendChar ( const byte data, byte pos, byte number, byte scrollspeed); 58 | }; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/Otto_mouths.h: -------------------------------------------------------------------------------- 1 | #ifndef Otto_mouths_h 2 | #define Otto_mouths_h 3 | 4 | 5 | //*********************************************************************************** 6 | //*********************************MOUTHS DEFINES************************************ 7 | //*********************************************************************************** 8 | const int NUMBER_OF_ELEMENTS = 31; 9 | const unsigned long int Mouthtable[NUMBER_OF_ELEMENTS] PROGMEM = { 10 | 0b00001100010010010010010010001100, //zero_code 11 | 0b00000100001100000100000100001110, //one_code 12 | 0b00001100010010000100001000011110, //two_code 13 | 0b00001100010010000100010010001100, //three_code 14 | 0b00010010010010011110000010000010, //four_code 15 | 0b00011110010000011100000010011100, //five_code 16 | 0b00000100001000011100010010001100, //six_code 17 | 0b00011110000010000100001000010000, //seven_code 18 | 0b00001100010010001100010010001100, //eight_code 19 | 0b00001100010010001110000010001110, //nine_code 20 | 0b00000000100001010010001100000000, //smile_code 21 | 0b00000000111111010010001100000000, //happyOpen_code 22 | 0b00000000111111011110000000000000, //happyClosed_code 23 | 0b00010010101101100001010010001100, //heart_code 24 | 0b00001100010010100001010010001100, //bigSurprise_code 25 | 0b00000000000000001100001100000000, //smallSurprise_code 26 | 0b00111111001001001001000110000000, //tongueOut_code 27 | 0b00111111101101101101010010000000, //vamp1_code 28 | 0b00111111101101010010000000000000, //vamp2_code 29 | 0b00000000000000111111000000000000, //lineMouth_code 30 | 0b00000000001000010101100010000000, //confused_code 31 | 0b00100000010000001000000100000010, //diagonal_code 32 | 0b00000000001100010010100001000000, //sad_code 33 | 0b00000000001100010010111111000000, //sadOpen_code 34 | 0b00000000001100011110110011000000, //sadClosed_code 35 | 0b00000001000010010100001000000000, //okMouth_code 36 | 0b00100001010010001100010010100001, //xMouth_code 37 | 0b00001100010010000100000100000100, //interrogation_code 38 | 0b00000100001000011100001000010000, //thunder_code 39 | 0b00000000100001101101010010000000, //culito_code 40 | 0b00000000011110100001100001000000 //angry_code 41 | } ; 42 | 43 | //Mouths sorted by numbers, and after, by happy to sad mouths 44 | #define zero 0 45 | #define one 1 46 | #define two 2 47 | #define three 3 48 | #define four 4 49 | #define five 5 50 | #define six 6 51 | #define seven 7 52 | #define eight 8 53 | #define nine 9 54 | #define smile 10 55 | #define happyOpen 11 56 | #define happyClosed 12 57 | #define heart 13 58 | #define bigSurprise 14 59 | #define smallSurprise 15 60 | #define tongueOut 16 61 | #define vamp1 17 62 | #define vamp2 18 63 | #define lineMouth 19 64 | #define confused 20 65 | #define diagonal 21 66 | #define sad 22 67 | #define sadOpen 23 68 | #define sadClosed 24 69 | #define okMouth 25 70 | #define xMouth 26 71 | #define interrogation 27 72 | #define thunder 28 73 | #define culito 29 74 | #define angry 30 75 | 76 | #endif -------------------------------------------------------------------------------- /src/Otto_sounds.h: -------------------------------------------------------------------------------- 1 | #ifndef Otto_sounds_h 2 | #define Otto_sounds_h 3 | 4 | // Reference: This list was adapted from the table located here: 5 | // http://www.phy.mtu.edu/~suits/notefreqs.html 6 | #define note_C0 16.35 //C0 7 | #define note_Db0 17.32 //C#0/Db0 8 | #define note_D0 18.35 //D0 9 | #define note_Eb0 19.45 //D#0/Eb0 10 | #define note_E0 20.6 //E0 11 | #define note_F0 21.83 //F0 12 | #define note_Gb0 23.12 //F#0/Gb0 13 | #define note_G0 24.5 //G0 14 | #define note_Ab0 25.96 //G#0/Ab0 15 | #define note_A0 27.5 //A0 16 | #define note_Bb0 29.14 //A#0/Bb0 17 | #define note_B0 30.87 //B0 18 | #define note_C1 32.7 //C1 19 | #define note_Db1 34.65 //C#1/Db1 20 | #define note_D1 36.71 //D1 21 | #define note_Eb1 38.89 //D#1/Eb1 22 | #define note_E1 41.2 //E1 23 | #define note_F1 43.65 //F1 24 | #define note_Gb1 46.25 //F#1/Gb1 25 | #define note_G1 49 //G1 26 | #define note_Ab1 51.91 //G#1/Ab1 27 | #define note_A1 55 //A1 28 | #define note_Bb1 58.27 //A#1/Bb1 29 | #define note_B1 61.74 //B1 30 | #define note_C2 65.41 //C2 (Middle C) 31 | #define note_Db2 69.3 //C#2/Db2 32 | #define note_D2 73.42 //D2 33 | #define note_Eb2 77.78 //D#2/Eb2 34 | #define note_E2 82.41 //E2 35 | #define note_F2 87.31 //F2 36 | #define note_Gb2 92.5 //F#2/Gb2 37 | #define note_G2 98 //G2 38 | #define note_Ab2 103.83 //G#2/Ab2 39 | #define note_A2 110 //A2 40 | #define note_Bb2 116.54 //A#2/Bb2 41 | #define note_B2 123.47 //B2 42 | #define note_C3 130.81 //C3 43 | #define note_Db3 138.59 //C#3/Db3 44 | #define note_D3 146.83 //D3 45 | #define note_Eb3 155.56 //D#3/Eb3 46 | #define note_E3 164.81 //E3 47 | #define note_F3 174.61 //F3 48 | #define note_Gb3 185 //F#3/Gb3 49 | #define note_G3 196 //G3 50 | #define note_Ab3 207.65 //G#3/Ab3 51 | #define note_A3 220 //A3 52 | #define note_Bb3 233.08 //A#3/Bb3 53 | #define note_B3 246.94 //B3 54 | #define note_C4 261.63 //C4 55 | #define note_Db4 277.18 //C#4/Db4 56 | #define note_D4 293.66 //D4 57 | #define note_Eb4 311.13 //D#4/Eb4 58 | #define note_E4 329.63 //E4 59 | #define note_F4 349.23 //F4 60 | #define note_Gb4 369.99 //F#4/Gb4 61 | #define note_G4 392 //G4 62 | #define note_Ab4 415.3 //G#4/Ab4 63 | #define note_A4 440 //A4 64 | #define note_Bb4 466.16 //A#4/Bb4 65 | #define note_B4 493.88 //B4 66 | #define note_C5 523.25 //C5 67 | #define note_Db5 554.37 //C#5/Db5 68 | #define note_D5 587.33 //D5 69 | #define note_Eb5 622.25 //D#5/Eb5 70 | #define note_E5 659.26 //E5 71 | #define note_F5 698.46 //F5 72 | #define note_Gb5 739.99 //F#5/Gb5 73 | #define note_G5 783.99 //G5 74 | #define note_Ab5 830.61 //G#5/Ab5 75 | #define note_A5 880 //A5 76 | #define note_Bb5 932.33 //A#5/Bb5 77 | #define note_B5 987.77 //B5 78 | #define note_C6 1046.5 //C6 79 | #define note_Db6 1108.73 //C#6/Db6 80 | #define note_D6 1174.66 //D6 81 | #define note_Eb6 1244.51 //D#6/Eb6 82 | #define note_E6 1318.51 //E6 83 | #define note_F6 1396.91 //F6 84 | #define note_Gb6 1479.98 //F#6/Gb6 85 | #define note_G6 1567.98 //G6 86 | #define note_Ab6 1661.22 //G#6/Ab6 87 | #define note_A6 1760 //A6 88 | #define note_Bb6 1864.66 //A#6/Bb6 89 | #define note_B6 1975.53 //B6 90 | #define note_C7 2093 //C7 91 | #define note_Db7 2217.46 //C#7/Db7 92 | #define note_D7 2349.32 //D7 93 | #define note_Eb7 2489.02 //D#7/Eb7 94 | #define note_E7 2637.02 //E7 95 | #define note_F7 2793.83 //F7 96 | #define note_Gb7 2959.96 //F#7/Gb7 97 | #define note_G7 3135.96 //G7 98 | #define note_Ab7 3322.44 //G#7/Ab7 99 | #define note_A7 3520 //A7 100 | #define note_Bb7 3729.31 //A#7/Bb7 101 | #define note_B7 3951.07 //B7 102 | #define note_C8 4186.01 //C8 103 | #define note_Db8 4434.92 //C#8/Db8 104 | #define note_D8 4698.64 //D8 105 | #define note_Eb8 4978.03 //D#8/Eb8 106 | 107 | #define S_connection 0 108 | #define S_disconnection 1 109 | #define S_buttonPushed 2 110 | #define S_mode1 3 111 | #define S_mode2 4 112 | #define S_mode3 5 113 | #define S_surprise 6 114 | #define S_OhOoh 7 115 | #define S_OhOoh2 8 116 | #define S_cuddly 9 117 | #define S_sleeping 10 118 | #define S_happy 11 119 | #define S_superHappy 12 120 | #define S_happy_short 13 121 | #define S_sad 14 122 | #define S_confused 15 123 | #define S_fart1 16 124 | #define S_fart2 17 125 | #define S_fart3 18 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /src/SerialCommand.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | SerialCommand - An Arduino library to tokenize and parse commands received over 3 | a serial port. 4 | Copyright (C) 2011-2013 Steven Cogswell 5 | http://awtfy.com 6 | 7 | See SerialCommand.h for version history. 8 | 9 | This library is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Lesser General Public 11 | License as published by the Free Software Foundation; either 12 | version 2.1 of the License, or (at your option) any later version. 13 | 14 | This library is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public 20 | License along with this library; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 | ***********************************************************************************/ 23 | 24 | #if defined(ARDUINO) && ARDUINO >= 100 25 | #include "Arduino.h" 26 | #else 27 | #include "WProgram.h" 28 | #endif 29 | 30 | #include "SerialCommand.h" 31 | 32 | 33 | #include 34 | #ifndef SERIALCOMMAND_HARDWAREONLY 35 | #include 36 | #endif 37 | 38 | // Constructor makes sure some things are set. 39 | SerialCommand::SerialCommand() 40 | { 41 | usingSoftwareSerial=0; 42 | strncpy(delim," ",MAXDELIMETER); // strtok_r needs a null-terminated string 43 | term='\r'; // return character, default terminator for commands 44 | numCommand=0; // Number of callback handlers installed 45 | clearBuffer(); 46 | } 47 | 48 | #ifndef SERIALCOMMAND_HARDWAREONLY 49 | // Constructor to use a SoftwareSerial object 50 | SerialCommand::SerialCommand(Stream &_ser) 51 | { 52 | usingSoftwareSerial=1; 53 | _serialPort = &_ser; 54 | strncpy(delim," ",MAXDELIMETER); // strtok_r needs a null-terminated string 55 | term='\r'; // return character, default terminator for commands 56 | numCommand=0; // Number of callback handlers installed 57 | clearBuffer(); 58 | } 59 | #endif 60 | 61 | 62 | // 63 | // Initialize the command buffer being processed to all null characters 64 | // 65 | void SerialCommand::clearBuffer() 66 | { 67 | for (int i=0; i 0) 91 | #else 92 | while ((usingSoftwareSerial==0 && Serial.available() > 0) || (usingSoftwareSerial==1 && _serialPort->available() > 0) ) 93 | #endif 94 | { 95 | int i; 96 | boolean matched; 97 | if (usingSoftwareSerial==0) { 98 | // Hardware serial port 99 | inChar=Serial.read(); // Read single available character, there may be more waiting 100 | } else { 101 | #ifndef SERIALCOMMAND_HARDWAREONLY 102 | // SoftwareSerial port 103 | inChar = _serialPort->read(); // Read single available character, there may be more waiting 104 | #endif 105 | } 106 | #ifdef SERIALCOMMANDDEBUG 107 | Serial.print(inChar); // Echo back to serial stream 108 | #endif 109 | if (inChar==term) { // Check for the terminator (default '\r') meaning end of command 110 | #ifdef SERIALCOMMANDDEBUG 111 | Serial.print("Received: "); 112 | Serial.println(buffer); 113 | #endif 114 | bufPos=0; // Reset to start of buffer 115 | token = strtok_r(buffer,delim,&last); // Search for command at start of buffer 116 | if (token == NULL) return; 117 | matched=false; 118 | for (i=0; i SERIALCOMMANDBUFFER-1) bufPos=0; // wrap buffer around if full 151 | } 152 | } 153 | } 154 | 155 | // Adds a "command" and a handler function to the list of available commands. 156 | // This is used for matching a found token in the buffer, and gives the pointer 157 | // to the handler function to deal with it. 158 | void SerialCommand::addCommand(const char *command, void (*function)()) 159 | { 160 | if (numCommand < MAXSERIALCOMMANDS) { 161 | #ifdef SERIALCOMMANDDEBUG 162 | Serial.print(numCommand); 163 | Serial.print("-"); 164 | Serial.print("Adding command for "); 165 | Serial.println(command); 166 | #endif 167 | 168 | strncpy(CommandList[numCommand].command,command,MAXDELIMETER); 169 | CommandList[numCommand].function = function; 170 | numCommand++; 171 | } else { 172 | // In this case, you tried to push more commands into the buffer than it is compiled to hold. 173 | // Not much we can do since there is no real visible error assertion, we just ignore adding 174 | // the command 175 | #ifdef SERIALCOMMANDDEBUG 176 | Serial.println("Too many handlers - recompile changing MAXSERIALCOMMANDS"); 177 | #endif 178 | } 179 | } 180 | 181 | // This sets up a handler to be called in the event that the receveived command string 182 | // isn't in the list of things with handlers. 183 | void SerialCommand::addDefaultHandler(void (*function)()) 184 | { 185 | defaultHandler = function; 186 | } -------------------------------------------------------------------------------- /src/SerialCommand.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | SerialCommand - An Arduino library to tokenize and parse commands received over 3 | a serial port. 4 | Copyright (C) 2011-2013 Steven Cogswell 5 | http://awtfy.com 6 | 7 | Version 20131021A. 8 | 9 | Version History: 10 | May 11 2011 - Initial version 11 | May 13 2011 - Prevent overwriting bounds of SerialCommandCallback[] array in addCommand() 12 | defaultHandler() for non-matching commands 13 | Mar 2012 - Some const char * changes to make compiler happier about deprecated warnings. 14 | Arduino 1.0 compatibility (Arduino.h header) 15 | Oct 2013 - SerialCommand object can be created using a SoftwareSerial object, for SoftwareSerial 16 | support. Requires #include in your sketch even if you don't use 17 | a SoftwareSerial port in the project. sigh. See Example Sketch for usage. 18 | Oct 2013 - Conditional compilation for the SoftwareSerial support, in case you really, really 19 | hate it and want it removed. 20 | Jun 2022 - Using MAXDELIMETER as maximum length of serial command added when calling addCommand 21 | order to reduce the usage of dynamic memory/RAM footprint. 22 | 23 | This library is free software; you can redistribute it and/or 24 | modify it under the terms of the GNU Lesser General Public 25 | License as published by the Free Software Foundation; either 26 | version 2.1 of the License, or (at your option) any later version. 27 | 28 | This library is distributed in the hope that it will be useful, 29 | but WITHOUT ANY WARRANTY; without even the implied warranty of 30 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 31 | Lesser General Public License for more details. 32 | 33 | You should have received a copy of the GNU Lesser General Public 34 | License along with this library; if not, write to the Free Software 35 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 36 | ***********************************************************************************/ 37 | #ifndef SerialCommand_h 38 | #define SerialCommand_h 39 | 40 | #if defined(ARDUINO) && ARDUINO >= 100 41 | #include "Arduino.h" 42 | #else 43 | #include "WProgram.h" 44 | #endif 45 | 46 | // If you want to use SerialCommand with the hardware serial port only, and want to disable 47 | // SoftwareSerial support, and thus don't have to use "#include " in your 48 | // sketches, then uncomment this define for SERIALCOMMAND_HARDWAREONLY, and comment out the 49 | // corresponding #undef line. 50 | // 51 | // You don't have to use SoftwareSerial features if this is not defined, you can still only use 52 | // the Hardware serial port, just that this way lets you get out of having to include 53 | // the SoftwareSerial.h header. 54 | //#define SERIALCOMMAND_HARDWAREONLY 1 55 | #undef SERIALCOMMAND_HARDWAREONLY 56 | 57 | #ifdef SERIALCOMMAND_HARDWAREONLY 58 | #warning "Warning: Building SerialCommand without SoftwareSerial Support" 59 | #endif 60 | 61 | #ifndef SERIALCOMMAND_HARDWAREONLY 62 | #include 63 | #endif 64 | 65 | #include 66 | 67 | #define SERIALCOMMANDBUFFER 35 68 | #define MAXSERIALCOMMANDS 16 69 | #define MAXDELIMETER 2 70 | 71 | #define SERIALCOMMANDDEBUG 1 72 | #undef SERIALCOMMANDDEBUG // Comment this out to run the library in debug mode (verbose messages) 73 | 74 | class SerialCommand 75 | { 76 | public: 77 | SerialCommand(); // Constructor 78 | #ifndef SERIALCOMMAND_HARDWAREONLY 79 | SerialCommand(Stream &SoftSer); // Constructor for using SoftwareSerial objects 80 | #endif 81 | 82 | void clearBuffer(); // Sets the command buffer to all '\0' (nulls) 83 | char *next(); // returns pointer to next token found in command buffer (for getting arguments to commands) 84 | void readSerial(); // Main entry point. 85 | void addCommand(const char *, void(*)()); // Add commands to processing dictionary 86 | void addDefaultHandler(void (*function)()); // A handler to call when no valid command received. 87 | 88 | private: 89 | char inChar; // A character read from the serial stream 90 | char buffer[SERIALCOMMANDBUFFER]; // Buffer of stored characters while waiting for terminator character 91 | int bufPos; // Current position in the buffer 92 | char delim[MAXDELIMETER]; // null-terminated list of character to be used as delimeters for tokenizing (default " ") 93 | char term; // Character that signals end of command (default '\r') 94 | char *token; // Returned token from the command buffer as returned by strtok_r 95 | char *last; // State variable used by strtok_r during processing 96 | typedef struct _callback { 97 | char command[MAXDELIMETER]; 98 | void (*function)(); 99 | } SerialCommandCallback; // Data structure to hold Command/Handler function key-value pairs 100 | int numCommand; 101 | SerialCommandCallback CommandList[MAXSERIALCOMMANDS]; // Actual definition for command/handler array 102 | void (*defaultHandler)(); // Pointer to the default handler function 103 | int usingSoftwareSerial; // Used as boolean to see if we're using SoftwareSerial object or not 104 | #ifndef SERIALCOMMAND_HARDWAREONLY 105 | Stream *_serialPort; // Pointer to a user-created SoftwareSerial object 106 | #endif 107 | }; 108 | 109 | #endif //SerialCommand_h --------------------------------------------------------------------------------