#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int p1 = 5, p2 = 2, p3 = 3, p4 = 4, b1 = 0;
int adv = 0, pp = A0, brnt = 0, br = 0;
void setup()
{
Serial.begin(9600);
lcd.init();
lcd.backlight();
pinMode(p1, OUTPUT);
pinMode(p2, OUTPUT);
pinMode(p3, OUTPUT);
pinMode(p4, INPUT_PULLUP);
pinMode(pp, INPUT);
}
void loop()
{
b1 = digitalRead(p4);
adv = analogRead(pp);
brnt = map(adv, 0,1023, 0,255);
Serial.print("Ocitana A/D vrijednost: ");
Serial.print(adv);
Serial.print("\tTrajanje intervala: ");
Serial.print(brnt);
Serial.print("ms\n");
if(b1 == 1){
digitalWrite(p1, HIGH);
br++;
delay(brnt);
digitalWrite(p2, HIGH);
br++;
digitalWrite(p1, LOW);
delay(brnt);
digitalWrite(p2, LOW);
digitalWrite(p3, HIGH);
br++;
delay(brnt);
digitalWrite(p3, LOW);
}
else {
digitalWrite(p3, HIGH);
br++;
delay(brnt);
digitalWrite(p3, LOW);
digitalWrite(p2, HIGH);
br++;
delay(brnt);
digitalWrite(p2, LOW);
digitalWrite(p1, HIGH);
br++;
delay(brnt);
digitalWrite(p1, LOW);
}
lcd.clear();
lcd.print("Petrovicki");
lcd.setCursor(11,0);
lcd.print(brnt);
lcd.print("ms");
lcd.setCursor(0,1);
lcd.print("Br. palj.: ");
lcd.print(br);
}