Skip to main content

Basics of Arduino - First C Program : Chapter 3

The only language you really need to know to code an Arduino is C++. Even with just the basics, you can do quite a lot. These are some things I think are a must to know:

 

  • Variables
  • If Statments
  • Loops
  • Importing Classes
  • Calling Functions

 

 Next you can download the Arduino IDE and install your system.




 

 

 

 

 

 

 If this is the first time you run the Desktop IDE, you can see a tab (called sketch) filled with the two basic Arduino functions: the setup() and loop().

 

setup():

 Use it to initialize variables, pin modes, start using libraries and etc. The setup() function will only run once and after each power-up or reset of the Arduino board 

int pin = 3;

void setup() {
  pinMode(pin, INPUT);
}

void loop() {
  // ...
}
 

loop():

After creating a setup() function, which initialize and set up the initial values and loop() function does precisely what its name suggests, and loops consecutively, allowing your program to change and respond. Use it to actively control the Arduino board.



void setup() { 
  // put your setup code here, to run once: 
  pinMode(13,OUTPUT); 
 } 
 void loop() { 
  // put your main code here, to run repeatedly: 
   digitalWrite(13,HIGH); 
  // digitalWrite(13,LOW);
 }
 
 

Then you can compile the program and upload to Arduino Board and Finally see the result.



 

 

Comments

Popular posts from this blog

Basics of Arduino: Chapter 1

Arduino is an electronics open source platform based on use hardware and software. It can be able to read inputs (light on sensor,figure on a burr-on, or send message) and turn it into an output (activating a motor, turning on LED, publishing something online).   First of all I'm introducing to Arduino Boards  1. ARDUINO UNO R3   ARDUINO UNO R3 based board( Micro-controller) . It has 20 digital input/output pin. Which 6 can be used as PWM ( Pulse Width Modulation ) outputs and 6 can be used as analog inputs.    Arduino Board The Main components of Arduino UNO board are as follows: USB connector Power port Micro-controller Analog input pins Digital pins Reset switch Crystal oscillator USB interface chip TX RX LED's  

Arduino Uno vs Arduino Mega: Chapter 2

The differences between Arduino UNO and Arduino Mega 2560 are as follow. The Arduino UNO is a microcontroller board based on the ATmega328 (datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz ceramic resonator, a USB connection, a power jack, an ICSP header, and a reset button.   Arduino Uno The UNO differs from all preceding boards in that it does not use the FTDI USB-to-serial driver chip. Instead, it features the Atmega16U2 (Atmega8U2 up to version R2) programmed as a USB-to-serial converter.     Arduino Mega 2560 The Arduino Mega 2560 is a microcontroller board based on the ATmega2560 (datasheet). It has 54 digital input/output pins (of which 15 can be used as PWM outputs), 16 analog inputs, 4 UARTs (hardware serial ports), a 16 MHz crystal oscillator, a USB connection, a power jack, an ICSP header, and a reset button. The Mega is compatible with most shields designed for the Arduino Duemilanove or Diecimila.