You are on page 1of 10

Arduino e Arm

Desenvolvendo para Arduino


O ambiente do arduino, disponvel para
download gratuito em http://arduino.cc
A utilizao de programao C, permite que
independente da plataforma de hardware em
que ser executado o programa, o programa
original no precisa ser customizado exceto no
caso de aplicaes especficas que fazem
acesso direto aos recursos de hardware.
Cdigo Exemplo
void setup() {
// Coloque aqui o cdigo de inicializao, que ser executado
//uma nica vez.:

void loop() {
// Coloque aqui o cdigo principal, que ser executado repetidas vezes.

}
Cdigo Led Blink
// the setup function runs once when you press reset or power the board
void setup() {

pinMode(13, OUTPUT); // initialize digital pin 13 as an output.


}

// Executa o loop repetidas vezes


void loop() {
digitalWrite(13, HIGH); // Liga o LED (HIGH o nvel de tenso)
delay(1000); // Espera um segundo
digitalWrite(13, LOW); // Desliga o Led jogando a tenso LOW no pino do LED
delay(1000); // Espera um segundo
}
Cdigo LED fade
int led = 9; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by

void setup() {
pinMode(led, OUTPUT); // declare pin 9 to be an output:
}
void loop() {
analogWrite(led, brightness); // set the brightness of pin 9:
brightness = brightness + fadeAmount; // change the brightness for next time through the
loop:
if (brightness == 0 || brightness == 255) { // reverse the direction of the fading at the ends of
the fade:
fadeAmount = -fadeAmount ;
}
Delay(30); // wait for 30 milliseconds to see the dimming effect
}
Interrupes
Interrupes Softwares
Pacote adicional
https://github.com/GreyGnome/PinChangeInt
Circuito Interrupo

http://labdegaragem.com/profiles/blogs/tutorial-sobre-interrup-es-no-arduino
Cdigo Interrupo
int pin = 13;
volatile int state = LOW;
volatile int state1 = LOW;
void setup()
{
pinMode(pin, OUTPUT);
attachInterrupt(0, blink, FALLING); // 0 - Pin 2, blink is the function that will be called e FALLING it
is when
} // the pin goes the HIGH to LOW
void loop()
{ digitalWrite(pin, state);
}
void blink()
{ if(state==state1){
state = !state1;
}else{
state=state1;
}
}
Principais comandos do Arduno
pinMode(Pin, [INPUT|OUTPUT])
define o pino Pin como entrada(INPUT) ou sada(OUTPUT)
digitalWrite(Pin,[HIGH|LOW]);
Define o nvel de sada do pino Pin em HIGH(5v) ou Low(Gnd)
analogWrite(Pin, [0-255]);
Utiliza o modulo pwm do processador para gerar no pino Pin uma sada
proporcional ao numero informado onde 0 = LOW e 255 = HIGH. Obs.
Essa sada no contnua no tempo
analogRead(Pin);
Retorna um valor entre 0 e 255 proporcional a tenso aplicada ao

pino Pin.

You might also like