Programs/Classes details
–Introduction to Arduino programming
In the previous section, you learned about the Arduino IDE, the tool of choice for people new to the Arduino. When it comes to the Arduino and microcontrollers in general, programming is a case skill. It's as important at least as a basic understanding of electronics but fear not. It can achieve a lot by achieving a basic level of competency in programming. In this section, I will introduce you to the Arduino programming basics. You will learn about functions, variables, and control structures. You'll learn how to control the Arduino digital input and output pins. You will use this knowledge to control LEDs and read the state of buttons and the geometers, some of the most commonly used components in Arduino prototyping.
Introduction
In this lecture we will talk about loops and conditionals. Conditionals are useful when you want to change the flow of execution in your sketch, and loops are useful when you want to repeat a block of code multiple times. Very often, these two work together and that's why I discuss them here together. Let's start with a conditional, and let's have a look at the simplest conditional out there. It's the "if" statement.
Another very common looping structure that is available on the Arduino is the "for" loop.
The "for" loop is a way to explicitly repeat a block of code a specific number of times that we have predetermined.
In this lecture I will show you how this works.
The next structure that I'd like to show you for this part of the lecture is the "switch" structure.
The "switch" structure provides an easy way to allow you to jump to a particular part of the structure, depending on the value of the variable.
This is useful if you have things such as a bunch of buttons and you want your gadget to do something different depending on which button was pressed.
Now that you have a good, even though it's just the beginning, understanding of some of the basic concepts in Arduino programming. You can move on and have a look at how to use the digital input and output pins that come with the Arduino. Of course input and output are fundamental features of the market controller can connect devices to special pins on your Arduino and to read or change the state of these pins, through special instructions in your sketch. There are two kinds of input and output pins on the Arduino. They are digital and analog pins.
In this lecture,we'll start with digital pins.
Getting an LED to blink is quite easy once you understand how to configure a digital pin to become an output control, the delay, and so on fairly simple.
But what about a button? A button requires to configure a digital pin as an input, so that we can use it to detect the button's state. In this lecture, I will show you how to do this.
In this lecture we will continue our work with the Arduino's input/output pins by taking a look at the analog pins.
Analog signals on microcontrollers is a tricky topic. Most microcontrollers can't generate true analog signals, that means they cannot create and output true analog signals, like an audio signal for example. But they are better at reading analog signals, so they can read for example, the output of a microphone. The atmega328p which is used in the Arduino Uno simulates analog signals using a technique called "pulse width modulation", and I'll talk a little bit about it a bit later when we look at how we can get the LED to, instead of just turning on and off, to get it to fade gradually from an fully off state to a fully on state.
No comments:
Post a Comment