Sunday 1 January 2017

WEEK 5

Date: 24/10/2017
TITLE: Learn about arduino and C language 


In this week I’m continuing my research about C programming language to use in Arduino UNO. This time the research is going into learn about basic introduction in C language, flow control, function, array and structure & file. In programming, functions and flow control is very important to write the code.  I also need to take a long time to study this part. As mentioned, it’s a good language to start learning programming. If you know C programming, you will not just understand how your program works, but you will also be able to create a mental picture on how a computer works. Programming is a very fun and interesting to learn!

Download Arduino Software

Firstly, you need to download the Arduino Software package for your operating system from the Arduino download page.

When you’ve downloaded and opened the application you should see something like this:
Arduino Software

This is where you type the code you want to compile and send to the Arduino board.

The Initial Setup

We need to setup the environment to Tools menu and select Board.


Tools Menu < Board
Then select the type of Arduino you want to program, in our case it’s the Arduino Uno.


Arduino Uno

The Code

The code you write for your Arduino are known as sketches. They are written in C++.
Every sketch needs two void type functionssetup() and loop(). A void type function doesn’t return any value.
The setup() method is ran once at the just after the Arduino is powered up and the loop() method is ran continuously afterwards. The setup() is where you want to do any initialisation steps, and in loop() you want to run the code you want to run over and over again.
So, your basic sketch or program should look like this:
1
2
3
4
5
6
7
8
9
void setup()
{
}
void loop()
{
}
Now we have the basic skeleton in place we can now do the Hello, World program of microcontrollers, a blinking an LED.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int ledPin = 13;
void setup()
{
pinMode(ledPin, OUTPUT); //set ledPin as OUTPUT
}
void loop()
{
digitalWrite(ledPin, HIGH); //set ledPin High is mean LED will ON
delay(2000); //call function delay and set 2000 is mean 2 seconds
digitalWrite(ledPin, LOW); //set ledPin High is mean LED will ON
delay(2000);
}
Press Upload and you should see LED in port 13 will blinking in every 2 seconds

No comments:

Post a Comment