Paso 3: Software
A continuación, vamos a montar los materiales de software.
- abrir el programa de Arduino
- copiar y pegar el código a continuación en el bosquejo en blanco
- subir el código haciendo clic en la flecha
- para comprobar si el código funciona en consecuencia
Código
int buttonPin = 12;int LED1 = 2; int LED2 = 3; int LED3 = 4; int LED4 = 5; int LED5 = 6; int buttonreading; int previous = LOW; int count=0;long time = 0; long debounce = 300;void setup() { pinMode(buttonPin, INPUT); pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); pinMode(LED3, OUTPUT); pinMode(LED4, OUTPUT); pinMode(LED5, OUTPUT); Serial.begin(9600); } void loop() { buttonreading = digitalRead(buttonPin); if (buttonreading == HIGH && previous == LOW && millis() - time > debounce){ count++; } previous = buttonreading; if (count == 0){ digitalWrite (LED1, LOW); digitalWrite (LED2, LOW); digitalWrite (LED3, LOW); digitalWrite (LED4, LOW); digitalWrite (LED5, LOW); } if (count == 2){ digitalWrite (LED1, HIGH); } if (count ==4){ digitalWrite (LED1, HIGH); digitalWrite (LED2, HIGH); } if (count ==6){ digitalWrite (LED1, HIGH); digitalWrite (LED2, HIGH);q digitalWrite (LED3, HIGH); } if (count ==8){ digitalWrite (LED1, HIGH); digitalWrite (LED2, HIGH); digitalWrite (LED3, HIGH); digitalWrite (LED4, HIGH); } if (count ==10){ digitalWrite (LED1, HIGH); digitalWrite (LED2, HIGH); digitalWrite (LED3, HIGH); digitalWrite (LED4, HIGH); digitalWrite (LED5, HIGH); } if (count >=11){ count = 0; } Serial.print(count); }