Skip to content

Instantly share code, notes, and snippets.

@magnomp
Created February 14, 2012 10:38
Show Gist options
  • Save magnomp/1825662 to your computer and use it in GitHub Desktop.
Save magnomp/1825662 to your computer and use it in GitHub Desktop.
Multi-tarefa em Arduino
/* Um led conectado ao pino 13 é acionado mediante um botão ligado ao pino 2. Paralelamente a
isso, um led conectado ao pino 3 pisca em intervalos de 1s */
#define BOTAO 2
#define LED_BOTAO 13
#define LED_PISCA 3
unsigned long start = 0;
int estado_led = LOW;
void setup() {
pinMode(BOTAO, INPUT);
pinMode(LED_BOTAO, OUTPUT);
pinMode(LED_PISCA, OUTPUT);
}
void loop() {
digitalWrite(LED_BOTAO, digitalRead(BOTAO));
unsigned long current = millis();
if ((current - start) >= 1000) {
estado_led = (estado_led == HIGH)?LOW:HIGH;
digitalWrite(LED_PISCA, estado_led);
start = current;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment