/* 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:
* LED attached from pin 13 to ground.
* Note: on most Arduinos, there is already an LED on the board
that's attached to pin 13, so no hardware is needed for this example.
// Pin 13 na većini arduino pločica već ima spojenu diodu.
// Ako spajate svoju diodu na drugi pin, nemojte zaboraviti u seriju staviti otpornik, recimo 1K...
created 2005
by David A. Mellis
modified 8 Feb 2010
by Paul Stoffregen
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
*/
// constants won't change. Used here to
// set pin numbers:
// dodijelite ime pinu na kojem je dioda radi lakšeg programiranja.
// const znači da se vrijednost varijable neće mijenjati
const int ledPin = 13; // the number of the LED pin
// Variables will change:
// Varijable koje će se mijenjati
int ledState = LOW; // ledState used to set the LED
// status LED diode
long previousMillis = 0; // will store last time LED was updated
// pamtit će vrijeme kada se stanje promjenilo
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
// vrijednost intervala je u long varijabli (više na http://arduino.cc/en/Reference/Long)
// ovdje je stavljeno da je varijabla long iz razloga što milisekunde brzo prolaze pa nam int
// ne bi bio dovoljan
long interval = 1000; // interval at which to blink (milliseconds)
// the setup routine runs once when you press reset:
// setup funkcija se pokreće samo jednom kada se mikrokontroler pali ili kada se pritisne restart.
void setup() {
// set the digital pin as output:
// postavi pin 13 (ledPin) kao izlazni pin
pinMode(ledPin, OUTPUT);
}
void loop() {
// here is where you'd put code that needs to be running all the time.
// ovdje stavite vaš kod koji se mora odvijati cijelo vrijeme
// check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
//provjerimo je li vrijeme da upalimo LED diodu;
//a to će se dogoditi ako je razlika između trenutnog vremena i vremena kada je dioda
//zadnji puta upaljena, veća od intervala koji smo odredili.
//interval smo upisali gore i trenutno nam je 1000.
unsigned long currentMillis = millis();
if (currentMillis - previousMillis & gt; interval) {
// save the last time you blinked the LED
// spremimo stanje kada smo zadnji puta upalili LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
// ako je LED upaljena dodjeli stanje HIGH varijabli ledstate
// ako je ugašena dodjeli joj status LOW
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
// upali ili ugasi LED, ovisno u stanju dodijeljenom gore
digitalWrite(ledPin, ledState);
}
}