وبلاگ بلیان

Beginning C for Arduino [learn C programming for the Arduino and compatible microcontrollers ; take complete control of your Arduino with the power of C

جلد کتاب Beginning C for Arduino [learn C programming for the Arduino and compatible microcontrollers ; take complete control of your Arduino with the power of C

معرفی کتاب «Beginning C for Arduino [learn C programming for the Arduino and compatible microcontrollers ; take complete control of your Arduino with the power of C» نوشتهٔ Jack J Purdum، منتشرشده توسط نشر Apress : Distributed to the Book trade worldwide by Springer Science+Business Media در سال 2012. این کتاب در فرمت pdf، زبان انگلیسی ارائه شده است.

Beginning C for Arduino is written for those who have no prior experience with microcontrollers or programming but would like to experiment and learn both. This book introduces you to the C programming language, reinforcing each programming structure with a simple demonstration of how you can use C to control the Arduino family of microcontrollers. Author Jack Purdum uses an engaging style to teach good programming techniques using examples that have been honed during his 25 years of university teaching. Beginning C for Arduino will teach you: * The C programming language * How to use C to control a microcontroller and related hardware * How to extend C by creating your own library routines During the course of the book, you will learn the basics of programming, such as working with data types, making decisions, and writing control loops. You'll then progress onto some of the trickier aspects of C programming, such as using pointers effectively, working with the C preprocessor, and tackling file I/O. Each chapter ends with a series of exercises and review questions to test your knowledge and reinforce what you have learned. What you'll learn * The syntax of the C programming language as defined for the Arduino * Tried and true coding practices (applicable to any programming language) * How to design, code, and debug programs that drive Arduino microcontrollers * How to extend the functionality of C * How to integrate low cost, off-the-shelf, hardware shields into your own projects Who this book is for The book is aimed at a complete novice with no programming background. It assumes no prior programming or hardware design experience and is written for creative and curious people who would like to blend a software and hardware learning experience into a single, enjoyable endeavor. Cover 1 Contents at a Glance 5 Contents 6 About the Author 14 About the Technical Reviewer 15 Acknowledgments 16 Introduction 17 Assumptions About You 18 Resources 18 Chapter 1: Introduction 19 Assumptions About You 20 What You Need 21 An Atmel-Based Microcontroller Card 21 Breadboard 23 Miscellaneous Parts 24 Verifying the Software 24 Verifying the Hardware 26 Attaching the USB Cable 26 Selecting Your 27 c Board in the Integrated Development Environment 27 Port Selection 28 Loading and Running Your First Program 31 The Blink Program 32 Running the Blink Program Code 34 Compiling the Blink Program Code 35 Uploading the Blink Program 36 Summary 38 Chapter 2: Arduino C 39 The Building Blocks of All Programming Languages 39 Expressions 39 Statements 41 Statement Blocks 42 Function Blocks 43 The Five Program Steps 44 1. Initialization Step 44 2. Input Step 44 3. Process Step 44 4. Output Step 45 5. Termination Step 45 The Purpose of the Five Program Steps 45 A Revisit to the Blink Program 46 Program Comments 47 Data Definition 48 The setup() Function 50 The loop() Function 52 Summary 53 Exercises 54 Chapter 3: Arduino C Data Types 55 Unknown -1 Keywords in C 56 Variable Names in C 56 The boolean Data Type 57 The char Data Type 57 Binary Data 57 The char Data Type and Character Sets 58 Generating a Table of ASCII Characters 59 The byte Data Type 60 The int Data Type 61 The word Data Type 61 The long Data type 61 The float and double Data Types 61 Floating Point Precision 62 The string Data Type 62 String Data Type 63 The void Data Type 64 The array Data Type 65 Defining versus Declaring Variables 65 Symbol Tables 65 lvalues and rvalues 66 The Bucket Analogy 68 Using the cast Operator 70 Summary 71 Exercises 72 Chapter 4: Decision Making in C 73 Relational Operators 73 The if Statement 74 A Modified Blink Program 76 The Circuit 77 The Program Code 78 The if-else Statement 80 Cascading if Statements 81 The Increment and Decrement Operators 83 Two Types of Increment Operator (++) 83 Two Flavors of the Decrement Operator (--) 84 Precedence of Operators 84 The switch Statement 85 The goto Statement 86 Getting Rid of Magic Numbers 86 The C Preprocessor 86 Heads or Tails 89 Initialization Step 89 Input Step 89 Process Step 89 Output Step 89 Termination Step 90 Something to Think About 92 Summary 93 Exercises 94 Chapter 5: Program Loops in C 95 The Characteristics of Well-Behaved Loops 95 Condition 1: Variable Initialization 95 Condition 2: Loop Control Test 96 Condition 3: Changing the Loop Control Variable’s State 96 Using a for Loop 96 The while Loop 98 The do-while Loop 99 The break and continue Keywords 100 The break Statement 100 The continue Statement 101 A Complete Code Example 102 Step 1. Initialization 103 Step 2. Input 103 Step 3. Process 103 Step 4. Output 103 Step 5. Termination 103 Listing 5-1 is Sorta Dumb Code 105 Loops and Coding Style 106 Summary 107 Exercises 108 Chapter 6: Functions in C 109 The Anatomy of a Function 110 Function Type Specifier 110 Function Name 110 Function Arguments 111 Function Body 112 Function Signature 113 What Makes a “Good” Function 114 Functions Use Task-Oriented Names 114 The Function Should Be Cohesive 114 Functions Should Avoid Coupling 115 Writing Your Own Functions 115 Function Design Considerations 116 Argument List 117 Function Body 117 Logical Operators 118 Logical AND Operator (&&) 118 Logical OR (||) 119 Logical NOT (!) 119 Writing Your Function 120 The IsLeapYear() Function and Coding Style 121 Arguments versus Parameters 121 Why Use a Specific Function Style? 122 Leap Year Calculation Program 122 Passing Data Into and Back From a Function 125 Pass by Value 126 Summary 128 Exercises 129 Chapter 7: Storage Classes and Scope 130 Hiding Your Program Data 130 Statement Block Scope 130 Local Scope 133 Name Collisions and Scope 134 Global Scope 136 Global Scope and Name Conflicts 138 Scope and Storage Classes 138 The auto Storage Class 138 The register Storage Class 138 The static Storage Class 139 The extern Storage Class 139 The volatile keyword 144 Summary 145 Exercises 146 Chapter 8: Introduction to Pointers 147 Defining a Pointer 147 Pointer Name 147 Asterisk 148 Pointer Type Specifiers and Pointer Scalars 148 Using a Pointer 152 The Indirection Operator (*) 153 Using Indirection 153 Summary of Pointer Rules 157 Why Are Pointers Useful? 157 Pointers and Arrays 161 The Importance of Scalars 164 Summary 165 Exercises 166 Chapter 9: Using Pointers Effectively 167 Relational Operations and Test for Equality Using Pointers 167 Pointer Comparisons Must be Between Pointers to the Same Data 168 Pointer Arithmetic 168 Constant lvalues 172 Two-Dimensional Arrays 173 A Small Improvement 175 How Many Dimensions? 176 Two-Dimensional Arrays and Pointers 176 Treating the Two-Dimensional Array of chars as a String 178 Pointers to Functions 178 Arrays of Pointers to Functions 180 enum Data Type 180 The Right-Left Rule 184 Summary 185 Exercises 186 Chapter 10: Structures, Unions, and Data Storage 187 Structures 187 Declaring a Structure 188 Defining a Structure 189 Accessing Structure Members 190 Returning a Structure from a Function Call 192 Using Structure Pointers 194 Initializing a Structure 197 Arrays of Structures 197 Unions 198 EEPROM Memory 199 Using EEPROM 200 Data Logging 200 Other Storage Alternatives 207 Shields 207 Other Uses for Secure Digital Storage 209 Summary 211 Exercises 212 Chapter 11: The C Preprocessor and Bitwise Operations 213 Preprocessor Directives 213 #undef 215 #line 216 #if, Conditional Directives 216 #include 218 Parameterized Macros 218 Bitwise Operators 219 Bitwise Shift Operators 221 Using Different Bases for Integer Constants 223 Parameterized Macros...continued 223 Summary 224 Exercises 225 Chapter 12: Arduino Libraries 226 Libraries 226 Arduino Libraries 226 Other Libraries 233 Writing Your Own Library 235 The Library Header File 236 The Library Code File (Dates.cpp) 237 Setting the Arduino IDE to Use Your Library 239 A Sample Program Using the Dates Library 240 Adding the Easter Program to the IDE 242 The keywords.txt File 242 Keyword Coloring (theme.txt) 242 Summary 244 Exercises 245 Appendix A: Suppliers and Sources 246 Suppliers 246 Seeedino Studio 246 Diligent Inc 247 OSEPP 248 Tinyos Electronics 248 Cooking Hacks 249 Sources 250 Software 251 Appendix B: Electronic Components for Experiments 252 Microcontroller Board 252 Solderless Breadboard 252 Electronic Components 252 Online Component Purchases 253 Experiment! 254 Answers to Exercises 255 Chapter 2 255 Chapter 3 256 Chapter 4 258 Chapter 5 260 Chapter 6 262 Chapter 7 263 Chapter 8 264 Chapter 9 265 Chapter 10 266 Chapter 11 268 Chapter 12 269 Index 271 A 271 B 272 C 272 D 273 E 274 F 274 G, H 274 I 274 J, K 274 L 274 M 274 N 274 O 274 P, Q 274 R 275 S 275 T 276 U 276 V 276 W, X, Y, Z 276 Apress

Beginning C for Arduinois written for those who have no prior experience with microcontrollers or programming but would like to experiment and learn both. This book introduces you to the C programming language, reinforcing each programming structure with a simple demonstration ofhow you can use C to control the Arduino family of microcontrollers. Author Jack Purdum uses an engaging style to teach good programming techniques using examples that have been honed during his 25 years of university teaching.

Beginning C for Arduino willteach you:

  • The C programming language
  • How to use C to control a microcontroller and related hardware
  • How to extend C by creating your own library routines

During the course of the book, you willlearn the basics of programming, such as working with data types, making decisions, and writing control loops. You'll then progress onto some of the trickier aspects of C programming, such as using pointers effectively, working with the C preprocessor, and tackling file I/O. Each chapter ends with a series of exercises and review questions to test your knowledge and reinforce what you have learned.

What you’ll learn

  • The syntax of the C programming language as defined for the Arduino
  • Tried and true coding practices (applicable to any programming language)
  • How to design, code, and debug programs that drive Arduino microcontrollers
  • How to extend the functionality of C
  • How to integrate low cost, off-the-shelf, hardware shields into your own projects
Who this book is for

The book is aimed at a complete novice with no programming background. It assumes no prior programming or hardware design experience and is written for creative and curious people who would like to blend a software and hardware learning experience into a single, enjoyable endeavor.

Table of Contents

  1. Introduction to Arduino Microcontrollers
  2. Arduino C
  3. Data Types
  4. Decision Making in C
  5. Program Loops
  6. Functions in C
  7. Storage Classes and Scope
  8. Introduction to Pointers
  9. Using Pointers Effectively
  10. I/O Operations
  11. The C Preprocessor
  12. Arduino Libraries
  13. Appendix A - Suppliers
  14. Appendix B - Hardware Components
دانلود کتاب Beginning C for Arduino [learn C programming for the Arduino and compatible microcontrollers ; take complete control of your Arduino with the power of C