Sketch Arduino FFH
Multitareas con Led 2 y Tarea paralela con Led 13
/**
* Sketch 5 FFH. Tres máquinas de estado
* Agregando otro FFH sketch Buton eniende led 13
* LED attached from pin 13 to ground
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground
*/
const int buttonPin = 2;
const int ledPin = 13;
int buttonState = 0;
int ledUnoPin = 7;
int ledDosPin = 8;
int ledTresPin = 9;
int ledUnoEstado = LOW;
long temporizadorUno = 0;
int intervaloUno = 1000;
int ledDosEstado = LOW;
long temporizadorDos = 0;
int intervaloDos = 100;
int ledTresEstado = LOW;
long temporizadorTres = 0;
int intervaloTres = 200;
void setup() {
pinMode(ledUnoPin, OUTPUT);
pinMode(ledDosPin, OUTPUT);
pinMode(ledTresPin, OUTPUT);
pinMode(ledPin,OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
} else
// turn LED off:
digitalWrite(ledPin, LOW);
// máquina uno
if (millis() - temporizadorUno > intervaloUno) {
if (ledUnoEstado == HIGH) {
ledUnoEstado = LOW;
}
else {
ledUnoEstado = HIGH;
}
digitalWrite(ledUnoPin, ledUnoEstado);
temporizadorUno = millis();
}
// máquina dos
if (millis() - temporizadorDos > intervaloDos) {
if (ledDosEstado == HIGH) {
ledDosEstado = LOW;
}
else {
ledDosEstado = HIGH;
}
digitalWrite(ledDosPin, ledDosEstado);
temporizadorDos = millis();
}
// máquina Tres
if (millis() - temporizadorTres > intervaloTres) {
if (ledTresEstado == HIGH) {
ledTresEstado = LOW;
}
else {
ledTresEstado = HIGH;
}
digitalWrite(ledTresPin, ledTresEstado);
temporizadorTres = millis();
}
}

