■ Contents Adding Better Displays and Graphics����������������������������������������������������������������������������������������218 Gameduino Library�������������������������������������������������������������������������������������������������������������������������������������������� 218 A New Stop It����������������������������������������������������������������������������������������������������������������������������������������������������� 221 Art���������������������������������������������������������������������������������������������������������������������������������������������������������������������� 222 Coding Stack It�������������������������������������������������������������������������������������������������������������������������������������������������� 224 Verifying the Code��������������������������������������������������������������������������������������������������������������������������������������������� 228 Making Sounds�������������������������������������������������������������������������������������������������������������������������������������������������� 229 Adding a Bit of Splash��������������������������������������������������������������������������������������������������������������������������������������� 231 Programming the Game to Play Itself���������������������������������������������������������������������������������������������������������������� 232 The Finishing Polish������������������������������������������������������������������������������������������������������������������������������������������ 234 Arcade and Game Resources����������������������������������������������������������������������������������������������������������������������������� 235 Summary�����������������������������������������������������������������������������������������������������������������������������������236 ■■Chapter 12: Writing Your Own Arduino Libraries�����������������������������������������������������������237 What you need to know to write your own libraries������������������������������������������������������������������237 Creating a simple library����������������������������������������������������������������������������������������������������������������������������������� 239 Making a Motor Library�������������������������������������������������������������������������������������������������������������244 The anatomy of an Arduino library folder����������������������������������������������������������������������������������249 Examples Folder������������������������������������������������������������������������������������������������������������������������������������������������ 250 License�������������������������������������������������������������������������������������������������������������������������������������������������������������� 250 keywords.txt������������������������������������������������������������������������������������������������������������������������������������������������������ 250 Installing Arduino Libraries�������������������������������������������������������������������������������������������������������������������������������� 251 Using Arduino Libraries������������������������������������������������������������������������������������������������������������������������������������� 251 Arduino Objects and Library Conventions���������������������������������������������������������������������������������251 Summary�����������������������������������������������������������������������������������������������������������������������������������258 ■■Chapter 13: Arduino Test Suite��������������������������������������������������������������������������������������259 Installing the Arduino Test Suite������������������������������������������������������������������������������������������������259 Getting Started with Testing������������������������������������������������������������������������������������������������������262 Arduino Test Result Format�������������������������������������������������������������������������������������������������������264 Test Result Section Format Details�������������������������������������������������������������������������������������������������������������������� 264 xiv
Download from Wow! eBook <www.wowebook.com> ■ Contents Arduino Test Suite Basic Functions ������������������������������������������������������������������������������������������ 265 ATS_begin����������������������������������������������������������������������������������������������������������������������������������������������������������266 ATS_PrintTestStatus ������������������������������������������������������������������������������������������������������������������������������������������266 ATS_end ������������������������������������������������������������������������������������������������������������������������������������������������������������266 Using the Basic Functions ���������������������������������������������������������������������������������������������������������������������������������267 Arduino Test Suite Built-In Tests����������������������������������������������������������������������������������������������� 268 Strategies for Testing Your Own Arduino Derivative ����������������������������������������������������������������� 269 Memory Testing������������������������������������������������������������������������������������������������������������������������ 269 Example: Testing for a Memory Leak�����������������������������������������������������������������������������������������������������������������272 Testing Libraries����������������������������������������������������������������������������������������������������������������������� 273 SPI�transfer() Test ����������������������������������������������������������������������������������������������������������������������������������������������280 setBitOrder() Test �����������������������������������������������������������������������������������������������������������������������������������������������281 setClockDivider() Test ����������������������������������������������������������������������������������������������������������������������������������������281 setDataMode() Test ��������������������������������������������������������������������������������������������������������������������������������������������282 SPI Test Results �������������������������������������������������������������������������������������������������������������������������������������������������282 Summary���������������������������������������������������������������������������������������������������������������������������������� 282 Index�������������������������������������������������������������������������������������������������������������������������������� 283 xv
About the Authors Rick Anderson is Director of Virtual Worlds for Rutgers University, Co-Director of NJ Makerspaces, and Trustee of Fair Use Building and Research Labs. He’s also a sponsor and judge at Hardware Hacking Hackathons, and a featured speaker at TEDxRutgers 2013. Rick teaches basic electronics, Minecraft Circuits in real life, Arduino, and soldering for people of all ages. He designed the original Arduino Test Suite, and is co-designer of the chipKIT Fubarino. His multiplatform code for Arduino 1.5, cowritten with Mark Sproul, won the Blue Ribbon Editor’s Choice award at Maker Faire 2011. Rick is currently working on Morse’s Secret Technology, a series of steampunk robotics and Arduino projects. Dan Cervo (Servo) is a project development director at MAD Fellows LLC, a research and development company started by Doug Bebb and Dan. MAD Fellows has embraced the Arduino and its culture as an essential cornerstone for scientific development and rapid proofs of concept. Dan has worked in ballet, jewelry, and commercial flight management systems. Dan is currently working on research in metamaterials, computational science, iso geometrics, and robotic control theory. xvii
About the Technical Reviewer Cliff Wootton is a former interactive TV systems architect at BBC News. The News Loops service developed there was nominated for a British Academy of Film and Television Arts (BAFTA) award and won a Royal Television Society Award for Technical Innovation. Cliff has been a speaker on preprocessing for video compression at the Apple WWDC conference, and he has taught postgraduate students about real-world computing, multimedia, video compression, metadata, and researching the deployment of next-generation interactive TV systems based on open standards. He is currently working on R&D projects investigating new interactive TV technologies, he’s involved with the MPEG standards working groups, and he’s writing more books on the topic. xix
Acknowledgments Deepest thanks go to Teri, Craig, Doug, Shane, and other family and friends who supported and helped with this project. Thanks to Cliff Sherrill for providing an excellent foundation in computer science. Miguel, Dr. Ayars, and everyone at Adafruit, SparkFun, and Arduino—thanks for your contributions. Rick, Michelle, and the Apress staff—thanks for the opportunity to work on this project. —Dan Cervo First and foremost, thank you with love to my wife, Kristen Abbey. She allowed this book to be the center of our lives until it was done. Many thanks to coauthor Dan Cervo. A giant thank you to all those that helped make this possible, especially Ryan Ostrager. I had so much support from my friends, Mark Sproul, Anjanette Young, Anthony Lioi, and editors Michelle Lowman, Brigid Duffy, Christine Ricketts, and Laura Jo Hess. Thanks Rutgers University for creating such a supportive environment. Thank you David Finegold and Rich Novak, and finally the open source and open hardware communities, without which Arduino, and all of my projects, would not exist. Lastly, thanks to the chipKIT team, which has been responsive and has worked sincerely to achieve the best open source support and vision for multiplatform Arduino. —Rick Anderson xxi
Search
Read the Text Version
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305