Professional Documents
Culture Documents
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() {
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.