Created
February 14, 2012 10:38
-
-
Save magnomp/1825662 to your computer and use it in GitHub Desktop.
Multi-tarefa em Arduino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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