├── .gitattributes ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── examples ├── by_board │ ├── WiFi_rev2 │ │ ├── IMU │ │ │ └── IMU.ino │ │ └── WebLed │ │ │ └── WebLed.ino │ └── all │ │ ├── Blink │ │ └── Blink.ino │ │ ├── Button │ │ └── Button.ino │ │ ├── ButtonStates │ │ └── ButtonStates.ino │ │ ├── DHT11 │ │ └── DHT11.ino │ │ ├── Empty │ │ └── Empty.ino │ │ ├── LM35 │ │ └── LM35.ino │ │ ├── LightSensor │ │ └── LightSensor.ino │ │ ├── Melody │ │ └── Melody.ino │ │ ├── MelodyButton │ │ └── MelodyButton.ino │ │ ├── MelodyButtonTwoSounds │ │ └── MelodyButtonTwoSounds.ino │ │ ├── MosFet │ │ └── MosFet.ino │ │ ├── PIR │ │ └── PIR.ino │ │ ├── PIRStates │ │ └── PIRStates.ino │ │ ├── PhysicalPixel │ │ └── PhysicalPixel.ino │ │ ├── Potentiometer │ │ └── Potentiometer.ino │ │ ├── Relay │ │ └── Relay.ino │ │ ├── RisingDecreasing │ │ └── RisingDecreasing.ino │ │ ├── Servo │ │ └── Servo.ino │ │ ├── ServoButton │ │ └── ServoButton.ino │ │ ├── ServoKnob │ │ └── ServoKnob.ino │ │ ├── ServoKnobContinuous │ │ └── ServoKnobContinuous.ino │ │ └── Thermistor │ │ └── Thermistor.ino ├── by_topic │ ├── Blink │ │ └── Blink.ino │ ├── Button │ │ └── Button.ino │ ├── ButtonStates │ │ └── ButtonStates.ino │ ├── DHT11 │ │ └── DHT11.ino │ ├── Empty │ │ └── Empty.ino │ ├── LM35 │ │ └── LM35.ino │ ├── LightSensor │ │ └── LightSensor.ino │ ├── Melody │ │ └── Melody.ino │ ├── MelodyButton │ │ └── MelodyButton.ino │ ├── MelodyButtonTwoSounds │ │ └── MelodyButtonTwoSounds.ino │ ├── MosFet │ │ └── MosFet.ino │ ├── PIR │ │ └── PIR.ino │ ├── PIRStates │ │ └── PIRStates.ino │ ├── PhysicalPixel │ │ └── PhysicalPixel.ino │ ├── Potentiometer │ │ └── Potentiometer.ino │ ├── Relay │ │ └── Relay.ino │ ├── RisingDecreasing │ │ └── RisingDecreasing.ino │ ├── Servo │ │ └── Servo.ino │ ├── ServoButton │ │ └── ServoButton.ino │ ├── ServoKnob │ │ └── ServoKnob.ino │ ├── ServoKnobContinuous │ │ └── ServoKnobContinuous.ino │ └── Thermistor │ │ └── Thermistor.ino └── courseware │ ├── cardboardKeyboard │ └── ButtonStatesKeyboard │ │ └── ButtonStatesKeyboard.ino │ └── workshop_1h │ ├── Blink │ └── Blink.ino │ ├── Button │ └── Button.ino │ ├── ButtonStates │ └── ButtonStates.ino │ ├── Empty │ └── Empty.ino │ ├── Melody │ └── Melody.ino │ ├── MelodyButton │ └── MelodyButton.ino │ ├── Servo │ └── Servo.ino │ └── ServoButton │ └── ServoButton.ino ├── keywords.txt ├── library.json ├── library.properties └── src ├── Button ├── Button.cpp └── Button.h ├── DHT11 ├── DHT11.cpp └── DHT11.h ├── EduIntro.cpp ├── EduIntro.h ├── Generic ├── AnalogInput.h ├── AnalogInput2.cpp ├── AnalogInput2.h ├── Analoginput.cpp ├── DigitalInput.cpp ├── DigitalInput.h ├── Output.cpp └── Output.h ├── IMU ├── Motion.cpp └── Motion.h ├── LED ├── LED.cpp └── LED.h ├── LM35 ├── LM35.cpp └── LM35.h ├── LightSensor ├── LightSensor.cpp └── LightSensor.h ├── MosFet ├── MosFet.cpp └── MosFet.h ├── PIR ├── PIR.cpp └── PIR.h ├── Piezo ├── Piezo.cpp ├── Piezo.h └── pitches.h ├── Potentiometer ├── Potentiometer.cpp └── Potentiometer.h ├── Relay ├── Relay.cpp └── Relay.h ├── ServoMotor ├── ServoMotor.cpp └── ServoMotor.h ├── Thermistor ├── Thermistor.cpp └── Thermistor.h └── WiFiComm ├── WiFiComm.cpp └── WiFiComm.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution Guidlines 2 | 3 | This library is the culmination of the expertise of many members of the open source community who have dedicated their time and hard work. The best way to ask for help or propose a new idea is to [create a new issue](https://github.com/arduino/EduIntro/issues/new) while creating a Pull Request with your code changes allows you to share your own innovations with the rest of the community. 4 | 5 | The following are some guidelines to observe when creating issues or PRs: 6 | 7 | - Be friendly; it is important that we can all enjoy a safe space as we are all working on the same project and it is okay for people to have different ideas 8 | 9 | - [Use code blocks](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code); it helps us help you when we can read your code! On that note also refrain from pasting more than 30 lines of code in a post, instead [create a gist](https://gist.github.com/) if you need to share large snippets 10 | 11 | - Use reasonable titles; refrain from using overly long or capitalized titles as they are usually annoying and do little to encourage others to help :smile: 12 | 13 | - Be detailed; refrain from mentioning code problems without sharing your source code and always give information regarding your board and version of the library -------------------------------------------------------------------------------- /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 | . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Education Introduction Library - a.k.a. EduIntro 2 | 3 | ## Description 4 | 5 | Arduino library for short introduction training workshops run by Arduino Education. This library is originally made for TinkerKit. It simplifies the use of sensors and actuators when connected to an Arduino board. The goal is to plan and conduct a simple one or two hours of training workshop where users will still have the opportunity to model meaningful interactions using discrete electronic components. It consists of already implemented basic functions for electronic components. In order to use its functions, it only requires to import this library and then call its functions. 6 | 7 | ## Installation 8 | 9 | ### First Method 10 | 11 | 1. In the Arduino IDE, navigate to Sketch > Include Library > Manage Libraries 12 | 1. Then the Library Manager will open and you will find a list of libraries that are already installed or ready for installation. 13 | 1. Then search for EduIntro using the search bar. 14 | 1. Click on the text area and then select the specific version and install it. 15 | 16 | ### Second Method 17 | 18 | 1. Navigate to the Releases page. 19 | 1. Download the latest release. 20 | 1. Extract the zip file 21 | 1. In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library 22 | 23 | ## Features 24 | 25 | - ### Self contained 26 | 27 | EduIntro doesn’t depend on any library. 28 | 29 | - ### Easy to use 30 | 31 | It is simple, basic and very easy to understand. The user only needs to import the library in his code and start using its functions. 32 | 33 | - ### Complete package for small workshops 34 | 35 | Basic functions of discrete electronic components have already been implemented in this library. For a small one or two hours workshop, the user does not have to implement all the basic functions for the electronic component from scratch. 36 | 37 | - ### Function calls 38 | 39 | Basic functions of the electronic components have been implemented in this library. There's no need to re-implement these basic functions from scratch. The user simply has to import the library in the project and can use any of its functions by just calling it. 40 | 41 | - ### Intuitive syntax 42 | 43 | EduIntro has a simple and intuitive syntax to handle variables and functions. 44 | 45 | - ### Give back 46 | 47 | EduIntro is free for everyone. Everyone can download and use it in their projects, assignments or anywhere for free. 48 | 49 | ## Components and functions 50 | 51 | - ### Button 52 | 53 | - readSwitch() 54 | - pressed() 55 | - released() 56 | - held() 57 | - *Note: construct a button with Button NAME(PIN) or Button NAME(PIN,PULL_UP | PULL_DOWN), by default buttons are considered to use internal pull-ups* 58 | 59 | - ### DHT11 60 | 61 | - update() 62 | - readCelsius() 63 | - readFahrenheit() 64 | - readHumidity() 65 | 66 | - ### Generic 67 | 68 | - ### For analog inputs 69 | 70 | - readX() 71 | - readY() 72 | - readZ() 73 | - read() 74 | - increasing() 75 | - decreasing() 76 | 77 | - ### For digital inputs 78 | 79 | - read() 80 | 81 | - ### For outputs (this extends to LEDs) 82 | 83 | - isPWM() 84 | - write() 85 | - on() 86 | - off() 87 | - blink() 88 | - state() 89 | - *Note: construct an output with e.g. Led NAME(PIN) or Led NAME(PIN,NORMAL | INVERTED), this helps with common cathode LEDs* 90 | 91 | - ### IMU 92 | 93 | - begin() 94 | - readAcceleration() 95 | - readGyroscope() 96 | - read() 97 | 98 | - ### LED (besides all of the output functions) 99 | 100 | - brightness() 101 | 102 | - ### LM35 103 | 104 | - readCelsius() 105 | - readFahrenheit() 106 | 107 | - ### PIR 108 | 109 | - update() 110 | - hadActivity() 111 | - resetActivity() 112 | - readSwitch() 113 | - activated() 114 | - deactivated() 115 | - active() 116 | 117 | - ### Piezo 118 | 119 | - beep() 120 | - noBeep() 121 | - play() 122 | - getMelodySize() 123 | 124 | - ### Potentiometer 125 | 126 | - read() 127 | - readRange() 128 | - readStep() 129 | 130 | - ### ServoMotor 131 | 132 | - write() 133 | 134 | - ### Thermistor 135 | 136 | - readCelsius() 137 | - readFahrenheit() 138 | 139 | - ### WiFiComm 140 | 141 | - init() 142 | - getSSID() 143 | - getIP() 144 | - getStatus() 145 | - getClient() 146 | 147 | ## Examples 148 | 149 | There are many examples implemented in this library. Below are shown some of the examples. 150 | 151 | - ### Blink 152 | Turns on an LED on for one second, then off for one second, repeatedly 153 | 154 | ``` C++ 155 | #include 156 | 157 | Led led(D10); 158 | 159 | void loop() 160 | { 161 | led.on(); 162 | delay(1000); 163 | led.off(); 164 | delay(1000); 165 | } 166 | ``` 167 | 168 | - ### Button 169 | Changes the behavior between on and off an LED when pressing a button. 170 | 171 | ``` C++ 172 | #include 173 | 174 | Button button(D7); 175 | Led led(D10); 176 | 177 | void loop() 178 | { 179 | if (button.readSwitch() == LOW) { 180 | led.on(); 181 | } 182 | else { 183 | led.off(); 184 | } 185 | } 186 | ``` 187 | 188 | ## Versions 189 | 190 | ### v0.0.16 (Current stable version) 191 | 192 | #### November, 2021 193 | 194 | * Fixed an issue with the Potentiometer class in mbed (Nano 33 BLE Sense) 195 | * Added readRange() method for the Potentiometer 196 | * Added inverted logic for outputs and the constructor to have e.g. *Led led(PIN, NORMAL | INVERTED)* 197 | 198 | ### v0.0.13 199 | 200 | #### April, 2021 201 | 202 | * Eliminated delays in button handling 203 | * Added second constructor for Button, choose pull_up or down 204 | 205 | ### v0.0.12 206 | 207 | #### December 16, 2019 208 | 209 | * Added library dependencies 210 | 211 | ### v0.0.11 212 | 213 | #### December 9, 2019 214 | 215 | * Added Nano Every by separating the two possible MEGAAVR boards (Nano Every + Uno WiFi rev2). 216 | * Included a noBeep() function 217 | * Added the new README with basic API description 218 | 219 | ### v0.0.10 220 | 221 | #### August 28, 2019 222 | 223 | The previous release included a non-functional WiFiComm file. It has been revised and made beautification in some of the code. It has been made sure that the Classic boards work fine as it got broken in the previous release. 224 | 225 | ### v0.0.9 226 | 227 | #### August 27, 2019 228 | 229 | Added support for the WiFi REV2 board and fixed the incompatibilities with servo and piezo. 230 | 231 | ### v0.0.8 232 | 233 | #### May 01, 2019 234 | 235 | All classes were separated to allow adding new classes by simply copy-pasting and modifying template examples. 236 | 237 | ### v0.0.7 238 | 239 | #### April 17, 2019 240 | 241 | General bug fixing: servo library not-two-servos fixed, added a new two-melodies example, fixed the button-pressed-by-default bug. Thanks to D. Spikol for bug catching and S. Mistry for reminding me that C++ inheritance is not always doing the things you expect. 242 | 243 | ### v0.0.6 244 | 245 | #### February 10, 2019 246 | 247 | For a course at Aalborg University, CPH, we added the humidity and temperature sensor DHT11, the LM35 temperature sensor, a PIR sensor, and a couple more examples to the courseware. 248 | 249 | ### v0.0.5 250 | 251 | #### January 27, 2019 252 | 253 | Sabas came all the way from Mexico to Malmo and made a fresh pull request. Now the library works with MKR boards! 254 | 255 | ### v0.0.4 256 | 257 | #### January 25, 2019 258 | 259 | See possible results of the workshop [here](https://photos.app.goo.gl/G9B4KmBHX7FQGdYNA) 260 | 261 | ## Contributing 262 | 263 | If you want to contribute to this project: 264 | 265 | - Report bugs and errors 266 | - Ask for enhancements 267 | - Create issues and pull requests 268 | - Tell others about this library 269 | - Contribute new protocols 270 | 271 | Please read [CONTRIBUTING.md](https://github.com/arduino/EduIntro/blob/master/CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us. 272 | 273 | ## Credits 274 | 275 | The Library created and maintained by D. Cuartielles, Malmo, 2018 - 2019 276 | WiFi REV2 compatibility by C. Rodriguez (IMU + WiFi), and D. Cuartielles (servo), Malmo, 2019 277 | MKR compatibility by A. Sabas, Malmo, 2019 278 | 279 | Based on previous work by: 280 | 281 | - D. Mellis, Milano, 2006 282 | - T. Igoe, New York, 2008 - 2010 283 | - S. Fitzgerald, New York, 2010 284 | - D. Gomba, Torino, 2010 285 | - F. Vanzati, Torino, 2011 286 | - M. Loglio, London, 2013 287 | - G. Hadjikyriacou (DHT11 lib originator), ?? 288 | - SimKard (DHT11), 2010 289 | - R. Tillaart (DHT11), 2011 - 2013 290 | - A. Dalton (DHT11), 2013 291 | - [Arduino community](https://www.arduino.cc) 292 | 293 | ## Current stable version 294 | 295 | **number:** v0.0.16 296 | 297 | **codename:** ananas 298 | 299 | ## License 300 | 301 | This library is licensed under [GPLv3](https://www.gnu.org/licenses/quick-guide-gplv3.html). 302 | -------------------------------------------------------------------------------- /examples/by_board/WiFi_rev2/IMU/IMU.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Inertia Meassurement Unit (IMU) A.K.A. Motion 3 | 4 | IMPORTANT: This example is using the Arduino_LSM6DS3 library in the backed. You 5 | need to have it installed before testing this code. If you are on 6 | Arduino Create (the online IDE) the library will already be there. 7 | 8 | This example uses the embeded IMU unit in the Arduino UNO Wifi Rev2. 9 | 10 | The IMU captures values from the accelerometer and the gyroscope. 11 | These values can be accesable with: 12 | 13 | acc_x: Returns the X value of the accelerometer. 14 | acc_y: Returns the Y value of the accelerometer. 15 | acc_z: Returns the Z value of the accelerometer. 16 | gyro_x: Returns the X value of the gyroscope. 17 | gyro_y: Returns the Y value of the gyroscope. 18 | gyro_z: Returns the Z value of the gyroscope. 19 | 20 | This example code is in the public domain. 21 | 22 | created in Aug 2019 by C. Rodriguez 23 | based on work by D. Cuartielles (2019), F. Vanzati (2011) and M. Loglio (2013) 24 | */ 25 | 26 | // include the EduIntro library 27 | #include 28 | 29 | Motion imu; //Create the object to access the IMU unit 30 | 31 | void setup() 32 | { 33 | // initialize serial communications at 9600 bps 34 | Serial.begin(9600); 35 | 36 | // initialize the IMU, if failed, stay here 37 | if (!imu.begin()) { 38 | Serial.println("Failed to initialize IMU!"); 39 | while (1); 40 | } 41 | } 42 | 43 | void loop() 44 | { 45 | // read all data from the IMU and store it in local variables 46 | if (imu.read()) { 47 | 48 | // print the collected data in a row on the Serial Monitor 49 | // or use the Serial Plotter to better understand the values 50 | Serial.print(imu.acc_x); 51 | Serial.print('\t'); 52 | Serial.print(imu.acc_y); 53 | Serial.print('\t'); 54 | Serial.println(imu.acc_z); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /examples/by_board/WiFi_rev2/WebLed/WebLed.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WebLed 3 | 4 | WiFi Web Server LED Blink 5 | 6 | A simple web server that lets you blink an LED via the web. 7 | This sketch will create a new access point (with no password). 8 | It will then launch a new server and print out the IP address 9 | to the Serial monitor. From there, you can open that address in a web browser 10 | to turn on and off the LED on pin 13. 11 | 12 | If the IP address of your board is yourAddress: 13 | http://yourAddress/H turns the LED on 14 | http://yourAddress/L turns it off 15 | 16 | Adapted to EduIntro by C. Rodriguez, and D. Cuartielles (2019) 17 | 18 | Created by Tom Igoe (2012) 19 | */ 20 | 21 | #include 22 | 23 | // network related info 24 | const char ssid[] = "ArduinoWiFi"; // your network SSID (name). Must have 8 or more characters. 25 | const char pass[] = ""; // your network password (use for WPA, or use as key for WEP). optional, but if set, must have 8 or more characters. 26 | int keyIndex = 0; // your network key Index number (needed only for WEP) 27 | 28 | // misc variables 29 | WiFiComm MyWiFi; 30 | int led = LED_BUILTIN; 31 | int status = WL_IDLE_STATUS; 32 | boolean firstTime = true; 33 | 34 | void setup() { 35 | // initialize serial and wait for port to open: 36 | Serial.begin(9600); 37 | while (!Serial) {}; 38 | 39 | MyWiFi.init(led, ssid, pass); 40 | 41 | // you're connected now, so print out the status 42 | printWiFiStatus(); 43 | Serial.print("\t SSID:"); 44 | Serial.println(MyWiFi.getSSID()); 45 | } 46 | 47 | void loop() { 48 | // compare the previous status to the current status 49 | if (status != MyWiFi.getStatus()) { 50 | // it has changed update the variable 51 | status = MyWiFi.getStatus(); 52 | 53 | if (status == WL_AP_CONNECTED) { 54 | // a device has connected to the AP 55 | Serial.println("Device connected to AP"); 56 | } else { 57 | if (!firstTime) { 58 | // a device has disconnected from the AP, and we are back in listening mode 59 | Serial.println("Device disconnected from AP"); 60 | } 61 | } 62 | } 63 | 64 | WiFiClient client = MyWiFi.getClient(); // listen for incoming clients 65 | 66 | if (client) { // if you get a client, 67 | firstTime = false; 68 | Serial.println("new client"); // print a message out the serial port 69 | String currentLine = ""; // make a String to hold incoming data from the client 70 | while (client.connected()) { // loop while the client's connected 71 | if (client.available()) { // if there's bytes to read from the client, 72 | char c = client.read(); // read a byte, then 73 | Serial.write(c); // print it out the serial monitor 74 | if (c == '\n') { // if the byte is a newline character 75 | 76 | // if the current line is blank, you got two newline characters in a row. 77 | // that's the end of the client HTTP request, so send a response: 78 | if (currentLine.length() == 0) { 79 | // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) 80 | // and a content-type so the client knows what's coming, then a blank line: 81 | client.println("HTTP/1.1 200 OK"); 82 | client.println("Content-type:text/html"); 83 | client.println(); 84 | 85 | // the content of the HTTP response follows the header: 86 | client.print("Click here turn the LED on
"); 87 | client.print("Click here turn the LED off
"); 88 | 89 | // The HTTP response ends with another blank line: 90 | client.println(); 91 | // break out of the while loop: 92 | break; 93 | } 94 | else { // if you got a newline, then clear currentLine: 95 | currentLine = ""; 96 | } 97 | } 98 | else if (c != '\r') { // if you got anything else but a carriage return character, 99 | currentLine += c; // add it to the end of the currentLine 100 | } 101 | 102 | // Check to see if the client request was "GET /H" or "GET /L": 103 | if (currentLine.endsWith("GET /H")) { 104 | digitalWrite(led, HIGH); // GET /H turns the LED on 105 | } 106 | if (currentLine.endsWith("GET /L")) { 107 | digitalWrite(led, LOW); // GET /L turns the LED off 108 | } 109 | } 110 | } 111 | // close the connection: 112 | client.stop(); 113 | Serial.println("client disconnected"); 114 | } 115 | 116 | } 117 | 118 | 119 | void printWiFiStatus() { 120 | // print the SSID of the network you're attached to: 121 | Serial.print("SSID: "); 122 | Serial.println(MyWiFi.getSSID()); 123 | 124 | // print your WiFi shield's IP address: 125 | IPAddress ip = MyWiFi.getIP(); 126 | Serial.print("IP Address: "); 127 | Serial.println(ip); 128 | 129 | // print where to go in a browser: 130 | Serial.print("To see this page in action, open a browser to http://"); 131 | Serial.println(ip); 132 | } 133 | -------------------------------------------------------------------------------- /examples/by_board/all/Blink/Blink.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Blink 3 | 4 | based on Blink, Arduino's "Hello World!" 5 | Turns on an LED on for one second, then off for one second, repeatedly. 6 | 7 | created in Aug 2018 by D. Cuartielles 8 | based on work by F. Vanzati (2011) 9 | 10 | This example code is in the public domain. 11 | */ 12 | 13 | // include the EduIntro library 14 | #include 15 | 16 | Led led(D10); // creating the object 'led' on pin D10 17 | 18 | void setup() { 19 | //nothing here 20 | } 21 | 22 | void loop() 23 | { 24 | led.on(); // set the LED on 25 | delay(1000); // wait for a second 26 | led.off(); // set the LED off 27 | delay(1000); // wait for a second 28 | } 29 | -------------------------------------------------------------------------------- /examples/by_board/all/Button/Button.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Button 3 | 4 | Changes the behavior between on and off an LED when pressing a Button. 5 | 6 | This example code is in the public domain. 7 | 8 | created in Aug 2018 by D. Cuartielles 9 | based on work by F. Vanzati (2011) and M. Loglio (2013) 10 | 11 | based on http://www.arduino.cc/en/Tutorial/Button 12 | */ 13 | 14 | // include the EduIntro library 15 | #include 16 | 17 | Button button(D7); // creating the object 'button' on pin D7 18 | 19 | Led led(D10); // creating the object 'led' on pin D10 20 | 21 | 22 | void setup() { 23 | //nothing here 24 | } 25 | 26 | void loop() 27 | { 28 | // check the switchState of the button 29 | // each time it is pressed, it toggles the LED 30 | // when LOW, light should go on 31 | if (button.readSwitch() == LOW) { 32 | led.on(); 33 | } 34 | else { 35 | led.off(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /examples/by_board/all/ButtonStates/ButtonStates.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ButtonStates 3 | 4 | Test the different Button methods: pressed, released, held 5 | and getSwitch. 6 | 7 | This example code is in the public domain. 8 | 9 | created in Aug 2018 by D. Cuartielles 10 | based on work by F. Vanzati (2011) and M. Loglio (2013) 11 | */ 12 | 13 | #include 14 | 15 | Button btn(D7); 16 | 17 | void setup() 18 | { 19 | // we are going to use the serial communication as a 20 | // way to see on the PC what is happening on the Arduino 21 | Serial.begin(9600); 22 | } 23 | 24 | void loop() 25 | { 26 | if(btn.pressed()) 27 | Serial.println("pressed"); 28 | if(btn.held()) 29 | Serial.println("held"); 30 | if(btn.released()) { 31 | Serial.println("released"); 32 | Serial.print("switch: "); 33 | Serial.println(btn.readSwitch()); 34 | } 35 | 36 | delay(50); 37 | } 38 | -------------------------------------------------------------------------------- /examples/by_board/all/DHT11/DHT11.ino: -------------------------------------------------------------------------------- 1 | /* 2 | DHT11 3 | 4 | This example reads a DHT11 sensor hooked up on pin D7. Reads both 5 | temperature and humidity and sends it to the Serial port 6 | 7 | created in Feb 2019 by D. Cuartielles 8 | based on work by F. Vanzati (2011) and M. Loglio (2013) 9 | 10 | This example code is in the public domain. 11 | */ 12 | 13 | // include the EduIntro library 14 | #include 15 | 16 | DHT11 dht11(D7); // creating the object sensor on pin 'D7' 17 | 18 | int C; // temperature C readings are integers 19 | float F; // temperature F readings are returned in float format 20 | int H; // humidity readings are integers 21 | 22 | void setup() 23 | { 24 | // initialize serial communications at 9600 bps 25 | Serial.begin(9600); 26 | } 27 | 28 | void loop() 29 | { 30 | dht11.update(); 31 | 32 | C = dht11.readCelsius(); // Reading the temperature in Celsius degrees and store in the C variable 33 | F = dht11.readFahrenheit(); // Reading the temperature in Fahrenheit degrees and store in the F variable 34 | H = dht11.readHumidity(); // Reading the humidity index 35 | 36 | // Print the collected data in a row on the Serial Monitor 37 | Serial.print("H: "); 38 | Serial.print(H); 39 | Serial.print("\tC: "); 40 | Serial.print(C); 41 | Serial.print("\tF: "); 42 | Serial.println(F); 43 | 44 | delay(1000); // Wait one second before get another temperature reading 45 | } 46 | -------------------------------------------------------------------------------- /examples/by_board/all/Empty/Empty.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void setup() { 4 | //Serial.begin(9600); 5 | } 6 | 7 | void loop() { 8 | 9 | } -------------------------------------------------------------------------------- /examples/by_board/all/LM35/LM35.ino: -------------------------------------------------------------------------------- 1 | /* 2 | LM35 3 | 4 | This example uses an LM35 (or equivalent) sensor hooked up on pin A0. 5 | 6 | Three values are displayed on the Serial Monitor every second: 7 | - the value between 0 and 1023 that represent the Analog Input reading 8 | - the temperature expressed in Celsius degrees 9 | - the temperature expressed in Fahrenheit dedegrees 10 | 11 | created in Feb 2019 by D. Cuartielles 12 | based on work by F. Vanzati (2011) and M. Loglio (2013) 13 | 14 | This example code is in the public domain. 15 | */ 16 | 17 | // include the EduIntro library 18 | #include 19 | 20 | LM35 lm35(A0); // creating the object 'lm35' on pin A0 21 | 22 | float C, F; // temperature readings are returned in float format 23 | 24 | void setup() 25 | { 26 | // initialize serial communications at 9600 bps 27 | Serial.begin(9600); 28 | } 29 | 30 | void loop() 31 | { 32 | C = lm35.readCelsius(); // Reading the temperature in Celsius degrees and store in the C variable 33 | F = lm35.readFahrenheit(); // Reading the temperature in Fahrenheit degrees and store in the F variable 34 | 35 | // Print the collected data in a row on the Serial Monitor 36 | Serial.print("Analog reading: "); // Reading the analog value from the thermistor 37 | Serial.print(lm35.read()); 38 | Serial.print("\tC: "); 39 | Serial.print(C); 40 | Serial.print("\tF: "); 41 | Serial.println(F); 42 | 43 | delay(1000); // Wait one second before get another temperature reading 44 | } 45 | -------------------------------------------------------------------------------- /examples/by_board/all/LightSensor/LightSensor.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Read values from an LDR Analog Sensor connected to A0, 3 | then uses the result to set the brightness on an LED 4 | connected on D9. Also prints the values on the 5 | serial monitor. 6 | 7 | created in Aug 2018 by D. Cuartielles 8 | based on work by T. Igoe (2010), D. Gomba (2010), F. Vanzati (2011) and M. Loglio (2013) 9 | 10 | This example code is in the public domain. 11 | */ 12 | 13 | #include 14 | 15 | LightSensor ldr(A0); //create the "ldr" object on pin A0 16 | 17 | Led led(D10); //create the "led" object on pin D10 18 | 19 | void setup() { 20 | // initialize serial communications at 9600 bps 21 | Serial.begin(9600); 22 | } 23 | 24 | void loop() { 25 | // store the ldr values into a variable called brightnessVal 26 | int brightnessVal = ldr.read(); 27 | 28 | // set the led brightness 29 | led.brightness(brightnessVal); 30 | 31 | //to have it at full brightness 32 | //when it's dark, uncomment this line: 33 | //led.brightness(1023 - brightnessVal); 34 | 35 | // print the results to the serial monitor: 36 | Serial.print("brightness = " ); 37 | Serial.println(brightnessVal); 38 | 39 | 40 | // wait 10 milliseconds before the next loop 41 | delay(10); 42 | } 43 | -------------------------------------------------------------------------------- /examples/by_board/all/Melody/Melody.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Melody 3 | 4 | Plays a song stored in an array, repeatedly. You should connect 5 | a speaker to pin D10 6 | 7 | created in Aug 2018 by D. Cuartielles 8 | 9 | This example code is in the public domain. 10 | */ 11 | 12 | // include the EduIntro library 13 | #include 14 | 15 | // define the song as (note, duration) pairs 16 | // note durations: 4 = quarter note, 8 = eighth note, etc.: 17 | int melody[] = { NOTE_C4, 4, 18 | NOTE_G3, 8, 19 | NOTE_G3, 8, 20 | NOTE_A3, 4, 21 | NOTE_G3, 4, 22 | SILENCE, 4, 23 | NOTE_B3, 4, 24 | NOTE_C4, 4 }; 25 | 26 | Piezo piezo(D10); // creating the object 'piezo' on pin D10 27 | 28 | void setup() { 29 | //nothing here 30 | } 31 | 32 | void loop() 33 | { 34 | piezo.play(melody); // play the song 35 | delay(1000); // wait for a second 36 | } 37 | -------------------------------------------------------------------------------- /examples/by_board/all/MelodyButton/MelodyButton.ino: -------------------------------------------------------------------------------- 1 | /* 2 | MelodyButton 3 | 4 | Plays a song stored in an array, when pressing a button. You should connect 5 | a speaker to pin D10 and a button to pin D7 6 | 7 | created in Aug 2018 by D. Cuartielles 8 | 9 | This example code is in the public domain. 10 | */ 11 | 12 | // include the EduIntro library 13 | #include 14 | 15 | // define the song as (note, duration) pairs 16 | // note durations: 4 = quarter note, 8 = eighth note, etc.: 17 | int melody[] = { NOTE_C4, 4, 18 | NOTE_G3, 8, 19 | NOTE_G3, 8, 20 | NOTE_A3, 4, 21 | NOTE_G3, 4, 22 | SILENCE, 4, 23 | NOTE_B3, 4, 24 | NOTE_C4, 4 }; 25 | 26 | Button button(D7); // creating the object 'button' on pin D7 27 | 28 | Piezo piezo(D10); // creating the object 'piezo' on pin D10 29 | 30 | void setup() { 31 | //nothing here 32 | } 33 | 34 | void loop() 35 | { 36 | // if the button was just pressed, play melody 37 | if (button.pressed()) { 38 | piezo.play(melody); // play the song 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /examples/by_board/all/MelodyButtonTwoSounds/MelodyButtonTwoSounds.ino: -------------------------------------------------------------------------------- 1 | /* 2 | MelodyButtonTwoSounds 3 | 4 | Plays a song stored in an array, when pressing a button, a different one 5 | when releasing the button. You should connect a speaker to pin D10 and a 6 | button to pin D7. Melodies are stored in arrays ending with NULL 7 | 8 | created in Apr 2019 by D. Cuartielles 9 | 10 | This example code is in the public domain. 11 | */ 12 | 13 | // include the EduIntro library 14 | #include 15 | 16 | // define the song as (note, duration) pairs 17 | // note durations: 4 = quarter note, 8 = eighth note, etc. 18 | // add the NULL to signify the end of the array 19 | int melody1[] = { NOTE_C4, 4, 20 | NOTE_G3, 8, 21 | NOTE_G3, 8, 22 | SILENCE, 4, NULL}; 23 | 24 | int melody2[] = { NOTE_D4, 4, 25 | NOTE_C3, 8, 26 | NOTE_F3, 8, 27 | SILENCE, 4, NULL}; 28 | 29 | Button button(D7);// creating the object 'button' on pin D7 30 | 31 | Piezo piezo(D10);// creating the object 'piezo' on pin D10 32 | 33 | void setup() { 34 | //nothing here 35 | } 36 | 37 | void loop() 38 | { 39 | // if the button was just pressed, play melody 40 | if (button.pressed()) { 41 | piezo.play (melody1); 42 | } 43 | if (button.released()) { 44 | piezo.play (melody2); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /examples/by_board/all/MosFet/MosFet.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Write a signal to a MosFet transistor using a Potentiometer. 3 | 4 | created in Aug 2018 by D. Cuartielles 5 | based on work by M. Loglio (2013) 6 | 7 | This example code is in the public domain. 8 | */ 9 | 10 | // include the EduIntro library 11 | #include 12 | 13 | MosFet mos(D3); //create the mos object on pin D3 14 | Potentiometer pot(A0); //create the pot object on pin A0 15 | 16 | void setup() { 17 | //nothing here 18 | } 19 | 20 | void loop() 21 | { 22 | int val = pot.read(); //assign to a "val" variable 23 | //the potentiometer values 24 | 25 | mos.write(val); //assign the values to the mosfet 26 | 27 | delay(10); //rest for 10 milliseconds. 28 | } 29 | -------------------------------------------------------------------------------- /examples/by_board/all/PIR/PIR.ino: -------------------------------------------------------------------------------- 1 | /* 2 | PIR 3 | 4 | Changes the behavior between on and off an LED when a PIR sensor is activated. 5 | Assumes the use of a PIR sensor that needs no pull-up 6 | 7 | This example code is in the public domain. 8 | 9 | created in Feb 2019 by D. Cuartielles 10 | based on work by F. Vanzati (2011) and M. Loglio (2013) 11 | */ 12 | 13 | // include the EduIntro library 14 | #include 15 | 16 | PIR pir(D7); // creating the object 'pir' on pin D7 17 | 18 | Led led(D10); // creating the object 'led' on pin D10 19 | 20 | 21 | void setup() { 22 | //nothing here 23 | } 24 | 25 | void loop() 26 | { 27 | // check the state of the PIR sensor 28 | // if you just want to detect the turn from not active to active 29 | // use pir.activated() instead 30 | if (pir.active() == HIGH) { 31 | led.on(); 32 | } 33 | else { 34 | led.off(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /examples/by_board/all/PIRStates/PIRStates.ino: -------------------------------------------------------------------------------- 1 | /* 2 | PIRStates 3 | 4 | Test the different PIR methods: activated, deactivated, active, 5 | readSwitch, hadActivity, and resetActivity 6 | 7 | This example code is in the public domain. 8 | 9 | created in Feb 2019 by D. Cuartielles 10 | based on work by F. Vanzati (2011) and M. Loglio (2013) 11 | */ 12 | 13 | #include 14 | 15 | PIR pir(D7); 16 | 17 | void setup() 18 | { 19 | // we are going to use the serial communication as a 20 | // way to see on the PC what is happening on the Arduino 21 | Serial.begin(9600); 22 | } 23 | 24 | void loop() 25 | { 26 | if(pir.activated()) 27 | Serial.println("activited"); 28 | if(pir.active()) 29 | Serial.println("still active"); 30 | if(pir.deactivated()) { 31 | Serial.println("deactivated"); 32 | Serial.print("switch: "); 33 | Serial.println(pir.readSwitch()); 34 | } 35 | if(!pir.activated() && pir.hadActivity()) { 36 | Serial.print("had activity: "); 37 | Serial.println(pir.hadActivity()); 38 | pir.resetActivity(); 39 | } 40 | 41 | delay(500); 42 | } 43 | -------------------------------------------------------------------------------- /examples/by_board/all/PhysicalPixel/PhysicalPixel.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Physical Pixel 3 | 4 | An example of using the Arduino board to receive data from the computer. In 5 | this case, the Arduino boards turns on an LED when it receives the character 6 | 'H', and turns off the LED when it receives the character 'L'. 7 | 8 | The data can be sent from the Arduino Serial Monitor, or another program like 9 | Processing (see code below), Flash (via a serial-net proxy), PD, or Max/MSP. 10 | 11 | The circuit: 12 | - LED connected from digital pin 13 to ground 13 | 14 | created in Aug 2018 by D. Cuartielles 15 | based on work by D. Mellis (2006), T. Igoe and S. Fitzgerald (2011) 16 | 17 | This example code is in the public domain. 18 | */ 19 | 20 | #include 21 | 22 | Led led(D13); 23 | 24 | int incomingByte; // a variable to read incoming serial data 25 | 26 | void setup() 27 | { 28 | Serial.begin(9600); 29 | } 30 | 31 | 32 | void loop() { 33 | // see if there's incoming serial data: 34 | if (Serial.available() > 0) { 35 | 36 | // read the oldest byte in the serial buffer: 37 | incomingByte = Serial.read(); 38 | 39 | // if it's a capital H (ASCII 72), turn on the LED: 40 | if (incomingByte == 'H') { 41 | led.on(); 42 | } 43 | // if it's an L (ASCII 76) turn off the LED: 44 | if (incomingByte == 'L') { 45 | led.off(); 46 | } 47 | 48 | if (incomingByte == 'S') { 49 | Serial.println(led.state(), DEC); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /examples/by_board/all/Potentiometer/Potentiometer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Read the value of a Potentiometer connected to A0, 3 | then uses the results to write the brightness on 4 | an LED connected on D10. Also prints the values 5 | on the serial monitor. 6 | 7 | created in Aug 2018 by D. Cuartielles 8 | based on work by T. Igoe (2008, 2010), D. Gomba (2010), F. Vanzati (2011) and M. Loglio (2013) 9 | 10 | This example code is in the public domain. 11 | */ 12 | 13 | #include 14 | 15 | Potentiometer pot(A0); // creating the object 'pot' on pin A0 16 | 17 | Led led(D10); // creating the object 'led' on pin D10 18 | 19 | int brightnessVal = 0; // value read from the pot 20 | 21 | void setup() { 22 | // initialize serial communications at 9600 bps 23 | Serial.begin(9600); 24 | } 25 | 26 | void loop() { 27 | // read the potentiometer's value: 28 | brightnessVal = pot.read(); 29 | 30 | // set the led brightness 31 | led.brightness(brightnessVal); 32 | 33 | // print the results to the serial monitor: 34 | Serial.print("brightness = " ); 35 | Serial.println(brightnessVal); 36 | 37 | 38 | // wait 10 milliseconds before the next loop 39 | delay(10); 40 | } 41 | -------------------------------------------------------------------------------- /examples/by_board/all/Relay/Relay.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Relay 3 | 4 | Turns on and off a Relay connected to D10, when pressing a 5 | Button attached to D7. 6 | 7 | This example code is in the public domain. 8 | 9 | created in Aug 2018 by D. Cuartielles 10 | based on work by F. Vanzati (2011) and M. Loglio (2013) 11 | 12 | This example code is in the public domain. 13 | */ 14 | 15 | // include the EduIntro library 16 | #include 17 | 18 | Button btn(D7); // creating the object 'button' on pin D7 19 | 20 | Relay relay(D10); // creating the object 'relay' on pin D10 21 | 22 | void setup() { 23 | // nothing to add here 24 | } 25 | 26 | void loop() 27 | { 28 | // check the switch state 29 | if(btn.readSwitch() == HIGH) { 30 | relay.on(); 31 | } 32 | else{ 33 | relay.off(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /examples/by_board/all/RisingDecreasing/RisingDecreasing.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Increasing & Decreasing 3 | 4 | this sketch shows how to use increasing() and 5 | decreasing() on analog inputs. 6 | 7 | increasing() returns HIGH when values are rising, 8 | decreasing() is HIGH when values are decreasing 9 | 10 | created in Aug 2018 by D. Cuartielles 11 | based on work by M. Loglio (2013) 12 | 13 | This example code is in the public domain. 14 | */ 15 | 16 | // include the EduIntro library 17 | #include 18 | 19 | Thermistor therm(A0); // creating the object 'therm' on pin A0 20 | 21 | void setup() 22 | { 23 | // initialize serial communications at 9600 bps 24 | Serial.begin(9600); 25 | } 26 | 27 | void loop() 28 | { 29 | if (therm.increasing()) Serial.println("increasing"); 30 | if (therm.decreasing()) Serial.println("decreasing"); 31 | delay(50); 32 | } 33 | -------------------------------------------------------------------------------- /examples/by_board/all/Servo/Servo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Servo 3 | 4 | Makes a Servo change angle after some time. 5 | 6 | This example code is in the public domain. 7 | 8 | created in Aug 2018 by D. Cuartielles 9 | 10 | based on http://www.arduino.cc/en/Tutorial/Button 11 | */ 12 | 13 | // include the EduIntro library 14 | #include 15 | 16 | ServoMotor servo(D10); // creating the object 'servo' on pin D10 17 | 18 | 19 | void setup() { 20 | //nothing here 21 | } 22 | 23 | void loop() 24 | { 25 | servo.write(90); 26 | delay (1000); // wait for a second 27 | servo.write(0); 28 | delay (1000); // wait for a second 29 | } 30 | -------------------------------------------------------------------------------- /examples/by_board/all/ServoButton/ServoButton.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Makes a Servo change angle when pressing a Button. 3 | 4 | This example code is in the public domain. 5 | 6 | created in Aug 2018 by D. Cuartielles 7 | 8 | based on http://www.arduino.cc/en/Tutorial/Button 9 | */ 10 | 11 | // include the EduIntro library 12 | #include 13 | 14 | Button button(D7); // creating the object 'button' on pin D7 15 | 16 | ServoMotor servo(D10); // creating the object 'servo' on pin D10 17 | 18 | 19 | void setup() { 20 | //nothing here 21 | } 22 | 23 | void loop() 24 | { 25 | // check the switchState of the button 26 | // each time it is pressed, it toggles the servo's position 27 | // when LOW, light should go on 28 | if (button.readSwitch() == LOW) { 29 | servo.write(90); 30 | } 31 | else { 32 | servo.write(0); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /examples/by_board/all/ServoKnob/ServoKnob.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Makes a Servo change angle when turning a potentiometer. 3 | 4 | This example code is in the public domain. 5 | 6 | created in Feb 2019 by D. Cuartielles 7 | 8 | based on https://www.arduino.cc/en/tutorial/knob 9 | */ 10 | 11 | // include the EduIntro library 12 | #include 13 | 14 | Potentiometer pot(A0); // creating the object 'pot' on pin A0 15 | 16 | ServoMotor servo(D10); // creating the object 'servo' on pin D10 17 | 18 | int potVal = 0; // value read from the pot 19 | int angleVal = 0; // value of the angle to set the servo 20 | 21 | void setup() { 22 | // initialize serial communications at 9600 bps 23 | Serial.begin(9600); 24 | } 25 | 26 | void loop() 27 | { 28 | // read the potentiometer's value: 29 | potVal = pot.read(); 30 | 31 | // map the data from the sensor (0..1023) to 32 | // one the servo can take (0..180) 33 | angleVal = map(potVal, 0, 1023, 0, 180); 34 | 35 | // set the led brightness 36 | servo.write(angleVal); 37 | 38 | // print the results to the serial monitor: 39 | Serial.print("angle = " ); 40 | Serial.println(angleVal); 41 | 42 | 43 | // wait 100 milliseconds before the next loop 44 | delay(100); 45 | } 46 | -------------------------------------------------------------------------------- /examples/by_board/all/ServoKnobContinuous/ServoKnobContinuous.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Makes a Continuous Servo change speed when turning a potentiometer. 3 | Prints the different motor states to the serial port. 4 | 5 | This example code is in the public domain. 6 | 7 | created in Feb 2019 by D. Cuartielles 8 | 9 | based on https://www.arduino.cc/en/tutorial/knob 10 | */ 11 | 12 | // include the EduIntro library 13 | #include 14 | 15 | Potentiometer pot(A0); // creating the object 'pot' on pin A0 16 | 17 | ServoMotor servo(D10); // creating the object 'servo' on pin D10 18 | 19 | int potVal = 0; // value read from the pot 20 | int angleVal = 0; // value of the angle to set the servo 21 | 22 | void setup() { 23 | // initialize serial communications at 9600 bps 24 | Serial.begin(9600); 25 | } 26 | 27 | void loop() 28 | { 29 | // read the potentiometer's value: 30 | potVal = pot.read(); 31 | 32 | // map the data from the sensor (0..1023) to 33 | // one the servo can take (0..180) 34 | angleVal = map(potVal, 0, 1023, 0, 180); 35 | 36 | // set the led brightness 37 | servo.write(angleVal); 38 | 39 | // Signify it different events for the motor 40 | if (angleVal == 90) 41 | Serial.println("Motor Stop"); 42 | if (angleVal <= 1) 43 | Serial.println("Motor Max clockwise"); 44 | if (angleVal >= 179) 45 | Serial.println("Motor Max counter clockwise"); 46 | 47 | // print the results to the serial monitor: 48 | Serial.print("angle = " ); 49 | Serial.println(angleVal); 50 | 51 | 52 | // wait 100 milliseconds before the next loop 53 | delay(100); 54 | } 55 | -------------------------------------------------------------------------------- /examples/by_board/all/Thermistor/Thermistor.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Thermistor hooked up on pin A0. 3 | 4 | Three values are displayed on the Serial Monitor every second: 5 | - the value between 0 and 1023 that represent the Analog Input reading 6 | - the temperature expressed in Celsius degrees 7 | - the temperature expressed in Fahrenheit dedegrees 8 | 9 | created in Aug 2018 by D. Cuartielles 10 | based on work by F. Vanzati (2011) and M. Loglio (2013) 11 | 12 | This example code is in the public domain. 13 | */ 14 | 15 | // include the EduIntro library 16 | #include 17 | 18 | Thermistor therm(A0); // creating the object 'therm' on pin A0 19 | 20 | float C, F; // temperature readings are returned in float format 21 | 22 | void setup() 23 | { 24 | // initialize serial communications at 9600 bps 25 | Serial.begin(9600); 26 | } 27 | 28 | void loop() 29 | { 30 | C = therm.readCelsius(); // Reading the temperature in Celsius degrees and store in the C variable 31 | F = therm.readFahrenheit(); // Reading the temperature in Fahrenheit degrees and store in the F variable 32 | 33 | // Print the collected data in a row on the Serial Monitor 34 | Serial.print("Analog reading: "); // Reading the analog value from the thermistor 35 | Serial.print(therm.read()); 36 | Serial.print("\tC: "); 37 | Serial.print(C); 38 | Serial.print("\tF: "); 39 | Serial.println(F); 40 | 41 | delay(1000); // Wait one second before get another temperature reading 42 | } 43 | -------------------------------------------------------------------------------- /examples/by_topic/Blink/Blink.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Blink 3 | 4 | based on Blink, Arduino's "Hello World!" 5 | Turns on an LED on for one second, then off for one second, repeatedly. 6 | 7 | created in Aug 2018 by D. Cuartielles 8 | based on work by F. Vanzati (2011) 9 | 10 | This example code is in the public domain. 11 | */ 12 | 13 | // include the EduIntro library 14 | #include 15 | 16 | Led led(D10); // creating the object 'led' on pin D10 17 | 18 | void setup() { 19 | //nothing here 20 | } 21 | 22 | void loop() 23 | { 24 | led.on(); // set the LED on 25 | delay(1000); // wait for a second 26 | led.off(); // set the LED off 27 | delay(1000); // wait for a second 28 | } 29 | -------------------------------------------------------------------------------- /examples/by_topic/Button/Button.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Button 3 | 4 | Changes the behavior between on and off an LED when pressing a Button. 5 | 6 | This example code is in the public domain. 7 | 8 | created in Aug 2018 by D. Cuartielles 9 | based on work by F. Vanzati (2011) and M. Loglio (2013) 10 | 11 | based on http://www.arduino.cc/en/Tutorial/Button 12 | */ 13 | 14 | // include the EduIntro library 15 | #include 16 | 17 | Button button(D7); // creating the object 'button' on pin D7 18 | 19 | Led led(D10); // creating the object 'led' on pin D10 20 | 21 | 22 | void setup() { 23 | //nothing here 24 | } 25 | 26 | void loop() 27 | { 28 | // check the switchState of the button 29 | // each time it is pressed, it toggles the LED 30 | // when LOW, light should go on 31 | if (button.readSwitch() == LOW) { 32 | led.on(); 33 | } 34 | else { 35 | led.off(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /examples/by_topic/ButtonStates/ButtonStates.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ButtonStates 3 | 4 | Test the different Button methods: pressed, released, held 5 | and getSwitch. 6 | 7 | This example code is in the public domain. 8 | 9 | created in Aug 2018 by D. Cuartielles 10 | based on work by F. Vanzati (2011) and M. Loglio (2013) 11 | */ 12 | 13 | #include 14 | 15 | Button btn(D7); 16 | 17 | void setup() 18 | { 19 | // we are going to use the serial communication as a 20 | // way to see on the PC what is happening on the Arduino 21 | Serial.begin(9600); 22 | } 23 | 24 | void loop() 25 | { 26 | if(btn.pressed()) 27 | Serial.println("pressed"); 28 | if(btn.held()) 29 | Serial.println("held"); 30 | if(btn.released()) { 31 | Serial.println("released"); 32 | Serial.print("switch: "); 33 | Serial.println(btn.readSwitch()); 34 | } 35 | 36 | delay(50); 37 | } 38 | -------------------------------------------------------------------------------- /examples/by_topic/DHT11/DHT11.ino: -------------------------------------------------------------------------------- 1 | /* 2 | DHT11 3 | 4 | This example reads a DHT11 sensor hooked up on pin D7. Reads both 5 | temperature and humidity and sends it to the Serial port 6 | 7 | created in Feb 2019 by D. Cuartielles 8 | based on work by F. Vanzati (2011) and M. Loglio (2013) 9 | 10 | This example code is in the public domain. 11 | */ 12 | 13 | // include the EduIntro library 14 | #include 15 | 16 | DHT11 dht11(D7); // creating the object sensor on pin 'D7' 17 | 18 | int C; // temperature C readings are integers 19 | float F; // temperature F readings are returned in float format 20 | int H; // humidity readings are integers 21 | 22 | void setup() 23 | { 24 | // initialize serial communications at 9600 bps 25 | Serial.begin(9600); 26 | } 27 | 28 | void loop() 29 | { 30 | dht11.update(); 31 | 32 | C = dht11.readCelsius(); // Reading the temperature in Celsius degrees and store in the C variable 33 | F = dht11.readFahrenheit(); // Reading the temperature in Fahrenheit degrees and store in the F variable 34 | H = dht11.readHumidity(); // Reading the humidity index 35 | 36 | // Print the collected data in a row on the Serial Monitor 37 | Serial.print("H: "); 38 | Serial.print(H); 39 | Serial.print("\tC: "); 40 | Serial.print(C); 41 | Serial.print("\tF: "); 42 | Serial.println(F); 43 | 44 | delay(1000); // Wait one second before get another temperature reading 45 | } 46 | -------------------------------------------------------------------------------- /examples/by_topic/Empty/Empty.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void setup() { 4 | //Serial.begin(9600); 5 | } 6 | 7 | void loop() { 8 | 9 | } -------------------------------------------------------------------------------- /examples/by_topic/LM35/LM35.ino: -------------------------------------------------------------------------------- 1 | /* 2 | LM35 3 | 4 | This example uses an LM35 (or equivalent) sensor hooked up on pin A0. 5 | 6 | Three values are displayed on the Serial Monitor every second: 7 | - the value between 0 and 1023 that represent the Analog Input reading 8 | - the temperature expressed in Celsius degrees 9 | - the temperature expressed in Fahrenheit dedegrees 10 | 11 | created in Feb 2019 by D. Cuartielles 12 | based on work by F. Vanzati (2011) and M. Loglio (2013) 13 | 14 | This example code is in the public domain. 15 | */ 16 | 17 | // include the EduIntro library 18 | #include 19 | 20 | LM35 lm35(A0); // creating the object 'lm35' on pin A0 21 | 22 | float C, F; // temperature readings are returned in float format 23 | 24 | void setup() 25 | { 26 | // initialize serial communications at 9600 bps 27 | Serial.begin(9600); 28 | } 29 | 30 | void loop() 31 | { 32 | C = lm35.readCelsius(); // Reading the temperature in Celsius degrees and store in the C variable 33 | F = lm35.readFahrenheit(); // Reading the temperature in Fahrenheit degrees and store in the F variable 34 | 35 | // Print the collected data in a row on the Serial Monitor 36 | Serial.print("Analog reading: "); // Reading the analog value from the thermistor 37 | Serial.print(lm35.read()); 38 | Serial.print("\tC: "); 39 | Serial.print(C); 40 | Serial.print("\tF: "); 41 | Serial.println(F); 42 | 43 | delay(1000); // Wait one second before get another temperature reading 44 | } 45 | -------------------------------------------------------------------------------- /examples/by_topic/LightSensor/LightSensor.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Read values from an LDR Analog Sensor connected to A0, 3 | then uses the result to set the brightness on an LED 4 | connected on D9. Also prints the values on the 5 | serial monitor. 6 | 7 | created in Aug 2018 by D. Cuartielles 8 | based on work by T. Igoe (2010), D. Gomba (2010), F. Vanzati (2011) and M. Loglio (2013) 9 | 10 | This example code is in the public domain. 11 | */ 12 | 13 | #include 14 | 15 | LightSensor ldr(A0); //create the "ldr" object on pin A0 16 | 17 | Led led(D10); //create the "led" object on pin D10 18 | 19 | void setup() { 20 | // initialize serial communications at 9600 bps 21 | Serial.begin(9600); 22 | } 23 | 24 | void loop() { 25 | // store the ldr values into a variable called brightnessVal 26 | int brightnessVal = ldr.read(); 27 | 28 | // set the led brightness 29 | led.brightness(brightnessVal); 30 | 31 | //to have it at full brightness 32 | //when it's dark, uncomment this line: 33 | //led.brightness(1023 - brightnessVal); 34 | 35 | // print the results to the serial monitor: 36 | Serial.print("brightness = " ); 37 | Serial.println(brightnessVal); 38 | 39 | 40 | // wait 10 milliseconds before the next loop 41 | delay(10); 42 | } 43 | -------------------------------------------------------------------------------- /examples/by_topic/Melody/Melody.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Melody 3 | 4 | Plays a song stored in an array, repeatedly. You should connect 5 | a speaker to pin D10 6 | 7 | created in Aug 2018 by D. Cuartielles 8 | 9 | This example code is in the public domain. 10 | */ 11 | 12 | // include the EduIntro library 13 | #include 14 | 15 | // define the song as (note, duration) pairs 16 | // note durations: 4 = quarter note, 8 = eighth note, etc.: 17 | int melody[] = { NOTE_C4, 4, 18 | NOTE_G3, 8, 19 | NOTE_G3, 8, 20 | NOTE_A3, 4, 21 | NOTE_G3, 4, 22 | SILENCE, 4, 23 | NOTE_B3, 4, 24 | NOTE_C4, 4 }; 25 | 26 | Piezo piezo(D10); // creating the object 'piezo' on pin D10 27 | 28 | void setup() { 29 | //nothing here 30 | } 31 | 32 | void loop() 33 | { 34 | piezo.play(melody); // play the song 35 | delay(1000); // wait for a second 36 | } 37 | -------------------------------------------------------------------------------- /examples/by_topic/MelodyButton/MelodyButton.ino: -------------------------------------------------------------------------------- 1 | /* 2 | MelodyButton 3 | 4 | Plays a song stored in an array, when pressing a button. You should connect 5 | a speaker to pin D10 and a button to pin D7 6 | 7 | created in Aug 2018 by D. Cuartielles 8 | 9 | This example code is in the public domain. 10 | */ 11 | 12 | // include the EduIntro library 13 | #include 14 | 15 | // define the song as (note, duration) pairs 16 | // note durations: 4 = quarter note, 8 = eighth note, etc.: 17 | int melody[] = { NOTE_C4, 4, 18 | NOTE_G3, 8, 19 | NOTE_G3, 8, 20 | NOTE_A3, 4, 21 | NOTE_G3, 4, 22 | SILENCE, 4, 23 | NOTE_B3, 4, 24 | NOTE_C4, 4 }; 25 | 26 | Button button(D7); // creating the object 'button' on pin D7 27 | 28 | Piezo piezo(D10); // creating the object 'piezo' on pin D10 29 | 30 | void setup() { 31 | //nothing here 32 | } 33 | 34 | void loop() 35 | { 36 | // if the button was just pressed, play melody 37 | if (button.pressed()) { 38 | piezo.play(melody); // play the song 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /examples/by_topic/MelodyButtonTwoSounds/MelodyButtonTwoSounds.ino: -------------------------------------------------------------------------------- 1 | /* 2 | MelodyButtonTwoSounds 3 | 4 | Plays a song stored in an array, when pressing a button, a different one 5 | when releasing the button. You should connect a speaker to pin D10 and a 6 | button to pin D7. Melodies are stored in arrays ending with NULL 7 | 8 | created in Apr 2019 by D. Cuartielles 9 | 10 | This example code is in the public domain. 11 | */ 12 | 13 | // include the EduIntro library 14 | #include 15 | 16 | // define the song as (note, duration) pairs 17 | // note durations: 4 = quarter note, 8 = eighth note, etc. 18 | // add the NULL to signify the end of the array 19 | int melody1[] = { NOTE_C4, 4, 20 | NOTE_G3, 8, 21 | NOTE_G3, 8, 22 | SILENCE, 4, NULL}; 23 | 24 | int melody2[] = { NOTE_D4, 4, 25 | NOTE_C3, 8, 26 | NOTE_F3, 8, 27 | SILENCE, 4, NULL}; 28 | 29 | Button button(D7);// creating the object 'button' on pin D7 30 | 31 | Piezo piezo(D10);// creating the object 'piezo' on pin D10 32 | 33 | void setup() { 34 | //nothing here 35 | } 36 | 37 | void loop() 38 | { 39 | // if the button was just pressed, play melody 40 | if (button.pressed()) { 41 | piezo.play (melody1); 42 | } 43 | if (button.released()) { 44 | piezo.play (melody2); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /examples/by_topic/MosFet/MosFet.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Write a signal to a MosFet transistor using a Potentiometer. 3 | 4 | created in Aug 2018 by D. Cuartielles 5 | based on work by M. Loglio (2013) 6 | 7 | This example code is in the public domain. 8 | */ 9 | 10 | // include the EduIntro library 11 | #include 12 | 13 | MosFet mos(D3); //create the mos object on pin D3 14 | Potentiometer pot(A0); //create the pot object on pin A0 15 | 16 | void setup() { 17 | //nothing here 18 | } 19 | 20 | void loop() 21 | { 22 | int val = pot.read(); //assign to a "val" variable 23 | //the potentiometer values 24 | 25 | mos.write(val); //assign the values to the mosfet 26 | 27 | delay(10); //rest for 10 milliseconds. 28 | } 29 | -------------------------------------------------------------------------------- /examples/by_topic/PIR/PIR.ino: -------------------------------------------------------------------------------- 1 | /* 2 | PIR 3 | 4 | Changes the behavior between on and off an LED when a PIR sensor is activated. 5 | Assumes the use of a PIR sensor that needs no pull-up 6 | 7 | This example code is in the public domain. 8 | 9 | created in Feb 2019 by D. Cuartielles 10 | based on work by F. Vanzati (2011) and M. Loglio (2013) 11 | */ 12 | 13 | // include the EduIntro library 14 | #include 15 | 16 | PIR pir(D7); // creating the object 'pir' on pin D7 17 | 18 | Led led(D10); // creating the object 'led' on pin D10 19 | 20 | 21 | void setup() { 22 | //nothing here 23 | } 24 | 25 | void loop() 26 | { 27 | // check the state of the PIR sensor 28 | // if you just want to detect the turn from not active to active 29 | // use pir.activated() instead 30 | if (pir.active() == HIGH) { 31 | led.on(); 32 | } 33 | else { 34 | led.off(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /examples/by_topic/PIRStates/PIRStates.ino: -------------------------------------------------------------------------------- 1 | /* 2 | PIRStates 3 | 4 | Test the different PIR methods: activated, deactivated, active, 5 | readSwitch, hadActivity, and resetActivity 6 | 7 | This example code is in the public domain. 8 | 9 | created in Feb 2019 by D. Cuartielles 10 | based on work by F. Vanzati (2011) and M. Loglio (2013) 11 | */ 12 | 13 | #include 14 | 15 | PIR pir(D7); 16 | 17 | void setup() 18 | { 19 | // we are going to use the serial communication as a 20 | // way to see on the PC what is happening on the Arduino 21 | Serial.begin(9600); 22 | } 23 | 24 | void loop() 25 | { 26 | if(pir.activated()) 27 | Serial.println("activited"); 28 | if(pir.active()) 29 | Serial.println("still active"); 30 | if(pir.deactivated()) { 31 | Serial.println("deactivated"); 32 | Serial.print("switch: "); 33 | Serial.println(pir.readSwitch()); 34 | } 35 | if(!pir.activated() && pir.hadActivity()) { 36 | Serial.print("had activity: "); 37 | Serial.println(pir.hadActivity()); 38 | pir.resetActivity(); 39 | } 40 | 41 | delay(500); 42 | } 43 | -------------------------------------------------------------------------------- /examples/by_topic/PhysicalPixel/PhysicalPixel.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Physical Pixel 3 | 4 | An example of using the Arduino board to receive data from the computer. In 5 | this case, the Arduino boards turns on an LED when it receives the character 6 | 'H', and turns off the LED when it receives the character 'L'. 7 | 8 | The data can be sent from the Arduino Serial Monitor, or another program like 9 | Processing (see code below), Flash (via a serial-net proxy), PD, or Max/MSP. 10 | 11 | The circuit: 12 | - LED connected from digital pin 13 to ground 13 | 14 | created in Aug 2018 by D. Cuartielles 15 | based on work by D. Mellis (2006), T. Igoe and S. Fitzgerald (2011) 16 | 17 | This example code is in the public domain. 18 | */ 19 | 20 | #include 21 | 22 | Led led(D13); 23 | 24 | int incomingByte; // a variable to read incoming serial data 25 | 26 | void setup() 27 | { 28 | Serial.begin(9600); 29 | } 30 | 31 | 32 | void loop() { 33 | // see if there's incoming serial data: 34 | if (Serial.available() > 0) { 35 | 36 | // read the oldest byte in the serial buffer: 37 | incomingByte = Serial.read(); 38 | 39 | // if it's a capital H (ASCII 72), turn on the LED: 40 | if (incomingByte == 'H') { 41 | led.on(); 42 | } 43 | // if it's an L (ASCII 76) turn off the LED: 44 | if (incomingByte == 'L') { 45 | led.off(); 46 | } 47 | 48 | if (incomingByte == 'S') { 49 | Serial.println(led.state(), DEC); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /examples/by_topic/Potentiometer/Potentiometer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Read the value of a Potentiometer connected to A0, 3 | then uses the results to write the brightness on 4 | an LED connected on D10. Also prints the values 5 | on the serial monitor. 6 | 7 | created in Aug 2018 by D. Cuartielles 8 | based on work by T. Igoe (2008, 2010), D. Gomba (2010), F. Vanzati (2011) and M. Loglio (2013) 9 | 10 | This example code is in the public domain. 11 | */ 12 | 13 | #include 14 | 15 | Potentiometer pot(A0); // creating the object 'pot' on pin A0 16 | 17 | Led led(D10); // creating the object 'led' on pin D10 18 | 19 | int brightnessVal = 0; // value read from the pot 20 | 21 | void setup() { 22 | // initialize serial communications at 9600 bps 23 | Serial.begin(9600); 24 | } 25 | 26 | void loop() { 27 | // read the potentiometer's value: 28 | brightnessVal = pot.read(); 29 | 30 | // set the led brightness 31 | led.brightness(brightnessVal); 32 | 33 | // print the results to the serial monitor: 34 | Serial.print("brightness = " ); 35 | Serial.println(brightnessVal); 36 | 37 | 38 | // wait 10 milliseconds before the next loop 39 | delay(10); 40 | } 41 | -------------------------------------------------------------------------------- /examples/by_topic/Relay/Relay.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Relay 3 | 4 | Turns on and off a Relay connected to D10, when pressing a 5 | Button attached to D7. 6 | 7 | This example code is in the public domain. 8 | 9 | created in Aug 2018 by D. Cuartielles 10 | based on work by F. Vanzati (2011) and M. Loglio (2013) 11 | 12 | This example code is in the public domain. 13 | */ 14 | 15 | // include the EduIntro library 16 | #include 17 | 18 | Button btn(D7); // creating the object 'button' on pin D7 19 | 20 | Relay relay(D10); // creating the object 'relay' on pin D10 21 | 22 | void setup() { 23 | // nothing to add here 24 | } 25 | 26 | void loop() 27 | { 28 | // check the switch state 29 | if(btn.readSwitch() == HIGH) { 30 | relay.on(); 31 | } 32 | else{ 33 | relay.off(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /examples/by_topic/RisingDecreasing/RisingDecreasing.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Increasing & Decreasing 3 | 4 | this sketch shows how to use increasing() and 5 | decreasing() on analog inputs. 6 | 7 | increasing() returns HIGH when values are rising, 8 | decreasing() is HIGH when values are decreasing 9 | 10 | created in Aug 2018 by D. Cuartielles 11 | based on work by M. Loglio (2013) 12 | 13 | This example code is in the public domain. 14 | */ 15 | 16 | // include the EduIntro library 17 | #include 18 | 19 | Thermistor therm(A0); // creating the object 'therm' on pin A0 20 | 21 | void setup() 22 | { 23 | // initialize serial communications at 9600 bps 24 | Serial.begin(9600); 25 | } 26 | 27 | void loop() 28 | { 29 | if (therm.increasing()) Serial.println("increasing"); 30 | if (therm.decreasing()) Serial.println("decreasing"); 31 | delay(50); 32 | } 33 | -------------------------------------------------------------------------------- /examples/by_topic/Servo/Servo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Servo 3 | 4 | Makes a Servo change angle after some time. 5 | 6 | This example code is in the public domain. 7 | 8 | created in Aug 2018 by D. Cuartielles 9 | 10 | based on http://www.arduino.cc/en/Tutorial/Button 11 | */ 12 | 13 | // include the EduIntro library 14 | #include 15 | 16 | ServoMotor servo(D10); // creating the object 'servo' on pin D10 17 | 18 | 19 | void setup() { 20 | //nothing here 21 | } 22 | 23 | void loop() 24 | { 25 | servo.write(90); 26 | delay (1000); // wait for a second 27 | servo.write(0); 28 | delay (1000); // wait for a second 29 | } 30 | -------------------------------------------------------------------------------- /examples/by_topic/ServoButton/ServoButton.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Makes a Servo change angle when pressing a Button. 3 | 4 | This example code is in the public domain. 5 | 6 | created in Aug 2018 by D. Cuartielles 7 | 8 | based on http://www.arduino.cc/en/Tutorial/Button 9 | */ 10 | 11 | // include the EduIntro library 12 | #include 13 | 14 | Button button(D7); // creating the object 'button' on pin D7 15 | 16 | ServoMotor servo(D10); // creating the object 'servo' on pin D10 17 | 18 | 19 | void setup() { 20 | //nothing here 21 | } 22 | 23 | void loop() 24 | { 25 | // check the switchState of the button 26 | // each time it is pressed, it toggles the servo's position 27 | // when LOW, light should go on 28 | if (button.readSwitch() == LOW) { 29 | servo.write(90); 30 | } 31 | else { 32 | servo.write(0); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /examples/by_topic/ServoKnob/ServoKnob.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Makes a Servo change angle when turning a potentiometer. 3 | 4 | This example code is in the public domain. 5 | 6 | created in Feb 2019 by D. Cuartielles 7 | 8 | based on https://www.arduino.cc/en/tutorial/knob 9 | */ 10 | 11 | // include the EduIntro library 12 | #include 13 | 14 | Potentiometer pot(A0); // creating the object 'pot' on pin A0 15 | 16 | ServoMotor servo(D10); // creating the object 'servo' on pin D10 17 | 18 | int potVal = 0; // value read from the pot 19 | int angleVal = 0; // value of the angle to set the servo 20 | 21 | void setup() { 22 | // initialize serial communications at 9600 bps 23 | Serial.begin(9600); 24 | } 25 | 26 | void loop() 27 | { 28 | // read the potentiometer's value: 29 | potVal = pot.read(); 30 | 31 | // map the data from the sensor (0..1023) to 32 | // one the servo can take (0..180) 33 | angleVal = map(potVal, 0, 1023, 0, 180); 34 | 35 | // set the led brightness 36 | servo.write(angleVal); 37 | 38 | // print the results to the serial monitor: 39 | Serial.print("angle = " ); 40 | Serial.println(angleVal); 41 | 42 | 43 | // wait 100 milliseconds before the next loop 44 | delay(100); 45 | } 46 | -------------------------------------------------------------------------------- /examples/by_topic/ServoKnobContinuous/ServoKnobContinuous.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Makes a Continuous Servo change speed when turning a potentiometer. 3 | Prints the different motor states to the serial port. 4 | 5 | This example code is in the public domain. 6 | 7 | created in Feb 2019 by D. Cuartielles 8 | 9 | based on https://www.arduino.cc/en/tutorial/knob 10 | */ 11 | 12 | // include the EduIntro library 13 | #include 14 | 15 | Potentiometer pot(A0); // creating the object 'pot' on pin A0 16 | 17 | ServoMotor servo(D10); // creating the object 'servo' on pin D10 18 | 19 | int potVal = 0; // value read from the pot 20 | int angleVal = 0; // value of the angle to set the servo 21 | 22 | void setup() { 23 | // initialize serial communications at 9600 bps 24 | Serial.begin(9600); 25 | } 26 | 27 | void loop() 28 | { 29 | // read the potentiometer's value: 30 | potVal = pot.read(); 31 | 32 | // map the data from the sensor (0..1023) to 33 | // one the servo can take (0..180) 34 | angleVal = map(potVal, 0, 1023, 0, 180); 35 | 36 | // set the led brightness 37 | servo.write(angleVal); 38 | 39 | // Signify it different events for the motor 40 | if (angleVal == 90) 41 | Serial.println("Motor Stop"); 42 | if (angleVal <= 1) 43 | Serial.println("Motor Max clockwise"); 44 | if (angleVal >= 179) 45 | Serial.println("Motor Max counter clockwise"); 46 | 47 | // print the results to the serial monitor: 48 | Serial.print("angle = " ); 49 | Serial.println(angleVal); 50 | 51 | 52 | // wait 100 milliseconds before the next loop 53 | delay(100); 54 | } 55 | -------------------------------------------------------------------------------- /examples/by_topic/Thermistor/Thermistor.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Thermistor hooked up on pin A0. 3 | 4 | Three values are displayed on the Serial Monitor every second: 5 | - the value between 0 and 1023 that represent the Analog Input reading 6 | - the temperature expressed in Celsius degrees 7 | - the temperature expressed in Fahrenheit dedegrees 8 | 9 | created in Aug 2018 by D. Cuartielles 10 | based on work by F. Vanzati (2011) and M. Loglio (2013) 11 | 12 | This example code is in the public domain. 13 | */ 14 | 15 | // include the EduIntro library 16 | #include 17 | 18 | Thermistor therm(A0); // creating the object 'therm' on pin A0 19 | 20 | float C, F; // temperature readings are returned in float format 21 | 22 | void setup() 23 | { 24 | // initialize serial communications at 9600 bps 25 | Serial.begin(9600); 26 | } 27 | 28 | void loop() 29 | { 30 | C = therm.readCelsius(); // Reading the temperature in Celsius degrees and store in the C variable 31 | F = therm.readFahrenheit(); // Reading the temperature in Fahrenheit degrees and store in the F variable 32 | 33 | // Print the collected data in a row on the Serial Monitor 34 | Serial.print("Analog reading: "); // Reading the analog value from the thermistor 35 | Serial.print(therm.read()); 36 | Serial.print("\tC: "); 37 | Serial.print(C); 38 | Serial.print("\tF: "); 39 | Serial.println(F); 40 | 41 | delay(1000); // Wait one second before get another temperature reading 42 | } 43 | -------------------------------------------------------------------------------- /examples/courseware/cardboardKeyboard/ButtonStatesKeyboard/ButtonStatesKeyboard.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ButtonStates for Cardboard Keyboard 3 | 4 | This example code is in the public domain. 5 | 6 | created in Jan 2019 by D. Cuartielles 7 | based on work by F. Vanzati (2011) and M. Loglio (2013) 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | // reconfigure these pins to be the ones where you plug your wires 14 | byte btnPins[] = {D9, D10, D11, D12}; 15 | 16 | // which are the keys you will be using ... ? 17 | byte key[] = {'a', 'd', KEY_UP_ARROW, ' '}; 18 | 19 | // array to control the buttons 20 | Button btn[] = { 21 | Button(btnPins[0]), 22 | Button(btnPins[1]), 23 | Button(btnPins[2]), 24 | Button(btnPins[3]), 25 | }; 26 | 27 | void setup() 28 | { 29 | // we are going to use the serial communication as a 30 | // way to see on the PC what is happening on the Arduino 31 | Serial.begin(9600); 32 | 33 | // initialize the keyboard controller 34 | Keyboard.begin(); 35 | } 36 | 37 | void loop() 38 | { 39 | for (int i; i < 4; i ++) { 40 | if (btn[i].pressed()) { 41 | Serial.print("pressed pin: "); Serial.println(btnPins[i]); 42 | Keyboard.press(key[i]); 43 | } 44 | if (btn[i].held()) 45 | Serial.print("held pin: "); Serial.println(btnPins[i]); 46 | if (btn[i].released()) { 47 | Serial.print("released pin: "); Serial.println(btnPins[i]); 48 | Serial.print("switch pin "); Serial.print(btnPins[i]); Serial.print(": "); 49 | Serial.println(btn[i].readSwitch()); 50 | Keyboard.release(key[i]); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /examples/courseware/workshop_1h/Blink/Blink.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Blink 3 | 4 | based on Blink, Arduino's "Hello World!" 5 | Turns on an LED on for one second, then off for one second, repeatedly. 6 | 7 | created in Aug 2018 by D. Cuartielles 8 | based on work by F. Vanzati (2011) 9 | 10 | This example code is in the public domain. 11 | */ 12 | 13 | // include the EduIntro library 14 | #include 15 | 16 | Led led(D10); // creating the object 'led' on pin D10 17 | 18 | void setup() { 19 | //nothing here 20 | } 21 | 22 | void loop() 23 | { 24 | led.on(); // set the LED on 25 | delay(1000); // wait for a second 26 | led.off(); // set the LED off 27 | delay(1000); // wait for a second 28 | } 29 | -------------------------------------------------------------------------------- /examples/courseware/workshop_1h/Button/Button.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Button 3 | 4 | Changes the behavior between on and off an LED when pressing a Button. 5 | 6 | This example code is in the public domain. 7 | 8 | created in Aug 2018 by D. Cuartielles 9 | based on work by F. Vanzati (2011) and M. Loglio (2013) 10 | 11 | based on http://www.arduino.cc/en/Tutorial/Button 12 | */ 13 | 14 | // include the EduIntro library 15 | #include 16 | 17 | Button button(D7); // creating the object 'button' on pin D7 18 | 19 | Led led(D10); // creating the object 'led' on pin D10 20 | 21 | 22 | void setup() { 23 | //nothing here 24 | } 25 | 26 | void loop() 27 | { 28 | // check the switchState of the button 29 | // each time it is pressed, it toggles the LED 30 | // when LOW, light should go on 31 | if (button.readSwitch() == LOW) { 32 | led.on(); 33 | } 34 | else { 35 | led.off(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /examples/courseware/workshop_1h/ButtonStates/ButtonStates.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ButtonStates 3 | 4 | Test the different Button methods: pressed, released, held 5 | and getSwitch. 6 | 7 | This example code is in the public domain. 8 | 9 | created in Aug 2018 by D. Cuartielles 10 | based on work by F. Vanzati (2011) and M. Loglio (2013) 11 | */ 12 | 13 | #include 14 | 15 | Button btn(D7); 16 | 17 | void setup() 18 | { 19 | // we are going to use the serial communication as a 20 | // way to see on the PC what is happening on the Arduino 21 | Serial.begin(9600); 22 | } 23 | 24 | void loop() 25 | { 26 | if(btn.pressed()) 27 | Serial.println("pressed"); 28 | if(btn.held()) 29 | Serial.println("held"); 30 | if(btn.released()) { 31 | Serial.println("released"); 32 | Serial.print("switch: "); 33 | Serial.println(btn.readSwitch()); 34 | } 35 | 36 | delay(50); 37 | } 38 | -------------------------------------------------------------------------------- /examples/courseware/workshop_1h/Empty/Empty.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void setup() { 4 | //Serial.begin(9600); 5 | } 6 | 7 | void loop() { 8 | 9 | } -------------------------------------------------------------------------------- /examples/courseware/workshop_1h/Melody/Melody.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Melody 3 | 4 | Plays a song stored in an array, repeatedly. You should connect 5 | a speaker to pin D10 6 | 7 | created in Aug 2018 by D. Cuartielles 8 | 9 | This example code is in the public domain. 10 | */ 11 | 12 | // include the EduIntro library 13 | #include 14 | 15 | // define the song as (note, duration) pairs 16 | // note durations: 4 = quarter note, 8 = eighth note, etc.: 17 | int melody[] = { NOTE_C4, 4, 18 | NOTE_G3, 8, 19 | NOTE_G3, 8, 20 | NOTE_A3, 4, 21 | NOTE_G3, 4, 22 | SILENCE, 4, 23 | NOTE_B3, 4, 24 | NOTE_C4, 4 }; 25 | 26 | Piezo piezo(D10); // creating the object 'piezo' on pin D10 27 | 28 | void setup() { 29 | //nothing here 30 | } 31 | 32 | void loop() 33 | { 34 | piezo.play(melody); // play the song 35 | delay(1000); // wait for a second 36 | } 37 | -------------------------------------------------------------------------------- /examples/courseware/workshop_1h/MelodyButton/MelodyButton.ino: -------------------------------------------------------------------------------- 1 | /* 2 | MelodyButton 3 | 4 | Plays a song stored in an array, when pressing a button. You should connect 5 | a speaker to pin D10 and a button to pin D7 6 | 7 | created in Aug 2018 by D. Cuartielles 8 | 9 | This example code is in the public domain. 10 | */ 11 | 12 | // include the EduIntro library 13 | #include 14 | 15 | // define the song as (note, duration) pairs 16 | // note durations: 4 = quarter note, 8 = eighth note, etc.: 17 | int melody[] = { NOTE_C4, 4, 18 | NOTE_G3, 8, 19 | NOTE_G3, 8, 20 | NOTE_A3, 4, 21 | NOTE_G3, 4, 22 | SILENCE, 4, 23 | NOTE_B3, 4, 24 | NOTE_C4, 4 }; 25 | 26 | Button button(D7); // creating the object 'button' on pin D7 27 | 28 | Piezo piezo(D10); // creating the object 'piezo' on pin D10 29 | 30 | void setup() { 31 | //nothing here 32 | } 33 | 34 | void loop() 35 | { 36 | // if the button was just pressed, play melody 37 | if (button.pressed()) { 38 | piezo.play(melody); // play the song 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /examples/courseware/workshop_1h/Servo/Servo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Servo 3 | 4 | Makes a Servo change angle after some time. 5 | 6 | This example code is in the public domain. 7 | 8 | created in Aug 2018 by D. Cuartielles 9 | 10 | based on http://www.arduino.cc/en/Tutorial/Button 11 | */ 12 | 13 | // include the EduIntro library 14 | #include 15 | 16 | ServoMotor servo(D10); // creating the object 'servo' on pin D10 17 | 18 | 19 | void setup() { 20 | //nothing here 21 | } 22 | 23 | void loop() 24 | { 25 | servo.write(90); 26 | delay (1000); // wait for a second 27 | servo.write(0); 28 | delay (1000); // wait for a second 29 | } 30 | -------------------------------------------------------------------------------- /examples/courseware/workshop_1h/ServoButton/ServoButton.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Makes a Servo change angle when pressing a Button. 3 | 4 | This example code is in the public domain. 5 | 6 | created in Aug 2018 by D. Cuartielles 7 | 8 | based on http://www.arduino.cc/en/Tutorial/Button 9 | */ 10 | 11 | // include the EduIntro library 12 | #include 13 | 14 | Button button(D7); // creating the object 'button' on pin D7 15 | 16 | ServoMotor servo(D10); // creating the object 'servo' on pin D10 17 | 18 | 19 | void setup() { 20 | //nothing here 21 | } 22 | 23 | void loop() 24 | { 25 | // check the switchState of the button 26 | // each time it is pressed, it toggles the servo's position 27 | // when LOW, light should go on 28 | if (button.readSwitch() == LOW) { 29 | servo.write(90); 30 | } 31 | else { 32 | servo.write(0); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For EduLib 3 | ####################################### 4 | # Datatypes (KEYWORD1) 5 | ####################################### 6 | 7 | EduIntro KEYWORD1 EduIntro 8 | Led KEYWORD1 Led 9 | Button KEYWORD1 Button 10 | Potentiometer KEYWORD1 Potentiometer 11 | Piezo KEYWORD1 Piezo 12 | PIR KEYWORD1 PIR 13 | DHT11 KEYWORD1 DHT11 14 | LM35 KEYWORD1 LM35 15 | Thermistor KEYWORD1 Thermistor 16 | LightSensor KEYWORD1 LightSensor 17 | MosFet KEYWORD1 MosFet 18 | Relay KEYWORD1 Relay 19 | ServoMotor KEYWORD1 ServoMotor 20 | AnalogInput KEYWORD1 AnalogInput 21 | AnalogInput2 KEYWORD1 AnalogInput2 22 | DigitalInput KEYWORD1 DigitalInput 23 | Output KEYWORD1 Output 24 | Motion KEYWORD1 Motion 25 | WiFiComm KEYWORD1 WiFiComm 26 | 27 | ####################################### 28 | # Methods and Functions (KEYWORD2) 29 | ####################################### 30 | 31 | state KEYWORD2 32 | write KEYWORD2 33 | read KEYWORD2 34 | readRange KEYWORD2 35 | on KEYWORD2 36 | off KEYWORD2 37 | blink KEYWORD2 38 | readCelsius KEYWORD2 39 | readFahrenheit KEYWORD2 40 | readSwitch KEYWORD2 41 | pressed KEYWORD2 42 | held KEYWORD2 43 | released KEYWORD2 44 | brightness KEYWORD2 45 | fade KEYWORD2 46 | readX KEYWORD2 47 | readY KEYWORD2 48 | readXAxisRate KEYWORD2 49 | readYAxisRate KEYWORD2 50 | calibrate KEYWORD2 51 | readStep KEYWORD2 52 | inclination KEYWORD2 53 | polarity KEYWORD2 54 | increasing KEYWORD2 55 | decreasing KEYWORD2 56 | getStatus KEYWORD2 57 | getSSID KEYWORD2 58 | getIP KEYWORD2 59 | getClient KEYWORD2 60 | beep KEYWORD2 61 | play KEYWORD2 62 | noBeep KEYWORD2 63 | 64 | ####################################### 65 | # System Variables (KEYWORD2) 66 | ####################################### 67 | acc_x KEYWORD2 68 | acc_y KEYWORD2 69 | acc_z KEYWORD2 70 | gyro_x KEYWORD2 71 | gyro_y KEYWORD2 72 | gyro_z KEYWORD2 73 | 74 | ####################################### 75 | # Constants (LITERAL1) 76 | ####################################### 77 | D21 LITERAL1 78 | D20 LITERAL1 79 | D19 LITERAL1 80 | D18 LITERAL1 81 | D17 LITERAL1 82 | D16 LITERAL1 83 | D15 LITERAL1 84 | D14 LITERAL1 85 | D13 LITERAL1 86 | D12 LITERAL1 87 | D11 LITERAL1 88 | D10 LITERAL1 89 | D9 LITERAL1 90 | D8 LITERAL1 91 | D7 LITERAL1 92 | D6 LITERAL1 93 | D5 LITERAL1 94 | D4 LITERAL1 95 | D3 LITERAL1 96 | D2 LITERAL1 97 | D1 LITERAL1 98 | D0 LITERAL1 99 | 100 | A16 LITERAL1 101 | A15 LITERAL1 102 | A14 LITERAL1 103 | A13 LITERAL1 104 | A12 LITERAL1 105 | A11 LITERAL1 106 | A10 LITERAL1 107 | A9 LITERAL1 108 | A8 LITERAL1 109 | A7 LITERAL1 110 | A6 LITERAL1 111 | A5 LITERAL1 112 | A4 LITERAL1 113 | A3 LITERAL1 114 | A2 LITERAL1 115 | A1 LITERAL1 116 | A0 LITERAL1 117 | 118 | PULL_DOWN LITERAL1 119 | PULL_UP LITERAL1 120 | NORMAL LITERAL1 121 | INVERTED LITERAL1 122 | ANALOG_MAX LITERAL1 123 | 124 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "EduIntro", 3 | "frameworks": "Arduino", 4 | "keywords": "Introduction, Education, Workshop", 5 | "description": "Library for the Arduino Education Introduction Workshop series, includes examples for a broad range of sensors, courseware, and more. Optimized for collaboration.", 6 | "url": "https://github.com/arduino/Arduino_EduIntro", 7 | "downloadUrl": "https://github.com/arduino/Arduino_EduIntro/releases", 8 | "authors": 9 | { 10 | "name": "David Cuartielles", 11 | "maintainer": true 12 | }, 13 | "repository": 14 | { 15 | "type": "git", 16 | "url": "https://github.com/arduino/Arduino_EduIntro.git" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=EduIntro 2 | version=0.0.16 3 | author=Arduino LLC 4 | maintainer=David Cuartielles 5 | sentence=Library used for super-fast introduction workshops 6 | paragraph=Is intended to be used with Arduino UNO / MICRO / MEGA / NANO classic / NANO Every / NANO 33 BLE / NANO 33 IoT / MKR / WiFi REV2 and a set of basic components (led, button, piezo, LM35, thermistor, LDR, PIR, DHT11, and servo) as a way to introduce people to the basic aspects of Arduino during short workshops. 7 | category=Other 8 | url=https://www.arduino.cc 9 | architectures=* 10 | depends=Esplora, Arduino_LSM6DS3, WiFiNINA 11 | -------------------------------------------------------------------------------- /src/Button/Button.cpp: -------------------------------------------------------------------------------- 1 | #include "Button.h" 2 | #include "EduIntro.h" 3 | 4 | /* 5 | The button is considered to be using the chip's internal pull-up 6 | which means that by default, it should be HIGH; LOW when pressed 7 | */ 8 | Button::Button(uint8_t _pin) : DigitalInput(_pin, INPUT_PULLUP) 9 | { 10 | _toggleState = false; 11 | _oldState = HIGH; 12 | _pressedState = false; 13 | _releasedState = false; 14 | _heldState = false; 15 | _heldTime = 500; 16 | _debounceTime = 50; 17 | _pulltype = 1; // by default it is pullup 18 | _millisDebounceMark = millis(); 19 | } 20 | 21 | Button::Button(uint8_t _pin, uint8_t pulltype) : DigitalInput(_pin, INPUT) 22 | { 23 | _toggleState = false; 24 | _oldState = HIGH; 25 | _pressedState = false; 26 | _releasedState = false; 27 | _heldState = false; 28 | _heldTime = 500; 29 | _debounceTime = 50; 30 | _pulltype = pulltype; // by default it is pullup 31 | _millisDebounceMark = millis(); 32 | } 33 | 34 | void Button::update() { 35 | boolean newState = Button::read(); 36 | if (newState != _oldState) { 37 | int timeDebounceDiff = millis() - _millisDebounceMark; 38 | 39 | // pressed? 40 | if (_pulltype == 1) { 41 | if (newState == LOW && timeDebounceDiff > _debounceTime) { 42 | _pressedState = true; 43 | } 44 | else { 45 | _releasedState = true; 46 | _toggleState = !_toggleState; 47 | } 48 | } else { 49 | if (newState == HIGH && timeDebounceDiff > _debounceTime) { 50 | _pressedState = true; 51 | } 52 | else { 53 | _releasedState = true; 54 | _toggleState = !_toggleState; 55 | } 56 | } 57 | 58 | _oldState = newState; 59 | _millisDebounceMark = millis(); 60 | //delay(50); // XXX debouncing FIXME to avoid delay 61 | } 62 | 63 | else { 64 | 65 | int timeDiff = millis() - _millisMark; 66 | 67 | if (_pulltype == 1) { 68 | if(newState == LOW && _oldState == LOW && timeDiff > _heldTime) { 69 | _heldState = true; 70 | } else { 71 | _heldState = false; 72 | } 73 | } else { 74 | if(newState == HIGH && _oldState == HIGH && timeDiff > _heldTime) { 75 | _heldState = true; 76 | } else { 77 | _heldState = false; 78 | } 79 | } 80 | } 81 | } 82 | 83 | 84 | boolean Button::readSwitch() 85 | { 86 | Button::update(); 87 | return _toggleState; 88 | } 89 | 90 | boolean Button::pressed() 91 | { 92 | Button::update(); 93 | 94 | if(_pressedState == true) 95 | { 96 | _millisMark = millis(); 97 | _pressedState = false; 98 | return true; 99 | } 100 | else 101 | return false; 102 | } 103 | 104 | boolean Button::released() 105 | { 106 | Button::update(); 107 | 108 | if(_releasedState == true) 109 | { 110 | _releasedState = false; 111 | return true; 112 | } 113 | else 114 | return false; 115 | } 116 | 117 | boolean Button::held() 118 | { 119 | Button::update(); 120 | return _heldState; 121 | } 122 | -------------------------------------------------------------------------------- /src/Button/Button.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../Generic/DigitalInput.h" 3 | 4 | #ifndef Button_h 5 | #define Button_h 6 | 7 | #define PULL_DOWN 0 8 | #define PULL_UP 1 9 | 10 | class Button: public DigitalInput 11 | { 12 | public: 13 | Button(uint8_t _pin); 14 | Button(uint8_t _pin, uint8_t pulltype); 15 | boolean readSwitch(); 16 | boolean pressed(); 17 | boolean held(); 18 | boolean released(); 19 | 20 | protected: 21 | boolean _toggleState, _oldState; 22 | boolean _pressedState, _releasedState; 23 | boolean _heldState; 24 | int _heldTime; 25 | int _millisMark; 26 | int _debounceTime; 27 | int _millisDebounceMark; 28 | int _pulltype; 29 | 30 | void update(); 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/DHT11/DHT11.cpp: -------------------------------------------------------------------------------- 1 | #include "DHT11.h" 2 | #include "EduIntro.h" 3 | 4 | DHT11::DHT11(uint8_t _pin) : DigitalInput(_pin, INPUT) 5 | { 6 | pin = _pin; 7 | } 8 | 9 | DHT11::ReadStatus DHT11::update() { 10 | uint8_t buffer[RESPONSE_SIZE] = { 0 }; 11 | uint8_t bitIndex = BYTE_MS_BIT; 12 | ReadStatus status = OK; 13 | 14 | // Request sample 15 | pinMode(this->pin, OUTPUT); 16 | digitalWrite(this->pin, LOW); 17 | delay(START_SIGNAL_WAIT); 18 | 19 | // Wait for response 20 | digitalWrite(this->pin, HIGH); 21 | pinMode(this->pin, INPUT); 22 | delayMicroseconds(RESPONSE_WAIT); 23 | 24 | // Acknowledge or timeout 25 | // Response signal should first be low for 80us... 26 | if ((status = this->waitForPinChange(LOW)) != OK) { 27 | goto done; 28 | } 29 | 30 | // ... then be high for 80us ... 31 | if ((status = this->waitForPinChange(HIGH)) != OK) { 32 | goto done; 33 | } 34 | 35 | /* 36 | * ... then provide 5 bytes of data that include the integral part of the 37 | * humidity, the fractional part of the humidity, the integral part of the 38 | * temperature, the fractional part of the temperature, and a checksum 39 | * that is the sum of the integral parts of humidity and temperature. 40 | */ 41 | for (size_t i = 0; i < BITS_IN(buffer); i++) { 42 | if ((status = this->waitForPinChange(LOW)) != OK) { 43 | goto done; 44 | } 45 | 46 | unsigned long highStart = micros(); 47 | 48 | if ((status = this->waitForPinChange(HIGH)) != OK) { 49 | goto done; 50 | } 51 | 52 | // 26-28 us = 0, 50 us = 1. 40 us is a good threshold between 0 and 1 53 | if ((micros() - highStart) > ONE_THRESHOLD) { 54 | buffer[i / BITS_PER_BYTE] |= (1 << bitIndex); 55 | } 56 | 57 | // Decrement or reset bitIndex 58 | bitIndex = (bitIndex > 0) ? bitIndex - 1 : BYTE_MS_BIT; 59 | } 60 | 61 | // Check the checksum. Only if it's good, record the new values. 62 | if (buffer[CHECKSUM_INDEX] == ( buffer[0] + buffer[1] 63 | + buffer[2] + buffer[3])) { 64 | this->humidity = buffer[HUMIDITY_INDEX]; 65 | this->temperatureC = buffer[TEMPERATURE_INDEX]; 66 | this->temperatureF = (this->temperatureC * 9.0)/ 5.0 + 32.0; ; 67 | } else { 68 | status = ERROR_CHECKSUM; 69 | } 70 | 71 | done: 72 | return status; 73 | } 74 | -------------------------------------------------------------------------------- /src/DHT11/DHT11.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../Generic/DigitalInput.h" 3 | 4 | #ifndef DHT11_h 5 | #define DHT11_h 6 | 7 | /* for DHT11 serialized input */ 8 | 9 | #define BITS_IN(object) (8 * sizeof((object))) 10 | 11 | enum { 12 | /* 13 | * Time required to signal the DHT11 to switch from low power mode to 14 | * running mode. 18 ms is the minimal, add a few extra ms to be safe. 15 | */ 16 | START_SIGNAL_WAIT = 20, 17 | 18 | /* 19 | * Once the start signal has been sent, we wait for a response. The doc 20 | * says this should take 20-40 us, we wait 5 ms to be safe. 21 | */ 22 | RESPONSE_WAIT = 30, 23 | 24 | /* 25 | * The time threshold between a 0 bit and a 1 bit in the response. Times 26 | * greater than this (in ms) will be considered a 1; otherwise they'll be 27 | * considered a 0. 28 | */ 29 | ONE_THRESHOLD = 40, 30 | 31 | /* 32 | * The number of bytes we expect from the sensor. This consists of one 33 | * byte for the integral part of the humidity, one byte for the fractional 34 | * part of the humidity, one byte for the integral part of the temperature, 35 | * one byte for the fractional part of the temperature, and one byte for 36 | * a checksum. The DHT11 doesn't capture the fractional parts of the 37 | * temperature and humidity, but it doesn't transmit data during those 38 | * times. 39 | */ 40 | RESPONSE_SIZE = 5, 41 | 42 | /* 43 | * The number of bits in a bytes. 44 | */ 45 | BITS_PER_BYTE = 8, 46 | 47 | /* 48 | * The 0-base most significant bit in a byte. 49 | */ 50 | BYTE_MS_BIT = 7, 51 | 52 | /* 53 | * The index in the response where the humidity reading is stored. 54 | */ 55 | HUMIDITY_INDEX = 0, 56 | 57 | /* 58 | * The index in the response where the temperature is stored. 59 | */ 60 | TEMPERATURE_INDEX = 2, 61 | 62 | /* 63 | * The index in the response where the checksum is stored. 64 | */ 65 | CHECKSUM_INDEX = 4, 66 | }; 67 | 68 | class DHT11 : public DigitalInput 69 | { 70 | public: 71 | //DHT11(uint8_t _pin): humidity(-1), temperatureC(-1), pin(_pin); 72 | DHT11(uint8_t _pin); 73 | // An enumeration modeling the read status of the sensor. 74 | enum ReadStatus { 75 | OK, 76 | ERROR_CHECKSUM, 77 | ERROR_TIMEOUT, 78 | }; 79 | ReadStatus update(); // read the data and return status 80 | inline int readCelsius() const { 81 | return this->temperatureC; 82 | } 83 | inline float readFahrenheit() const { 84 | return this->temperatureF; 85 | } 86 | inline int readHumidity() const { 87 | return this->humidity; 88 | } 89 | 90 | private: 91 | int pin; 92 | int humidity; 93 | int temperatureC; 94 | float temperatureF; 95 | enum { 96 | MAX_PIN_CHANGE_ITERATIONS = 10000, // timeout variable 97 | }; 98 | inline ReadStatus waitForPinChange(const int oldValue, 99 | unsigned maxIterations = 100 | MAX_PIN_CHANGE_ITERATIONS) const { 101 | while ((--maxIterations > 0) && (digitalRead(this->pin) == oldValue)) { 102 | // Just keep looping... 103 | } 104 | 105 | return (maxIterations > 0) ? OK : ERROR_TIMEOUT; 106 | } 107 | }; 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /src/EduIntro.cpp: -------------------------------------------------------------------------------- 1 | #include "EduIntro.h" 2 | 3 | /* 4 | ----------------------------------------------------------------------------- 5 | Classes: Generals 6 | ----------------------------------------------------------------------------- 7 | Digital Input 8 | Analog Input 9 | Analog Input with two connectors 10 | Output 11 | ----------------------------------------------------------------------------- 12 | Classes: Digital Inputs 13 | ----------------------------------------------------------------------------- 14 | Button 15 | PIR 16 | DHT 11 temperature sensor 17 | ----------------------------------------------------------------------------- 18 | Classes: Analog Inputs 19 | ----------------------------------------------------------------------------- 20 | Potentiometer 21 | Light Sensor 22 | Temperature Sensor 23 | Thermistor 24 | LM35 25 | ----------------------------------------------------------------------------- 26 | Classes: Outputs 27 | ----------------------------------------------------------------------------- 28 | LED 29 | MosFet 30 | Relay 31 | ServoMotor 32 | Piezo 33 | ----------------------------------------------------------------------------- 34 | Classes: Board Specific 35 | ----------------------------------------------------------------------------- 36 | Arduino uno wifi Rev2 accelerometer 37 | Arduino uno wifi Rev2 WIFININA 38 | */ 39 | -------------------------------------------------------------------------------- /src/EduIntro.h: -------------------------------------------------------------------------------- 1 | /* 2 | * EduIntro Library v0.1 3 | * 4 | * 5 | * 6 | * created on Aug 2018 7 | * by D. Cuartielles 8 | * based on work from Dec 2011 by F. Vanzati 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 23 | * MA 02110-1301, USA. 24 | */ 25 | 26 | #include "Arduino.h" 27 | 28 | #ifndef EduIntro_h 29 | #define EduIntro_h 30 | 31 | /* 32 | ----------------------------------------------------------------------------- 33 | Generic Classes 34 | ----------------------------------------------------------------------------- 35 | */ 36 | 37 | #include "Generic/DigitalInput.h" 38 | #include "Generic/AnalogInput.h" 39 | #include "Generic/AnalogInput2.h" 40 | 41 | /* 42 | ----------------------------------------------------------------------------- 43 | Digital Inputs 44 | ----------------------------------------------------------------------------- 45 | */ 46 | 47 | /* Button */ 48 | 49 | #include "Button/Button.h" 50 | 51 | /* PIR */ 52 | 53 | #include "PIR/PIR.h" 54 | 55 | /* DHT11 */ 56 | 57 | #include "DHT11/DHT11.h" 58 | 59 | /* 60 | ----------------------------------------------------------------------------- 61 | Analog Inputs 62 | ----------------------------------------------------------------------------- 63 | */ 64 | 65 | /* Potentiometer */ 66 | 67 | #include "Potentiometer/Potentiometer.h" 68 | 69 | /* Light Sensor */ 70 | 71 | #include "LightSensor/LightSensor.h" 72 | 73 | /* Temperature Sensor */ 74 | 75 | #include "Thermistor/Thermistor.h" 76 | #include "LM35/LM35.h" 77 | 78 | /* 79 | ----------------------------------------------------------------------------- 80 | Outputs 81 | ----------------------------------------------------------------------------- 82 | */ 83 | 84 | /* LED */ 85 | 86 | #include "LED/LED.h" 87 | 88 | /* Piezo */ 89 | 90 | #include "Piezo/Piezo.h" 91 | 92 | /* MosFet */ 93 | 94 | #include "MosFet/MosFet.h" 95 | 96 | /* Relay */ 97 | 98 | #include "Relay/Relay.h" 99 | 100 | /* Servo */ 101 | 102 | #include "ServoMotor/ServoMotor.h" 103 | 104 | /* Arduino uno wifi Rev2 accelerometer */ 105 | 106 | #include "IMU/Motion.h" 107 | 108 | /* Arduino uno wifi Rev2 WIFININA */ 109 | 110 | #include "WiFiComm/WiFiComm.h" 111 | 112 | /* 113 | ----------------------------------------------------------------------------- 114 | Constants 115 | ----------------------------------------------------------------------------- 116 | */ 117 | 118 | /* Names of pins */ 119 | 120 | #define D21 21 121 | #define D20 20 122 | #define D19 19 123 | #define D18 18 124 | #define D17 17 125 | #define D16 16 126 | #define D15 15 127 | #define D14 14 128 | #define D13 13 129 | #define D12 12 130 | #define D11 11 131 | #define D10 10 132 | #define D9 9 133 | #define D8 8 134 | #define D7 7 135 | #define D6 6 136 | #define D5 5 137 | #define D4 4 138 | #define D3 3 139 | #define D2 2 140 | #define D1 1 141 | #define D0 0 142 | 143 | /* Minimum Analog In/Out that each platform have */ 144 | 145 | #define ANALOG_MAX 1023 146 | 147 | /* Possible types of outputs */ 148 | #define NORMAL 0 149 | #define INVERTED 1 150 | 151 | #endif 152 | -------------------------------------------------------------------------------- /src/Generic/AnalogInput.h: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | 3 | #ifndef AnalogInput_h 4 | #define AnalogInput_h 5 | 6 | class AnalogInput 7 | { 8 | public: 9 | AnalogInput(uint8_t _pin); 10 | int read(); 11 | boolean increasing(); 12 | boolean decreasing(); 13 | 14 | protected: 15 | uint8_t pin; 16 | int _oldVal; 17 | boolean _increasing; 18 | boolean _decreasing; 19 | }; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/Generic/AnalogInput2.cpp: -------------------------------------------------------------------------------- 1 | #include "AnalogInput2.h" 2 | #include "EduIntro.h" 3 | 4 | #if USB_VID == 0x2341 && USB_PID == 0x803C 5 | #include 6 | #endif 7 | 8 | AnalogInput2::AnalogInput2(uint8_t _pinX, uint8_t _pinY) 9 | { 10 | pinX = _pinX; 11 | pinY = _pinY; 12 | } 13 | 14 | AnalogInput2::AnalogInput2(uint8_t _pinX, uint8_t _pinY, uint8_t _pinZ) 15 | { 16 | pinX = _pinX; 17 | pinY = _pinY; 18 | pinZ = _pinZ; 19 | } 20 | 21 | int AnalogInput2::readX() { 22 | 23 | int val; 24 | 25 | #if USB_VID == 0x2341 && USB_PID == 0x803C 26 | val = Esplora.readTK(pinX); 27 | #else 28 | val = analogRead(pinX); 29 | #endif 30 | 31 | return val; 32 | } 33 | 34 | int AnalogInput2::readY() { 35 | 36 | int val; 37 | 38 | #if USB_VID == 0x2341 && USB_PID == 0x803C 39 | val = Esplora.readTK(pinY); 40 | #else 41 | val = analogRead(pinY); 42 | #endif 43 | 44 | return val; 45 | } 46 | 47 | int AnalogInput2::readZ() { 48 | 49 | int val; 50 | 51 | #if USB_VID == 0x2341 && USB_PID == 0x803C 52 | val = Esplora.readTK(pinZ); 53 | #else 54 | val = analogRead(pinZ); 55 | #endif 56 | 57 | return val; 58 | } 59 | -------------------------------------------------------------------------------- /src/Generic/AnalogInput2.h: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | 3 | #ifndef AnalogInput2_h 4 | #define AnalogInput2_h 5 | 6 | class AnalogInput2 7 | { 8 | public: 9 | AnalogInput2(uint8_t _pinX, uint8_t _pinY); 10 | AnalogInput2(uint8_t _pinX, uint8_t _pinY, uint8_t _pinZ); 11 | int readX(); 12 | int readY(); 13 | int readZ(); 14 | 15 | protected: 16 | uint8_t pinX, pinY, pinZ; 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/Generic/Analoginput.cpp: -------------------------------------------------------------------------------- 1 | #include "AnalogInput.h" 2 | #include "EduIntro.h" 3 | 4 | AnalogInput::AnalogInput(uint8_t _pin) 5 | { 6 | pin = _pin; 7 | } 8 | 9 | int AnalogInput::read() { 10 | 11 | int val; 12 | 13 | #if USB_VID == 0x2341 && USB_PID == 0x803C 14 | val = Esplora.readTK(pin); 15 | #else 16 | val = analogRead(pin); 17 | #endif 18 | 19 | if (val > _oldVal) 20 | { 21 | _increasing = true; 22 | _decreasing = false; 23 | } 24 | 25 | if (val < _oldVal) 26 | { 27 | _increasing = false; 28 | _decreasing = true; 29 | } 30 | 31 | _oldVal = val; 32 | 33 | return val; 34 | } 35 | 36 | boolean AnalogInput::increasing() { 37 | AnalogInput::read(); 38 | return _increasing; 39 | } 40 | 41 | boolean AnalogInput::decreasing() { 42 | AnalogInput::read(); 43 | return _decreasing; 44 | } 45 | -------------------------------------------------------------------------------- /src/Generic/DigitalInput.cpp: -------------------------------------------------------------------------------- 1 | #include "DigitalInput.h" 2 | #include "EduIntro.h" 3 | 4 | #if USB_VID == 0x2341 && USB_PID == 0x803C 5 | #include 6 | #endif 7 | 8 | DigitalInput::DigitalInput(uint8_t _pin) 9 | { 10 | pin = _pin; 11 | pinMode(pin, INPUT); 12 | } 13 | 14 | DigitalInput::DigitalInput(uint8_t _pin, uint8_t _mode) 15 | { 16 | pin = _pin; 17 | pinMode(pin, _mode); 18 | } 19 | 20 | boolean DigitalInput::read() { 21 | 22 | boolean val; 23 | 24 | #if USB_VID == 0x2341 && USB_PID == 0x803C 25 | int value = Esplora.readTK(pin); 26 | if (value < 128) 27 | val = 0; 28 | else 29 | val = 1; 30 | #else 31 | val = digitalRead(pin); 32 | #endif 33 | 34 | return val; 35 | } 36 | -------------------------------------------------------------------------------- /src/Generic/DigitalInput.h: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | 3 | #ifndef DigitalInput_h 4 | #define DigitalInput_h 5 | 6 | class DigitalInput 7 | { 8 | public: 9 | DigitalInput(uint8_t _pin); 10 | DigitalInput(uint8_t _pin, uint8_t _mode); 11 | boolean read(); 12 | 13 | protected: 14 | uint8_t pin; 15 | }; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/Generic/Output.cpp: -------------------------------------------------------------------------------- 1 | #include "Output.h" 2 | #include "EduIntro.h" 3 | 4 | Output::Output(uint8_t _pin) 5 | { 6 | pin = _pin; 7 | _state = LOW; 8 | pinMode(pin, OUTPUT); 9 | } 10 | 11 | Output::Output(uint8_t _pin, uint8_t _logic) 12 | { 13 | pin = _pin; 14 | logic = _logic; 15 | _state = LOW; 16 | pinMode(pin, OUTPUT); 17 | } 18 | 19 | boolean Output::isPWM() 20 | { 21 | //XXX this is just for the UNO board, needs fix 22 | #if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) 23 | 24 | //Code in here will only be compiled if an Arduino Uno (or older) is used. 25 | if (pin == D11 || pin == D10 || pin == D9 || pin == D6 || pin == D5 || pin == D3) 26 | return true; 27 | 28 | #endif 29 | 30 | #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__) 31 | 32 | //Code in here will only be compiled if an Arduino Leonardo is used. 33 | if (pin == D13 || pin == D11 || pin == D10 || pin == D9 || pin == D6 || pin == D5 || pin == D3) 34 | return true; 35 | 36 | #endif 37 | 38 | #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) 39 | 40 | //Code in here will only be compiled if an Arduino Mega is used. 41 | if (pin == D13 || pin == D12 || pin == D11 || pin == D10 || pin == D9 || pin == D8 || pin == D7 || pin == D6 || pin == D5 || pin == D4 || pin == D3 || pin == D2 || pin == D1 || pin == D0) 42 | return true; 43 | 44 | #endif 45 | 46 | #if defined(ARDUINO_ARCH_SAMD) 47 | 48 | //Code in here will only be compiled if an Arduino MKR and Nano IoT is used. 49 | if (pin == D19 || pin == D18 || pin == D12 || pin == D10 || pin == D8 || pin == D7 || pin == D6 || pin == D5 || pin == D4 || pin == D3 || pin == D2 || pin == D1 || pin == D0) 50 | return true; 51 | 52 | #endif 53 | 54 | #if defined(ARDUINO_ARCH_MBED) 55 | 56 | //Code in here will only be compiled if an Arduino Nano BLE is used. 57 | if (pin == D21 || pin == D20 || pin == D19 || pin == D18 || pin == D17 || pin == D16 || pin == D15 || pin == D14 || pin == D13 || pin == D12 || pin == D11 || pin == D10 || pin == D9 || pin == D8 || pin == D7 || pin == D6 || pin == D5 || pin == D4 || pin == D3 || pin == D2 || pin == D1 || pin == D0) 58 | return true; 59 | 60 | #endif 61 | 62 | return false; 63 | } 64 | 65 | void Output::write(int value) 66 | { 67 | if (isPWM()) 68 | if( value <= ANALOG_MAX && value >= 0 ) 69 | analogWrite(pin, value * 0.25); // make sure the value is constrained between 0..255 70 | else 71 | return; 72 | else 73 | if ( value > ANALOG_MAX * 0.5 ) 74 | digitalWrite(pin, HIGH); 75 | else 76 | digitalWrite(pin, LOW); 77 | } 78 | 79 | void Output::on() { 80 | if (logic == NORMAL) { 81 | write(1023); 82 | _state = HIGH; 83 | } else { 84 | write(0); 85 | _state = LOW; 86 | } 87 | } 88 | 89 | void Output::off() { 90 | if (logic == NORMAL) { 91 | write(0); 92 | _state = LOW; 93 | } else { 94 | write(1023); 95 | _state = HIGH; 96 | } 97 | } 98 | 99 | 100 | void Output::blink(int del) 101 | { 102 | on(); 103 | delay(del); 104 | off(); 105 | delay(del); 106 | } 107 | 108 | void Output::blink(int del1, int del2) 109 | { 110 | on(); 111 | delay(del1); 112 | off(); 113 | delay(del2); 114 | } 115 | -------------------------------------------------------------------------------- /src/Generic/Output.h: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | 3 | #ifndef Output_h 4 | #define Output_h 5 | 6 | class Output 7 | { 8 | public: 9 | Output (uint8_t _pin); 10 | Output (uint8_t _pin, uint8_t _logic); 11 | void write(int value); 12 | inline int state() { return _state; } 13 | void on(); 14 | void off(); 15 | void blink(int delay); 16 | void blink(int delay1, int delay2); 17 | 18 | protected: 19 | uint8_t pin; 20 | uint8_t logic; 21 | int _state; 22 | boolean isPWM(); 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/IMU/Motion.cpp: -------------------------------------------------------------------------------- 1 | #include "Motion.h" 2 | 3 | //#if defined(ARDUINO_ARCH_MEGAAVR) 4 | #if defined(AVR_UNO_WIFI_REV2) 5 | 6 | Motion::Motion(){ 7 | } 8 | 9 | int Motion::begin(){ 10 | return IMU.begin(); 11 | } 12 | 13 | int Motion::readAcceleration() { 14 | if (IMU.accelerationAvailable()) { 15 | IMU.readAcceleration(Motion::acc_x,Motion::acc_y,Motion::acc_z); 16 | return 1; 17 | } 18 | return 0; 19 | } 20 | 21 | int Motion::readGyroscope() { 22 | if (IMU.gyroscopeAvailable()) { 23 | IMU.readGyroscope(Motion::gyro_x,Motion::gyro_y,Motion::gyro_z); 24 | return 1; 25 | } 26 | return 0; 27 | } 28 | 29 | int Motion::read() { 30 | if(Motion::readAcceleration() && Motion::readGyroscope()) 31 | return 1; 32 | return 0; 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/IMU/Motion.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //#if defined(ARDUINO_ARCH_MEGAAVR) 4 | #if defined(AVR_UNO_WIFI_REV2) 5 | 6 | #include 7 | 8 | #ifndef Motion_h 9 | #define Motion_h 10 | 11 | class Motion 12 | { 13 | public: 14 | Motion(); 15 | int begin(); 16 | int read(); 17 | int readAcceleration(); 18 | int readGyroscope(); 19 | float acc_x; 20 | float acc_y; 21 | float acc_z; 22 | float gyro_x; 23 | float gyro_y; 24 | float gyro_z; 25 | }; 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/LED/LED.cpp: -------------------------------------------------------------------------------- 1 | #include "LED.h" 2 | #include "EduIntro.h" 3 | 4 | Led::Led(uint8_t _pin) : Output(_pin) {} 5 | Led::Led(uint8_t _pin, uint8_t _logic) : Output(_pin, _logic) {} 6 | -------------------------------------------------------------------------------- /src/LED/LED.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../Generic/Output.h" 3 | 4 | #ifndef LED_h 5 | #define LED_h 6 | 7 | class Led : public Output 8 | { 9 | public: 10 | Led(uint8_t _pin); 11 | Led(uint8_t _pin, uint8_t _logic); 12 | inline void brightness(int value) { write(value); } 13 | }; 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /src/LM35/LM35.cpp: -------------------------------------------------------------------------------- 1 | #include "LM35.h" 2 | #include "EduIntro.h" 3 | 4 | LM35::LM35(uint8_t _pin) : AnalogInput(_pin) {} 5 | 6 | float LM35::readCelsius() 7 | { 8 | float _temperatureC = LM35::read() * 5 / ADCres / Acc ; 9 | 10 | return _temperatureC; 11 | } 12 | 13 | float LM35::readFahrenheit() 14 | { 15 | float _temperatureF = (LM35::readCelsius() * 9.0)/ 5.0 + 32.0; ; 16 | 17 | return _temperatureF; 18 | } 19 | -------------------------------------------------------------------------------- /src/LM35/LM35.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../Generic/AnalogInput.h" 3 | 4 | #ifndef LM35_h 5 | #define LM35_h 6 | 7 | class LM35 : public AnalogInput 8 | { 9 | public: 10 | LM35(uint8_t _pin); 11 | float readCelsius(); 12 | float readFahrenheit(); 13 | 14 | protected: 15 | constexpr static float ADCres = 1023.0; 16 | constexpr static float Acc = 0.01; // Accuracy mV/C 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/LightSensor/LightSensor.cpp: -------------------------------------------------------------------------------- 1 | #include "LightSensor.h" 2 | #include "EduIntro.h" 3 | 4 | LightSensor::LightSensor(uint8_t _pin) : AnalogInput(_pin){} 5 | -------------------------------------------------------------------------------- /src/LightSensor/LightSensor.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../Generic/AnalogInput.h" 3 | 4 | #ifndef LightSensor_h 5 | #define LightSensor_h 6 | 7 | class LightSensor : public AnalogInput 8 | { 9 | public: 10 | LightSensor(uint8_t _pin); 11 | }; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/MosFet/MosFet.cpp: -------------------------------------------------------------------------------- 1 | #include "MosFet.h" 2 | #include "EduIntro.h" 3 | 4 | MosFet::MosFet(uint8_t _pin) : Output(_pin) {} 5 | -------------------------------------------------------------------------------- /src/MosFet/MosFet.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../Generic/Output.h" 3 | 4 | #ifndef MosFet_h 5 | #define MosFet_h 6 | 7 | class MosFet : public Output 8 | { 9 | public: 10 | MosFet(uint8_t _pin); 11 | }; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/PIR/PIR.cpp: -------------------------------------------------------------------------------- 1 | #include "PIR.h" 2 | #include "EduIntro.h" 3 | 4 | /* 5 | The PIR could be in need of the internal pull-up or not 6 | therefore the need of two constructors. By default: no pull-up 7 | */ 8 | PIR::PIR(uint8_t _pin) : DigitalInput(_pin, INPUT) 9 | { 10 | _toggleState = LOW; 11 | _oldState = LOW; 12 | _pressedState = LOW; 13 | _releasedState = LOW; 14 | _heldState = LOW; 15 | _heldTime = 500; 16 | _mode = INPUT; 17 | } 18 | 19 | PIR::PIR(uint8_t _pin, uint8_t _mod) : DigitalInput(_pin, _mod) 20 | { 21 | if(_mode == INPUT_PULLUP) { 22 | _toggleState = HIGH; 23 | _oldState = HIGH; 24 | _pressedState = HIGH; 25 | _releasedState = HIGH; 26 | _heldState = HIGH; 27 | } else { 28 | _toggleState = LOW; 29 | _oldState = LOW; 30 | _pressedState = LOW; 31 | _releasedState = LOW; 32 | _heldState = LOW; 33 | } 34 | _heldTime = 500; 35 | _mode = _mod; 36 | } 37 | 38 | void PIR::update() { 39 | boolean newState = PIR::read(); 40 | if (newState != _oldState) { 41 | _activityState = true; // there was some sort of activity 42 | // activated? 43 | if(_mode == INPUT_PULLUP) { 44 | if (newState == LOW) { 45 | _pressedState = true; 46 | } 47 | else { 48 | _releasedState = true; 49 | _toggleState = !_toggleState; 50 | } 51 | } else { 52 | if (newState == HIGH) { 53 | _pressedState = true; 54 | } 55 | else { 56 | _releasedState = true; 57 | _toggleState = !_toggleState; 58 | } 59 | } 60 | _oldState = newState; 61 | //delay(50); // debouncing is unlike in the button not needed, but this is up for testing 62 | } 63 | 64 | else { 65 | 66 | int timeDiff = millis() - _millisMark; 67 | 68 | if(_mode == INPUT_PULLUP) { 69 | if(newState == LOW && _oldState == LOW && timeDiff > _heldTime) { 70 | _heldState = true; 71 | } else { 72 | _heldState = false; 73 | } 74 | } else { 75 | if(newState == HIGH && _oldState == HIGH && timeDiff > _heldTime) { 76 | _heldState = true; 77 | } else { 78 | _heldState = false; 79 | } 80 | } 81 | } 82 | } 83 | 84 | boolean PIR::hadActivity() { 85 | return _activityState; 86 | } 87 | 88 | boolean PIR::resetActivity() { 89 | _activityState = false; 90 | return _activityState; 91 | } 92 | 93 | boolean PIR::readSwitch() 94 | { 95 | PIR::update(); 96 | return _toggleState; 97 | } 98 | 99 | boolean PIR::activated() 100 | { 101 | PIR::update(); 102 | 103 | if(_pressedState == true) 104 | { 105 | _millisMark = millis(); 106 | _pressedState = false; 107 | return true; 108 | } 109 | else 110 | return false; 111 | } 112 | 113 | boolean PIR::deactivated() 114 | { 115 | PIR::update(); 116 | 117 | if(_releasedState == true) 118 | { 119 | _releasedState = false; 120 | return true; 121 | } 122 | else 123 | return false; 124 | } 125 | 126 | boolean PIR::active() 127 | { 128 | PIR::update(); 129 | return _heldState; 130 | } 131 | -------------------------------------------------------------------------------- /src/PIR/PIR.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../Generic/DigitalInput.h" 3 | 4 | #ifndef PIR_h 5 | #define PIR_h 6 | 7 | class PIR: public DigitalInput 8 | { 9 | public: 10 | PIR(uint8_t _pin); 11 | PIR(uint8_t _pin, uint8_t _mode); 12 | boolean hadActivity(); // was it active since last reset? 13 | boolean resetActivity(); // reset activity variable 14 | boolean readSwitch(); 15 | boolean activated(); 16 | boolean active(); 17 | boolean deactivated(); 18 | 19 | protected: 20 | boolean _toggleState, _oldState; 21 | boolean _pressedState, _releasedState; 22 | boolean _heldState, _activityState; 23 | int _heldTime; 24 | int _millisMark; 25 | int _mode; 26 | 27 | void update(); 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/Piezo/Piezo.cpp: -------------------------------------------------------------------------------- 1 | #include "Piezo.h" 2 | #include "EduIntro.h" 3 | 4 | Piezo::Piezo(uint8_t _pin) : Output(_pin) {} 5 | 6 | void Piezo::noBeep() 7 | { 8 | noTone(pin); 9 | } 10 | 11 | void Piezo::beep(int _tone) 12 | { 13 | if (_tone > SILENCE) 14 | tone(pin, _tone); 15 | else 16 | noTone(pin); 17 | } 18 | 19 | void Piezo::beep(int _tone, int _duration) 20 | { 21 | if (_tone > SILENCE) 22 | tone(pin, _tone, _duration); 23 | else 24 | noTone(pin); 25 | } 26 | 27 | void Piezo::play(int melody[]) 28 | { 29 | //size_t n = sizeof(melody)/sizeof(melody[0]); 30 | int n = getMelodySize(melody); 31 | for (int i = 0; i < n; i+=2) { 32 | // to calculate the note duration, take one second divided by the note type. 33 | //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. 34 | int noteDuration = 1000 / melody[i+1]; 35 | beep(melody[i], noteDuration); 36 | 37 | // to distinguish the notes, set a minimum time between them. 38 | // the note's duration + 30% seems to work well: 39 | int pauseBetweenNotes = noteDuration * 1.30; 40 | delay(pauseBetweenNotes); 41 | } 42 | noTone(pin); 43 | } 44 | 45 | void Piezo::play(int n, int melody[]) 46 | { 47 | for (int i = 0; i < n; i+=2) { 48 | // to calculate the note duration, take one second divided by the note type. 49 | //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. 50 | int noteDuration = 1000 / melody[i+1]; 51 | beep(melody[i], noteDuration); 52 | 53 | // to distinguish the notes, set a minimum time between them. 54 | // the note's duration + 30% seems to work well: 55 | int pauseBetweenNotes = noteDuration * 1.30; 56 | delay(pauseBetweenNotes); 57 | } 58 | noTone(pin); 59 | } 60 | 61 | int Piezo::getMelodySize(int melody[]) 62 | { 63 | int count = 0; 64 | while (melody[count] != NULL) 65 | count++; 66 | return count; 67 | } 68 | -------------------------------------------------------------------------------- /src/Piezo/Piezo.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../Generic/Output.h" 3 | #include "pitches.h" 4 | 5 | #ifndef Piezo_h 6 | #define Piezo_h 7 | 8 | class Piezo : public Output 9 | { 10 | public: 11 | Piezo(uint8_t _pin); 12 | void noBeep(); 13 | void beep(int _tone); 14 | void beep(int _tone, int _duration); 15 | void play(int melody[]); 16 | void play(int n, int melody[]); 17 | protected: 18 | int getMelodySize(int melody[]); 19 | }; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/Piezo/pitches.h: -------------------------------------------------------------------------------- 1 | /************************************************* 2 | * Public Constants 3 | *************************************************/ 4 | 5 | #ifndef pitches_h 6 | #define pitches_h 7 | 8 | #define SILENCE 1 9 | #define NOTE_B0 31 10 | #define NOTE_C1 33 11 | #define NOTE_CS1 35 12 | #define NOTE_D1 37 13 | #define NOTE_DS1 39 14 | #define NOTE_E1 41 15 | #define NOTE_F1 44 16 | #define NOTE_FS1 46 17 | #define NOTE_G1 49 18 | #define NOTE_GS1 52 19 | #define NOTE_A1 55 20 | #define NOTE_AS1 58 21 | #define NOTE_B1 62 22 | #define NOTE_C2 65 23 | #define NOTE_CS2 69 24 | #define NOTE_D2 73 25 | #define NOTE_DS2 78 26 | #define NOTE_E2 82 27 | #define NOTE_F2 87 28 | #define NOTE_FS2 93 29 | #define NOTE_G2 98 30 | #define NOTE_GS2 104 31 | #define NOTE_A2 110 32 | #define NOTE_AS2 117 33 | #define NOTE_B2 123 34 | #define NOTE_C3 131 35 | #define NOTE_CS3 139 36 | #define NOTE_D3 147 37 | #define NOTE_DS3 156 38 | #define NOTE_E3 165 39 | #define NOTE_F3 175 40 | #define NOTE_FS3 185 41 | #define NOTE_G3 196 42 | #define NOTE_GS3 208 43 | #define NOTE_A3 220 44 | #define NOTE_AS3 233 45 | #define NOTE_B3 247 46 | #define NOTE_C4 262 47 | #define NOTE_CS4 277 48 | #define NOTE_D4 294 49 | #define NOTE_DS4 311 50 | #define NOTE_E4 330 51 | #define NOTE_F4 349 52 | #define NOTE_FS4 370 53 | #define NOTE_G4 392 54 | #define NOTE_GS4 415 55 | #define NOTE_A4 440 56 | #define NOTE_AS4 466 57 | #define NOTE_B4 494 58 | #define NOTE_C5 523 59 | #define NOTE_CS5 554 60 | #define NOTE_D5 587 61 | #define NOTE_DS5 622 62 | #define NOTE_E5 659 63 | #define NOTE_F5 698 64 | #define NOTE_FS5 740 65 | #define NOTE_G5 784 66 | #define NOTE_GS5 831 67 | #define NOTE_A5 880 68 | #define NOTE_AS5 932 69 | #define NOTE_B5 988 70 | #define NOTE_C6 1047 71 | #define NOTE_CS6 1109 72 | #define NOTE_D6 1175 73 | #define NOTE_DS6 1245 74 | #define NOTE_E6 1319 75 | #define NOTE_F6 1397 76 | #define NOTE_FS6 1480 77 | #define NOTE_G6 1568 78 | #define NOTE_GS6 1661 79 | #define NOTE_A6 1760 80 | #define NOTE_AS6 1865 81 | #define NOTE_B6 1976 82 | #define NOTE_C7 2093 83 | #define NOTE_CS7 2217 84 | #define NOTE_D7 2349 85 | #define NOTE_DS7 2489 86 | #define NOTE_E7 2637 87 | #define NOTE_F7 2794 88 | #define NOTE_FS7 2960 89 | #define NOTE_G7 3136 90 | #define NOTE_GS7 3322 91 | #define NOTE_A7 3520 92 | #define NOTE_AS7 3729 93 | #define NOTE_B7 3951 94 | #define NOTE_C8 4186 95 | #define NOTE_CS8 4435 96 | #define NOTE_D8 4699 97 | #define NOTE_DS8 4978 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /src/Potentiometer/Potentiometer.cpp: -------------------------------------------------------------------------------- 1 | #include "Potentiometer.h" 2 | #include "EduIntro.h" 3 | 4 | Potentiometer::Potentiometer(uint8_t _pin) : AnalogInput(_pin) 5 | { 6 | pin = _pin; 7 | _minVal = 1023; 8 | _maxVal = 0; 9 | } 10 | 11 | /* 12 | The potentiometer readRange function includes a filter to determine 13 | the potentiometer range interactively. This allows for the use of sensors 14 | which are not getting the full range 0..1023 15 | */ 16 | int Potentiometer::readRange() 17 | { 18 | 19 | int val = AnalogInput::read(); 20 | 21 | if (val < _minVal) {_minVal = val;} 22 | if (val > _maxVal) {_maxVal = val;} 23 | 24 | float __mappedVal = 0; 25 | if (_minVal != _maxVal) 26 | { 27 | __mappedVal = map(val, _minVal, _maxVal, 0, 1023); 28 | _mappedVal = constrain(__mappedVal, 0, 1023); 29 | } 30 | 31 | return _mappedVal; 32 | } 33 | 34 | int Potentiometer::readStep(int steps) { 35 | 36 | _steps = steps; 37 | 38 | int step = floor(map(AnalogInput::read(), 0, 1023, 0, _steps)); 39 | 40 | return step; 41 | } 42 | -------------------------------------------------------------------------------- /src/Potentiometer/Potentiometer.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../Generic/AnalogInput.h" 3 | 4 | #ifndef Potentiometer_h 5 | #define Potentiometer_h 6 | 7 | class Potentiometer: public AnalogInput 8 | { 9 | public: 10 | Potentiometer(uint8_t pin); 11 | int readRange(); 12 | int readStep(int steps); 13 | 14 | protected: 15 | int _minVal, _maxVal; 16 | int _mappedVal; 17 | int _steps; 18 | }; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/Relay/Relay.cpp: -------------------------------------------------------------------------------- 1 | #include "Relay.h" 2 | #include "EduIntro.h" 3 | 4 | Relay::Relay(uint8_t _pin) : Output(_pin) {} 5 | -------------------------------------------------------------------------------- /src/Relay/Relay.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../Generic/Output.h" 3 | 4 | #ifndef Relay_h 5 | #define Relay_h 6 | 7 | class Relay : public Output 8 | { 9 | public: 10 | Relay(uint8_t _pin); 11 | }; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/ServoMotor/ServoMotor.cpp: -------------------------------------------------------------------------------- 1 | #include "ServoMotor.h" 2 | #include "../EduIntro.h" 3 | 4 | ServoMotor::ServoMotor(uint8_t _pin) 5 | { 6 | Servo(); 7 | pin = _pin; 8 | _attached = false; 9 | } 10 | 11 | int ServoMotor::write(uint8_t _value) 12 | { 13 | if (!_attached) { 14 | attach(pin); 15 | _attached = true; 16 | } 17 | Servo::write(_value); 18 | } 19 | -------------------------------------------------------------------------------- /src/ServoMotor/ServoMotor.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Servo.h" 3 | 4 | #ifndef ServoMotor_h 5 | #define ServoMotor_h 6 | 7 | class ServoMotor : public Servo 8 | { 9 | public: 10 | ServoMotor(uint8_t _pin); 11 | int write(uint8_t _value); 12 | private: 13 | int pin; 14 | boolean _attached; 15 | }; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/Thermistor/Thermistor.cpp: -------------------------------------------------------------------------------- 1 | #include "Thermistor.h" 2 | #include "EduIntro.h" 3 | 4 | Thermistor::Thermistor(uint8_t _pin) : AnalogInput(_pin) {} 5 | 6 | float Thermistor::readCelsius() 7 | { 8 | float Rthermistor = Rb * (ADCres / Thermistor::read() - 1); 9 | float _temperatureC = Beta / (log( Rthermistor * Ginf )) ; 10 | 11 | return _temperatureC - Kelvin; 12 | } 13 | 14 | float Thermistor::readFahrenheit() 15 | { 16 | float _temperatureF = (Thermistor::readCelsius() * 9.0)/ 5.0 + 32.0; ; 17 | 18 | return _temperatureF; 19 | } 20 | -------------------------------------------------------------------------------- /src/Thermistor/Thermistor.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../Generic/AnalogInput.h" 3 | 4 | #ifndef Thermistor_h 5 | #define Thermistor_h 6 | 7 | class Thermistor : public AnalogInput 8 | { 9 | public: 10 | Thermistor(uint8_t _pin); 11 | float readCelsius(); 12 | float readFahrenheit(); 13 | 14 | protected: 15 | constexpr static float ADCres = 1023.0; 16 | constexpr static int Beta = 3950; // Beta parameter 17 | constexpr static float Kelvin = 273.15; // 0°C = 273.15 K 18 | constexpr static int Rb = 10000; // 10 kOhm 19 | constexpr static float Ginf = 120.6685; // Ginf = 1/Rinf 20 | // Rinf = R0*e^(-Beta/T0) = 4700*e^(-3950/298.15) 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/WiFiComm/WiFiComm.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "WiFiComm.h" 3 | 4 | //#if defined(ARDUINO_ARCH_MEGAAVR) 5 | #if defined(AVR_UNO_WIFI_REV2) 6 | 7 | WiFiComm::WiFiComm () { 8 | server = WiFiServer(80); 9 | 10 | } 11 | 12 | void WiFiComm::init(int led, const char *ssid, const char *pass){ 13 | 14 | //while (!Serial) {;} // wait for serial port to connect. Needed for native USB port only 15 | 16 | Serial.println("Access Point Web Server"); 17 | pinMode(led, OUTPUT); // set the LED pin mode 18 | 19 | // check for the WiFi module: 20 | if (WiFi.status() == WL_NO_MODULE) { 21 | Serial.println("Communication with WiFi module failed!"); 22 | // don't continue 23 | while (true); 24 | } 25 | 26 | String fv = WiFi.firmwareVersion(); 27 | if (fv < "1.0.0") { 28 | Serial.println("Please upgrade the firmware"); 29 | } 30 | 31 | // by default the local IP address of will be 192.168.4.1 32 | // you can override it with the following: 33 | // WiFi.config(IPAddress(10, 0, 0, 1)); 34 | 35 | // print the network name (SSID); 36 | Serial.print("Creating access point named: "); 37 | Serial.println(ssid); 38 | 39 | // Create open network. Change this line if you want to create an WEP network: 40 | status = WiFi.beginAP(ssid); 41 | 42 | if (status != WL_AP_LISTENING) { 43 | Serial.println("Creating access point failed"); 44 | // don't continue 45 | while (true); 46 | } 47 | 48 | // wait 10 seconds for connection: 49 | delay(10000); 50 | 51 | // start the web server on port 80 52 | server.begin(); 53 | 54 | } 55 | 56 | String WiFiComm::getSSID() { 57 | return WiFi.SSID(); 58 | } 59 | 60 | IPAddress WiFiComm::getIP() { 61 | return WiFi.localIP(); 62 | } 63 | 64 | int WiFiComm::getStatus(){ 65 | return WiFi.status(); 66 | } 67 | 68 | WiFiClient WiFiComm::getClient() { 69 | return server.available(); 70 | } 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /src/WiFiComm/WiFiComm.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #ifndef WiFiComm_h 5 | #define WiFiComm_h 6 | 7 | //#if defined(ARDUINO_ARCH_MEGAAVR) 8 | #if defined(AVR_UNO_WIFI_REV2) 9 | #include 10 | #include 11 | #include "WiFiServer.h" 12 | 13 | 14 | class WiFiComm 15 | { 16 | public: 17 | int led = LED_BUILTIN; 18 | int status = WL_IDLE_STATUS; 19 | WiFiServer server = NULL; 20 | 21 | 22 | WiFiComm(); 23 | 24 | void init(int led, const char *ssid, const char *pass); 25 | 26 | int getStatus(); 27 | 28 | String getSSID(); 29 | 30 | IPAddress getIP(); 31 | 32 | WiFiClient getClient(); 33 | }; 34 | 35 | #endif 36 | 37 | #endif 38 | --------------------------------------------------------------------------------