---
# System prepended metadata

title: UKR

---

## Vaja 1
```c=
int buttonGreen = 2;
int buttonRed = 3;
int Pinled = 8;

void setup() {
  // put your setup code here, to run once:
  pinMode(buttonGreen, INPUT_PULLUP);
  pinMode(buttonRed, INPUT_PULLUP);
  pinMode(Pinled, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (digitalRead(buttonRed) == LOW) digitalWrite(Pinled, HIGH);
  else if (digitalRead(buttonGreen) == LOW) digitalWrite(Pinled, LOW);
  
  // Ali:
  digitalWrite(Pinled, buttonState);
  
}
```
![](https://hackmd.io/_uploads/HkHeGh916.png)

## Vaja 2
```c=
int buttonGreen = 2;
int buttonRed = 3;
int Pinled = 8;

void setup() {

  pinMode(buttonGreen, INPUT_PULLUP);
  pinMode(buttonRed, INPUT_PULLUP);
  pinMode(Pinled, OUTPUT);
}

void loop() {
  static bool buttonState = true;// Lokalna spremenljivka ki se obnaša kot globalna

  if (digitalRead(buttonRed) == LOW) buttonState = true;
  else if (digitalRead(buttonGreen) == LOW) buttonState = false;

  //if (buttonState == true) digitalWrite(Pinled, HIGH);
  //else digitalWrite(Pinled, LOW);

  digitalWrite(Pinled, buttonState);
```

## Vaja 3 
```c=
int buttonGreen = 2;
int Pinled = 8;

void setup() {

  pinMode(buttonGreen, INPUT_PULLUP);
  pinMode(Pinled, OUTPUT);
  Serial.begin(115200);
}

void loop() {
  static bool m = false;
  bool buttonState = digitalRead(buttonGreen);// Lokalna spremenljivka ki se obnaša kot globalna
  if (buttonState == false & m == false){
    m = !m;
    digitalWrite(Pinled, HIGH);
    delay(500); // 500 ms zakasnitve 
  }
  else if (buttonState == false & m == true){
    m =!m;
    digitalWrite(Pinled, LOW);
    delay(500);
  }
}

```
![](https://hackmd.io/_uploads/BkKNIncya.png)
## Vaja 4 - Utripanje Led (SOS - morsova koda)
Zanka for:
for(1.int x=0;2.x<3,3.x++){

}
1. Začetna vrednost
2. Pogoj
3. Kaj naj se zgodi ob vsakem poteku 
```c=
int pin = 10;


void setup() {
  pinMode(pin, OUTPUT);
  
}

void loop() {
  for (int x=0;x < 3; x++){
    digitalWrite(pin, HIGH);
    delay(150);
    digitalWrite(pin, LOW);
    delay(100);
  }
    for (int x=0;x < 3; x++){
    digitalWrite(pin, HIGH);
    delay(400);
    digitalWrite(pin, LOW);
    delay(100);
  }
  for (int x=0;x < 3; x++){
    digitalWrite(pin, HIGH);
    delay(150);
    digitalWrite(pin, LOW);
    delay(100);
  }
  delay(3000);
```

## Vaja5
```c=
void setup() {
  DDRD = 0xFF; // 255 ali 0b111111111; Vse pine porta D smo določili kot izhod

}

void loop() {
  PORTD |= 0x14; //0b00010100(1<<PD2) | ((1<<PD6));
  delay(500);
  PORTD = (0>>PD2) | ((0>>PD6));// &= 0x14
  delay(500);
  
}
```
![image.png](https://hackmd.io/_uploads/SyQ94X9QT.png)
#### Vaja 6
```c= 
unsigned long changeTime;// = 0;
int ledDelay = 300; // 300 ms zakasnitev
bool m = HIGH;

void setup() {
  DDRD = 0x04;  // smerni register
  //changeTime = millis();

}

void loop() {
  if ((millis()-changeTime) > ledDelay){
    changeTime = millis();
    m = !m;
  }
  if (m == HIGH){
    PORTD |= 0x04;
  }
  if (m == LOW){
    PORTD &= !0x04; // = 0xFB
  } 
}
```
![image](https://hackmd.io/_uploads/SkTlU_iQT.png)
## Vaja 7

```c=
unsigned long changeTime;// = 0;
int ledDelay = 300; // 300 ms zakasnitev
bool m = HIGH;
bool vhod;

void setup() {
  DDRD = 0x04;  // smerni register
  //changeTime = millis();
  PORTD |= 0x80; //interni pull up za pin PD7
  
  Serial.begin(115200);
}

void loop() {

  vhod = PIND & 0x80; // filter => vhod = 0 ali 128
  Serial.println(vhod);
  if (vhod != 0){ // if(vhod) ali if(vhod == HIGH)(če je bool) ali if(vhod == 128) (če je int)
    if ((millis()-changeTime) > ledDelay){
      changeTime = millis();
      m = !m;
    }
    if (m == HIGH){
      PORTD |= 0x04;
    }
    if (m == LOW){
      PORTD &= !0x04; // = 0xFB
    } 
  }
  
}

```
![image](https://hackmd.io/_uploads/SkIr1ti7p.png)

Z digital.write(), digital.read() in pinMode()
```c=
unsigned long changeTime;// = 0;
int ledDelay = 300; // 300 ms zakasnitev
bool m = HIGH;
bool vhod;
int led = 2;
int btn = 7;


void setup() {
  pinMode(btn, INPUT);
  pinMode(led, OUTPUT);
  Serial.begin(115200);
}

void loop() {

  vhod = digitalRead(btn); // filter => vhod = 0 ali 128
  Serial.println(vhod);
  if (vhod == HIGH ){ // if(vhod) ali if(vhod == HIGH)(če je bool) ali if(vhod == 128) (če je int)
    if ((millis()-changeTime) > ledDelay){
      changeTime = millis();
      m = !m;
    }
    if (m == HIGH){
      digitalWrite(led, HIGH);
    }
    if (m == LOW){
      digitalWrite(led,LOW); // = 0xFB
    } 
  }
  else digitalWrite(led, LOW);
}
```
## Vaja 8 - Knight Rider
```c=
int timeDelay = 300;
unsigned long timeChange;
int counter = 1;
byte direction = HIGH;

void setup() {
  DDRD = 0xFF; // port D je izhod
  DDRB |= 0; //port B je vhod
}

void loop() {
  PORTD = counter;
  if((millis() - timeChange)>timeDelay){
    timeChange = millis();
   if(direction == HIGH){
    counter *= 2;
    }
  else counter/=2;
  if (counter > 64) direction = LOW;
  if (counter <= 1) direction = HIGH;

  }
}

```
![image](https://hackmd.io/_uploads/rkPBP24Ep.png)
## Vaja 9 - Light Show
```c= 
int ledPin[]={1,2,4,8,16,32,64,128,255,0,255,128,64,32,16,8,4,2,1,255,0,255};
int ledPin1[] = {255,0,255,0};

void setup(){
  DDRD = 0XFF;
  DDRB |= 0x00;
}

void loop() {
  int value = PINB & 0x01;
  if(value == HIGH){
    for (int x=0; x<(sizeof(ledPin)/ sizeof(ledPin[0])) ; x++){
    PORTD = ledPin[x];
    delay(300);
    }
  }
  if (value == LOW){
    for (int x=0; x<(sizeof(ledPin1)/ sizeof(ledPin1[0])) ; x++){
    PORTD = ledPin1[x];
    delay(300);
    }  
  }
}
```
![image](https://hackmd.io/_uploads/Bk1ta3N46.png)
## Vaja 10
```c=
void setup(){
  for(int x=0; x < 8; x++){
    pinMode(x, OUTPUT);
  }
}

void loop(){
  for(int y=0; y<8; y++){
    digitalWrite(y, HIGH);
    delay(500);
    }
  for (int y =8; y>=0; y--){
    digitalWrite(y, LOW);
    delay(500);
  }
}
```
![image](https://hackmd.io/_uploads/B19vVx5Vp.png)
## Vaja 11
```c=
int digit[8] = {0x01,0x02,0x04,0x08,0x010,0x20,0x40,0x80};
int pin[] = {2,4,5,7,6,10,11,8};

void setup(){
  for(int x=0; x < 8; x++){
    pinMode(pin[x], OUTPUT); //pinMode(x, OUTPUT);
  }
}

void loop(){
  for (int t =0; t<8;t++){
    int i = digit[t]; // 0b0000 0100
    for (int x = 0; x < 8; x++){
      int k = i &0x01; // filter 
      digitalWrite(pin[x], k); // digitalWrite(x,k) x določa meseto k določa vrednost
      i = i >>1;
    }
    delay(500);
  }
}
```
![image](https://hackmd.io/_uploads/BJvagb54T.png)
### Vaja 11.1
```c=
int digit[8] = {0x01,0x02,0x04,0x08,0x010,0x20,0x40,0x80};
int pin[] = {2,4,5,7,6,10,11,8};

void setup(){
  for(int x=0; x < sizeof(pin); x++){
    pinMode(pin[x], OUTPUT); //pinMode(x, OUTPUT);
  }
}

void loop(){
  for (int t =0; t < 8; t++){
    int i = digit[t]; // 0b0000 0100
    izpis(i);
    delay(500);
  }
}
void izpis(int i){
  for (int x = 0; x < 8; x++){
      int k = i &0x01; // filter 
      digitalWrite(pin[x], k); 
      
      // digitalWrite(x,k) x določa meseto k določa vrednost
      i = i >>1;
    }
}
```
## Vaja 12
```c=
int digit[10] = {0x7E,0x30,0x6D,0x79,0x33,0x5B,0x5F,0x70,0x7F,0x7B};
int m = 0;

void setup() {
  DDRD =0xff;
  }


void loop() {
  int i = digit[m];
  PORTD = i;
  delay(500);
  m++;
  if(m>=10) m=0;
}
//num: a b c | d e f g
//0:   1 1 1 | 1 1 1 0 => 0x7E
//1:   0 1 1 | 0 0 0 0 => 0x30
//2:   1 1 0 | 1 1 0 1 => 0x6D
//3:   1 1 1 | 1 0 0 1 => 0x79
//4:   0 1 1 | 0 0 1 1 => 0x33
//5:   1 0 1 | 1 0 1 1 => 0x5B
//6:   1 0 1 | 1 1 1 1 => 0x5F
//7:   1 1 1 | 0 0 0 0 => 0x70
//8:   1 1 1 | 1 1 1 1 => 0x7F
//9:   1 1 1 | 1 0 1 1 => 0x7B

```
## Vaja 13
```c= 
char digit[] = {0x7E,0x30,0x6D,0x79,0x33,0x5B,0x5F};
int pin[7] = {2,3,4,5,6,7,8};
int m = 0;

void setup() {
  for(int x = 0; x < 7; x++) pinMode(pin[x], OUTPUT);
}

void loop() {
  
  int cifra = digit[m];

  for(int x= 0;x < 7; x++){
    int lstB = cifra & 0x01;
    digitalWrite(pin[x], lstB);
    cifra = cifra >> 1;
  }
  delay(500);
  m++;
  if (m>7)m =0;
}
```
![image](https://hackmd.io/_uploads/HkTYowEST.png)
## vaja 14
```c=
char digit[] ={0x7E,0x30,0x6D,0x79,0x33,0x5B,0x5F,0x70,0x7F,0x7B};
int pin1[] ={0, 1, 2, 3, 4, 5, 6};
int pin2[] ={7, 8, 9, 10, 11, 12, 13};
int m = 0;
int z = 0;
int y = 0;

void setup() {
  for(int x = 0; x < 14; x++) pinMode(x, OUTPUT);
}

void loop() {
  int disp1 = digit[z];
  int disp2 = digit[y];
 
  for (int x = 0; x < 7; x++){
    int temp1 = disp1 & 0x01;
    digitalWrite(pin1[x], temp1);
    disp1 >>=1;
  }
  for (int x = 0; x < 7; x++){
    int temp2 = disp2 & 0x01;
    digitalWrite(pin2[x], temp2);
    disp2 >>=1;
  }
  delay(270);
  z++;
  if (z >= 10){
    z = 0;
    y++;
  }
  if (y >= 10) y=0;
}

```
![image](https://hackmd.io/_uploads/rynLOONHp.png)

## vaja 15
```c=
char digit[] ={0x7E,0x30,0x6D,0x79,0x33,0x5B,0x5F,0x70,0x7F,0x7B};
int pin1[] ={0, 1, 2, 3, 4, 5, 6};
int pin2[] ={7, 8, 9, 10, 11, 12, 13};
int m = 0;
int count,count2;

void setup() {
  for(int x = 0; x < 14; x++) pinMode(x, OUTPUT);
}

void loop() {
  int disp1 = digit[count];
  izpis(disp1,1);
  int disp2 = digit[count2];
  izpis(disp2,2);
  count++;
  delay(300);
  if (count > 10){
    count = 0;
    count2++;
  }
if (count2 > 10) count2 =0;
}

void izpis(int disp, int m){
  for(int x =0; x<7;x++){
    int temp = disp & 0x01;
    if (m == 1) digitalWrite(pin1[x], temp);
    else digitalWrite(pin2[x], temp);
    disp >>= 1; 
  }
}
```
![image](https://hackmd.io/_uploads/r1qIduVHT.png)

## Vaja 16 - lcd
```c=
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
String primer = "Stevec: ";

void setup() {
  lcd.begin(16,2);// stolpci, vrstice
  lcd.setCursor(0,0); // prvi stolpec
  lcd.print(primer);

}

void loop() {
  lcd.setCursor(8,0);
  lcd.print(millis()/10);

}
![image](https://hackmd.io/_uploads/HyZ_pfSF6.png)
```
![image](https://hackmd.io/_uploads/BJzAiGHF6.png)
### vaja 16.1 - lcd 
```c= 
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
String primer = "Stevec: ";

void setup() {
  lcd.begin(16,2);// stolpci, vrstice
  lcd.setCursor(0,0); // prvi stolpec
  lcd.print(primer);

}

void loop() {
  lcd.clear();
  lcd.setCursor(0,0); 
  lcd.print(primer);
  int value = analogRead(A0);
  lcd.setCursor(8,0);
  lcd.print(value);
  delay(500);

}
```
![image](https://hackmd.io/_uploads/HyZ_pfSF6.png)
### vaja 16.2 - lcd
```c= 
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
String primer = "Stevec: ";

void setup() {
  lcd.begin(16,2);// stolpci, vrstice
}

void loop() {
  textPrint("Besedilo"); // klic za izpis besedila
  stPrint(5); // klic za izpis stevila
}
// funkcija za izpis besedila
void textPrint(String text){//{(char text[]) or (char*text)} 
  lcd.setCursor(0,0);
  lcd.print(text);
}
// funkcija za izpis stevila
void stPrint(int stevilo){
  lcd.setCursor(0,1);
  lcd.print(stevilo);
}
```
![image](https://hackmd.io/_uploads/B15KVXBtT.png)


### vaja 16.4 - lcd
```c=
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
String primer = "Stevec: ";
byte hertz[8] ={
  0b00000,
  0b01010,
  0b11111,
  0b11111,
  0b11111,
  0b01110,
  0b00100,
  0b00000,
};

void setup() {
  lcd.begin(16,2);// stolpci, vrstice
  lcd.createChar(1,hertz);
  lcd.createChar(2,nohertz);
}

void loop() {
  lcd.setCursor(0,0);
  lcd.write(1);
  lcd.setCursor(0,1);
  lcd.write(2);
}

```
![image](https://hackmd.io/_uploads/r1zSv7rFa.png)
### vaja 16.5 - lcd
```c= 
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
String primer = "Stevec: ";
char cr_names[3][12] = {
  "Janez",
  "Franci",
  "Fitzgerald",
};
void setup() {
  lcd.begin(16,2);
}

void loop() {
  for(int x = 0; x < 3; x++){
    char*m = cr_names[x]; // or Srting m = cr_names;
    textPrint(m,x);
    delay(500);
    lcd.clear();
  }
}

void textPrint(char*text, int x){
  lcd.setCursor(0,0);
  lcd.print(text);
  lcd.setCursor(0,1);
  lcd.print(x);
}
```
### Vaja 16.6 -lcd
```c=
#include <LiquidCrystal.h>
#include "RTClib.h"

LiquidCrystal lcd(12,11,10,9,8,7);
RTC_DS1307 rtc;
#define buttonSec A2
#define buttonMin A1
#define buttonHour A0

int mSec,mMin,mHour;


void setup() {
  lcd.begin(16,2);
  rtc.begin();
  lcd.print("Peter");
  pinMode(buttonSec, INPUT_PULLUP);
  pinMode(buttonMin, INPUT_PULLUP);
  pinMode(buttonHour, INPUT_PULLUP);
}

void loop() {
  if(digitalRead(buttonHour) == LOW){
    mHour++;
    if (mHour >=24) mHour=0;
  }
  if(digitalRead(buttonMin) == LOW){
    mMin++;
    if (mMin >=60) mMin=0;
  }
  if(digitalRead(buttonSec) == LOW){
    mSec++;
    if (mSec >=60) mSec=0;
  }
  textPrint(mHour, mMin,mSec);
  delay(300);
}
void textPrint(int h,int m,int s){
  lcd.clear();
  char str[8];
  sprintf(str, " %02d:%02d:%02d",h,m,s);
  lcd.setCursor(7,1);
  lcd.print(str);
  time();
}
void time(){
  DateTime now = rtc.now(); //trenutni čas OS-a
  int hour = now.hour();
  int minute = now.minute();
  int second = now.second();
  char Print[14];
  sprintf(Print, " %02d:%02d:%02d",hour,minute,second);
  lcd.setCursor(7,0);
  lcd.print(Print);
}
```
![image](https://hackmd.io/_uploads/SJNtl1-qT.png)
### Vaja 16.7 - lcd
```c=
#include <LiquidCrystal.h>
#include "RTClib.h"

LiquidCrystal lcd(12,11,10,9,8,7);
RTC_DS1307 rtc;
#define buttonSEC A0
#define buttonMIN A1
#define buttonHOUR A2
#define _delaySEC 15

int mSEC, mMIN, mHOUR;
int tipka; // katera tipka je pritisnjena
char ch_imena[4][10] ={
  " ",
  "HOUR",
  "MIN",
  "SEC"
};

void setup() {
  lcd.begin(16,2);
  rtc.begin();
  lcd.print("TEST");
  pinMode(buttonSEC, INPUT_PULLUP);
  pinMode(buttonMIN, INPUT_PULLUP);
  pinMode(buttonHOUR, INPUT_PULLUP);
}

void loop() {
  // put your main code here, to run repeatedly:
  tipka = 0;
  if (digitalRead(buttonHOUR) == LOW){
    mHOUR++;
    if (mHOUR >= 24) mHOUR = 0;
    tipka = 1;
    delay(50);
  }
  if (digitalRead(buttonMIN) == LOW){
    mMIN++;
    if (mMIN >= 60) mMIN = 0;
    tipka = 2;
    delay(50);
  }
  if (digitalRead(buttonSEC) == LOW){
    mSEC++;
    if (mSEC >= 60) mSEC = 0;
    tipka = 3;
    delay(50);

  }
  char * tipkaP = ch_imena[tipka];
  textPrint(mHOUR, mMIN, mSEC, tipkaP); //klic funkcije za izpis
  delay(300);
}

void textPrint(int h, int m, int s, char *tipka_mhs){
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(tipka_mhs);
  char str[8];
  sprintf(str, " %02d:%02d:%02d ", h, m, s);
  lcd.setCursor(7,1);
  lcd.print(str);
  ura(); // klic funkcije za prikaz časa 
}

void ura(){
  DateTime now = rtc.now(); // trenutni čas je čas OS
  int hour = now.hour();
  int minute = now.minute();
  int second = now.second();
  char izpis[14];
  sprintf(izpis, " %02d:%02d:%02d ", hour, minute, second);
  lcd.setCursor(7,0);
  lcd.print(izpis);
  // alarm
  static bool alarm;
  if (second == mSEC && minute == mMIN && hour == mHOUR){
    alarm = HIGH;
  }
  if (alarm && (second - mSEC > _delaySEC)) alarm = LOW;
  digitalWrite(13, alarm);
}
```
![image](https://hackmd.io/_uploads/HJJ_5k-5T.png)

![image](https://hackmd.io/_uploads/ryZXFmSFp.png)

## Bounce
### bounce 1 - brez bounca z milis
```c=
#define button 4
boolean lastState = HIGH;
int counter;
unsigned long lastbounce = 0;
int delaybounce = 300;


void setup() {
  Serial.begin(115200);
  pinMode(button, INPUT_PULLUP);
}

void loop(){
  int state = digitalRead(button);
  if(state != lastState && (millis() - lastbounce) > delaybounce){
    lastbounce = millis();
    lastState = state;
    if(lastState == HIGH){
      counter++;
      Serial.println(counter);
    }
  }
}
```
![image](https://hackmd.io/_uploads/BkFvNW9sT.png)
### Interupt
#### Interupt No1
```c=
// tipka kot zunanji interupt
#define ledpin 8
#define button 2

volatile bool state = LOW;

void setup(){
  pinMode(ledpin, OUTPUT);
  pinMode(button, INPUT_PULLUP);
  //napovem funkcijo zunanjega interupta
  attachInterrupt(digitalPinToInterrupt(button),ISR_interupt, FALLING);
}

void loop(){
  digitalWrite(ledpin, state);
}

void ISR_interupt(){
  state = !state;
}
```
### Interupt No2
```c=
// tipka kot zunanji interupt; brez bounca feat. milis
#define ledpin 8
#define button 2

volatile bool state = LOW;
volatile unsigned long lastbounce = 0;
int bouncedelay = 300;
int counter;

void setup(){
  pinMode(ledpin, OUTPUT);
  pinMode(button, INPUT_PULLUP);
  //napovem funkcijo zunanjega interupta
  attachInterrupt(digitalPinToInterrupt(button),ISR_interupt, FALLING);
}

void loop(){
  digitalWrite(ledpin, state);
}

void ISR_interupt(){
  if((millis() - lastbounce) > bouncedelay){
    state = !state;
    lastbounce = millis();
    counter++;
    Serial.println(counter);
  }
}

```
![image](https://hackmd.io/_uploads/SyMF2W9op.png)

## Bounce2
### Bounce2 No1
```c=
// Knjižnica bounce.2
#define btnGreen 3
#define btnBlue 4

#include <Bounce2.h>
Bounce2::Button btn1, btn2
 = Bounce2::Button();
int counter;


void setup(){
  btn1.attach(btnGreen, INPUT_PULLUP);
  btn2.attach(btnBlue, INPUT_PULLUP);
  btn1.interval(10);
  btn2.interval(10);
  btn1.setPressedState(LOW);
  btn2.setPressedState(LOW);
  Serial.begin(115200);
}

void loop(){
  btn1.update();
  btn2.update();

  if(btn1.pressed()){
    counter++;
    Serial.println(counter);
  }  
  if(btn2.pressed()){
    counter--;
    Serial.println(counter);
  }
}

```
![image](https://hackmd.io/_uploads/B1jsMz5iT.png)

## Serijske funkcije
### no1 - case switch
```c=
int led = 11;

void setup() {
  Serial.begin(9600);
  pinMode(led,OUTPUT);
  Serial.println("Vpisi znak: ");  
}

void loop() {
  if(Serial.available()){
    char znak = Serial.read();
    switch(znak){
      case '1':
        Serial.println("ena");
        utripanje();
        break;
      case '2':
        Serial.println("dva");
        utripanje();
        utripanje();
        break;
      case '+':
        Serial.println("vklop");
        digitalWrite(led, HIGH);
        break;
      case '-':
        Serial.println("izklop");
        digitalWrite(led, LOW);
        break;
      default :
      if(znak == 10) break;
        Serial.println("Ni pravi znak");
        break;
    }
  }
}

void utripanje(){
  digitalWrite(led, HIGH);
  delay(300);
  digitalWrite(led, LOW);
  delay(300);
}
```
### no2 - delay 
```c=
int led = 11;
int vrednost;
int utrip;

void setup() {
  Serial.begin(9600);
  Serial.println("Vpiši število: ");
  pinMode(led, OUTPUT);
}

void loop() {
  if(Serial.available()){
    char z = Serial.read();
    if(z >= '0' && z <='9'){
      vrednost = (vrednost*10) +(z-'0');
    }
    else if(z == 10){
      utrip = vrednost;
      Serial.println(utrip);
      vrednost = 0;
    }
  }
  utrpanje(utrip);
}

void utrpanje(int x){
  digitalWrite(led, HIGH);
  delay(x);
  digitalWrite(led, LOW);
  delay(x);
}
```
### no3
```c=
int led = 11;
int utrip;
char sez[6];
int index = 0;
void setup() {
  Serial.begin(9600);
  Serial.println("Vpiši niz stevk");
  pinMode(led, OUTPUT);
 
}

void loop() {
  if(Serial.available()){
    char z = Serial.read();
    if(z >= '0' && z <= '9' && index < 5){
      sez[index++] = z;
    }
    else{
      sez[index] = 0;
      utrip = atoi(sez);
      Serial.println(utrip);// pretvorba v int 
      index = 0;
    }
  }
  utripanje(utrip);
}

void utripanje(int x){
  digitalWrite(led, HIGH);
  delay(x);
  digitalWrite(led, LOW);
  delay(x);
}
```
### no4
```c=
#define led 11
int index = 0;
char sez[6];
int utrip;

void setup() {
  pinMode(led, OUTPUT);
  Serial.begin(9600);
  Serial.println("Vpisi niz stevk: ");
}

void loop() {
  if(Serial.available()){
    char znak = Serial.read();
    if(znak >='0' && znak <='9' && index <5){
      sez[index++] = znak;
    }

    else{
      sez[index] = 0;
      utrip = atoi(sez);
      index = 0;
      Serial.println(utrip);
    }
  }
  utripanje(utrip);
}

void utripanje(int n){
  digitalWrite(led, HIGH);
  delay(n);
  digitalWrite(led, LOW);
  delay(n);
}
```
### no5
```c=
#define sezst 3
int index = 0;// index posameznega števila
int st[sezst];
int m; // marker napake

void setup() {
  Serial.begin(9600);
  Serial.println("Vpisi tri stevila locena z vejico: ");

}

void loop() {
  if(Serial.available()){
    char z = Serial.read();
    if(z >= "0" && z <='9'){
      st[index] = (st[index] *10) + (z -'0');
    }
    else if( z == ","){
      if(index > sezst){
        index++;
      }
      m++;
    }
    else{
      Serial.println("Seznam stevil");
      if(m >= 3 ){
        m =0;
        Serial.println("preveliko stevilo");
        for(int i = 0; i<= index;i++){
          st[i] =0;
        }
      }
    }
    for(int i = 0; i <= index;i=0){
      Serial.println(st[i]);
      st[i] = 0;
    }
    index = 0;
  }
}
```

### no6
```c=
#define sez 3
int st[sez];
int index = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("Vpisi tri stevila, locena z vejico: ");

}

void loop() {
  if(Serial.available()){
    char z = Serial.read();
    if (z >='0' && z <='9'){
      st[index] = (st[index]*10) + (z-'0');
    }
    else if(z ==','){
      if (index < sez) index++;
    }
    else if (z == 10){
      for (int i = 0; i < sez;i++) {
        Serial.print(st[i]);
        if(i< sez-1) Serial.print(",");
        else Serial.println();
        
        }
      for (int i = 0; i<sez;i++) st[i] = 0;
      index = 0;
      Serial.print("Vpisi tri stevila, locena z vejico: ");
    }
  }
}

```
### no7
```c=

#define BUFFER_SIZE 50
char buffer[BUFFER_SIZE];
long sezST[BUFFER_SIZE];
int index = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("Vpisi niz znakov ločenih z vejico: ");  
}

void loop() {
  if(Serial.available()){
    memset(buffer,0,sizeof(buffer));
    Serial.readBytesUntil('\n',buffer,BUFFER_SIZE);
    char *token = strtok(buffer,",");
    while(token != NULL){
      sezST[index] = atol(token);
      token = strtok(NULL,",");
      index++;
    }
    
    long min_st = sezST[0];
    long max_st = sezST[0];
    Serial.println("Seznam shranjenih stevilk: ");
    for(int x = 0; x < index;x++){
      Serial.print(sezST[x]);
      Serial.print(",");
      if(sezST[x] > max_st) max_st = sezST[x];
      if(sezST[x] < min_st) min_st = sezST[x];
    }
    Serial.println();
    Serial.print("Največja številka: ");
    Serial.print(max_st);
    Serial.println();
    Serial.print("Najmanša stevilka: ");
    Serial.print(min_st);
    memset(sezST,0,sizeof(sezST));
    index=0;
  }

}

```
### no8
```c=
#define led 8
#define code 5461

void setup() {
  Serial.begin(9600);
  Serial.println("Vpisi kodo");
  pinMode(led, OUTPUT);

}

void loop() {
  if(Serial.available()){
    char vpis[5];
    int st = Serial.readBytes(vpis,4);
    if(st == 4){
      vpis[4] = '\0';
      int stevilka = aoti(vpis);
      if(stevilka == code){
        Serial.println("dostop je");
        digitalWrite(led, HIGH);
      }
      else {
        Serial.println("Poskusi ponovno!");
        while(Serial.available() > 0){
          Serial.read();
        }
      }
    }
  }

}
```
### no9
```c=
#include <LiquidCrystal.h>

void setup() {
  Serial.begin(9600);
  Serial.println("Vpisi kodo: ");
  for(int x = 8; x < 11;x++) pinMode(x, OUTPUT);

}

void loop() {
  if(Serial.available()){
    static bool utrip3 = false;
    char vpis[5];
    int steviloZnakov = Serial.readBytes(vpis,4);
    if(steviloZnakov == 4){
      vpis[4] = '\0';
      int st = atoi(vpis);
      switch(st){
        case 5641:
          Serial.println("vklop");
          digitalWrite(8, HIGH);
          break;
        case 5640:
          Serial.println("Led1 izklop");
          digitalWrite(8,LOW);
          break;
        case 1234:
          Serial.println("Led2 izklop");
          digitalWrite(9, HIGH);
          break;
        case 1230:
          Serial.println("Led2 izklop");
          digitalWrite(9, LOW);
          break;
        case 4545:
          Serial.println("led3 utripanje vklop");
          utrip3 = true;
          break;
        case 4540:
          Serial.println("led3 utripanje izklop");
          digitalWrite(10, LOW);
          break;
        default:
          Serial.println("poskusi ponovno");
          while(Serial.available()) Serial.read();
          break;
      }
    }
  }
}

static unsigned long cagr = 0;
static bool m = false;
int zakasnitev = 300;
if(((millis() + cagr) > zakasnitev) && utrip3){
  m = !m;
  cagr = millis();

}
```