apuntes_Arduino/leds/testSerial2Leds/testSerial2Leds.ino
jp.av.dev 85bf8bb429 proyectos renombrados, reestructuracion
pendientes crear, indexar y linkear readmes
2022-04-04 01:11:04 -04:00

67 lines
1.0 KiB
C++
Executable File

void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
Serial.begin(9600);
}
void ciclo1() {
int i=0;
while (i < 5) {
digitalWrite(3, LOW);
digitalWrite(2, HIGH);
delay(500);
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
delay(500);
++i;
}
apagaLeds();
}
void ciclo2() {
int j=0;
while (j < 5) {
digitalWrite(3, LOW);
digitalWrite(2, HIGH);
delay(50);
digitalWrite(2, LOW);
digitalWrite(2, HIGH);
delay(50);
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
delay(50);
digitalWrite(3, LOW);
digitalWrite(3, HIGH);
++j;
}
apagaLeds();
}
void apagaLeds() {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
}
void loop() {
int serialCom;
if (Serial.available() > 0) {
serialCom = Serial.read();
Serial.print("Valor Recibido : ");
Serial.println(serialCom);
switch (serialCom) {
case 49:
ciclo1();
break;
case 50:
ciclo2();
break;
default:
apagaLeds();
}
delay(100);
Serial.read();
}
}