0% found this document useful (0 votes)
25 views

Arduino LED Projekt

This document contains 3 Arduino code examples that control LEDs using buttons or timed delays: 1. The first example uses variables to set a pin number and time delay, and toggles an LED on and off with each delay. 2. The second example uses constants to set a button pin and LED pin, and toggles the LED based on the button state being read as HIGH or LOW. 3. The third example uses variables to track the current and last button state, and toggles the LED only when the button is released by detecting a LOW after a HIGH state.

Uploaded by

starinandor
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Arduino LED Projekt

This document contains 3 Arduino code examples that control LEDs using buttons or timed delays: 1. The first example uses variables to set a pin number and time delay, and toggles an LED on and off with each delay. 2. The second example uses constants to set a button pin and LED pin, and toggles the LED based on the button state being read as HIGH or LOW. 3. The third example uses variables to track the current and last button state, and toggles the LED only when the button is released by detecting a LOW after a HIGH state.

Uploaded by

starinandor
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Arduino LED projekt

int LedPin=2; //Deklarišemo promenljivu LedPin i dodeljujemo vrednost 2 tj. broj pina na koji povezujemo diodu
int vreme=1000; // Deklarišemo promenljivu vreme u milisekundama

void setup() {
pinMode(LedPin, OUTPUT); //LedPin će postati izlazni port
}

void loop() {
digitalWrite(LedPin, 0); // isključujemo led
delay(vreme); // pauza
digitalWrite(LedPin, 1); // uključujemo led
delay(vreme); // pauza
}
Led i dugme

const int buttonPin = 3; // the number of the pushbutton pin


const int ledPin = 2; // the number of the LED pin

// variables will change:


int buttonState = 0; // variable for reading the pushbutton status

void setup() {
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
Serial.println(buttonState);

// 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);
}
}
Dugme koje pali i gasi led

int ledPin=2;
int buttonPin=3;
int buttonState=LOW;
int lastButtonState=LOW;

void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}

void loop() {
buttonState=digitalRead(buttonPin);
Serial.println(buttonState);
Serial.println(lastButtonState);
Serial.println("--------------");
if(buttonState== LOW && lastButtonState==HIGH)
{
delay(5);
digitalWrite(ledPin, !digitalRead(ledPin));
}
lastButtonState=buttonState;
}

You might also like