Book Image

Learning C for Arduino

By : Syed Omar Faruk Towaha
Book Image

Learning C for Arduino

By: Syed Omar Faruk Towaha

Overview of this book

This book will start with the fundamentals of C programming and programming topics, such data types, functions, decision making, program loops, pointers, and structures, with the help of an Arduino board. Then you will get acquainted with Arduino interactions with sensors, LEDs, and autonomous systems and setting up the Arduino environment. Moving on you will also learn how to work on the digital and analog I/O, establish serial communications with autonomous systems, and integrate with electronic devices. By the end of the book, you will be able to make basic projects such as LED cube and smart weather system that leverages C.
Table of Contents (17 chapters)
Learning C for Arduino
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Data types


In our day-to-day life, we use numbers, alphabets, words, and sentences. These can be defined as data. Again, numbers can be divided into two types: fraction and non-fraction, or integer and non-integer. Alphabets and symbols can be defined as characters. Let's look at what we call them in C, and their memory allocation. I will explain what memory allocation is and how you can find out how much memory a data type is consuming later.

Integers

Numbers that can be written without a fractional part are called integers: 5, 28, 273, 100, 986,343 are integers. There are negative integers too: -56, -87, -23,453, -1,000, and so on. They are called int in C programming. If we want to set a variable (number) equal to an integer (here, 24) we can write the following:

int number = 24;

An integer occupies 2 bytes (16 bits) or 4 bytes (32 bits) of memory depending on the processor's architecture. On 32-bit computers, an integer occupies 2 bytes of memory, and on 64-bit computers, integer occupies...