//vaja 1
#define tipka 4
int stevec;
bool zadnjeStanje = HIGH;
void setup() {
Serial.begin(115200);
pinMode(tipka, INPUT_PULLUP);
}
void loop() {
int stanje = digitalRead(tipka);
if(zadnjeStanje != stanje){
stevec++;
zadnjeStanje = stanje;
Serial.println(stevec);
}
delay()(300);
}
// vaja 2
#define tipka 4
int stevec;
bool zadnjeStanje = HIGH;
unsigned long zadnjiOdboj = 0;
unsigned long zakasnitevOdboja = 300;
void setup() {
Serial.begin(115200);
pinMode(tipka, INPUT_PULLUP);
}
void loop() {
int stanje = digitalRead(tipka);
if(stanje != zadnjeStanje && (millis() - zadnjiOdboj) > zakasnitevOdboja){
zadnjiOdboj = millis();
zadnjeStanje = stanje;
if(zadnjeStanje == HIGH){
stevec++;
Serial.println(stevec);
}
}
}
// vaja 3 dela ?
int tipka = 2;
int ledPin = 8;
volatile byte stanje = LOW;
void setup(){
pinMode(ledPin, OUTPUT);
pinMode(tipka, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(tipka), ISR_tipka, CHANGE);
}
void loop(){
digitalWrite(ledPin,stanje);
delay(300);
}
void ISR_tipka(){
stanje = !stanje;
}
// VAJA 4
#define intPin 2
int stevec;
volatile bool m;
unsigned long time;
int timedelay = 500;
void setup(){
pinMode(intPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(intPin), IS, RISING);
Serial.begin(115200);
}
void loop(){
if (m == HIGH && ((millis() - time) > timedelay)){
m = LOW;
stevec++;
time = millis();
Serial.println(stevec);
}
}
void IS(){
m = HIGH;
}
// vaja 5 ne dela luč pravilno
#include <LiquidCrystal.h>
#include <Bounce2.h>
#define btnRed 7
#define btnGreen 6
#define btnBlu 5
#define interruptPin 2
#define ledPin 3
int stevec;
int lastTime;
int delayTime = 150;
volatile bool state = LOW;
bool prevstate = state;
Bounce2::Button tipka1, tipka2, tipka3 = Bounce2::Button();
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
void setup() {
pinMode(btnRed, INPUT_PULLUP);
pinMode(btnGreen, INPUT_PULLUP);
pinMode(btnBlu, INPUT_PULLUP);
tipka1.attach(btnRed, INPUT_PULLUP);
tipka1.interval(10);
tipka2.attach(btnGreen, INPUT_PULLUP);
tipka2.interval(10);
tipka3.attach(btnBlu, INPUT_PULLUP);
tipka3.interval(10);
Serial.begin(115200);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), ISR_button, CHANGE);
}
void loop() {
if ((millis() - lastTime) > delayTime) {
tipka1.update();
tipka2.update();
tipka3.update();
lcd.setCursor(0, 0);
lcd.print(stevec);
if (tipka1.pressed()) {
stevec++;
lcd.clear();
lcd.print(stevec);
lastTime = millis();
}
if (tipka2.pressed()) {
stevec--;
lcd.clear();
lcd.print(stevec);
lastTime = millis();
}
if (tipka3.pressed()) {
stevec = 0;
lcd.clear();
lcd.print(stevec);
lastTime = millis();
}
digitalWrite(ledPin, state);
if (state != prevstate) {
prevstate = state;
lastTime = millis();
}
}
}
void ISR_button() {
state = !state;
}