///////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////// Empregamos milis para facer un blink nun led, e por outro lado ////////////// /////////////////////// activamos de maneira intantanea outro led cun interruptor /////////////// /////////////// Se o fixésemos co delay o segundo led non seguiría exactamente ó interruptor /////// //////////////////////// xa que pararía o programa durante o delay /////////////////////////////// /*Blink without Delay Turns on and off a light emitting diode (LED) connected to a digital pin, without using the delay() function. This means that other code can run at the same time without being interrupted by the LED code. The circuit: - Use the onboard LED. - Note: Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to the correct LED pin independent of which board is used. If you want to know what pin the on-board LED is connected to on your Arduino model, check the Technical Specs of your board at: https://www.arduino.cc/en/Main/Products created 2005 by David A. Mellis modified 8 Feb 2010 by Paul Stoffregen modified 11 Nov 2013 by Scott Fitzgerald modified 9 Jan 2017 by Arturo Guadalupi This example code is in the public domain. http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay */ // Declaramos as variables const int led1 = 13;// the number of the LED pin const int led2 = 12; const int interruptor = 7; // Inicializamos as variables en nivel baixo int led1State = LOW; int led2State = LOW; int val = 0; //val empregaremolo para almacenar o estado do interruptor // Generally, you should use "unsigned long" for variables that hold time // The value will quickly become too large for an int to store unsigned long previousMillis = 0; // will store last time LED was updated // constants won't change: const long interval = 1000; // interval at which to blink (milliseconds) void setup() { // set the digital pin as output: pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(interruptor,INPUT_PULLUP); // y BOTON como señal de entrada } void loop() { // Nesta parte controlaremos o led 1 coa función milis // Controlaremos a diferenza entre o tempo actual e o inicial. E no momento que a diferenza sexa // maior que o intervalo cambiase o valor actual polo inicial de novo, faise outra contaxe e así sucesivamente unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= interval) { // save the last time you blinked the LED previousMillis = currentMillis; // Cambiaremos o estado do led cada vez que entremos neste if, cada vez que se cumpra o tempo do intervalo if (led1State == LOW) { led1State = HIGH; } else { led1State = LOW; } // Escribimos o estado do led 1 digitalWrite(led1, led1State); } // Nesta parte controlamos o led 2 co interruptor val= digitalRead(interruptor); // Lemos o estado do interruptor digitalWrite(led2, val); // Escribimos o estado almacenado do interruptor no led 2 }