diff --git a/cetvrto_predavanje/fotosenzor/fotosenzor.ino b/cetvrto_predavanje/fotosenzor/fotosenzor.ino new file mode 100644 index 0000000..adb851e --- /dev/null +++ b/cetvrto_predavanje/fotosenzor/fotosenzor.ino @@ -0,0 +1,14 @@ +const int fotootpornik = A0; // Fotootpornik povezan na analogni pin A0 +int value; // Prati vrednost napona na otporniku + +void setup() +{ + Serial.begin(9600); // Inicijalizuje komunikaciju sa računarom pri brzini od 9600 bit/s +} + +void loop() +{ + value = analogRead(fotootpornik); // Čita vrednost na otporniku + Serial.println(value); // Štampa tu vrednost na serijski monitor + delay(50); // Pauza +} diff --git a/cetvrto_predavanje/fotosenzor/scheme.png b/cetvrto_predavanje/fotosenzor/scheme.png new file mode 100644 index 0000000..a715e93 Binary files /dev/null and b/cetvrto_predavanje/fotosenzor/scheme.png differ diff --git a/cetvrto_predavanje/fotosenzor/sketch.yaml b/cetvrto_predavanje/fotosenzor/sketch.yaml new file mode 100644 index 0000000..5ab1bb8 --- /dev/null +++ b/cetvrto_predavanje/fotosenzor/sketch.yaml @@ -0,0 +1,2 @@ +default_port: /dev/ttyUSB0 +default_fqbn: arduino:avr:uno diff --git a/cetvrto_predavanje/fotosenzor_led/fotosenzor_led.ino b/cetvrto_predavanje/fotosenzor_led/fotosenzor_led.ino new file mode 100644 index 0000000..0872ad9 --- /dev/null +++ b/cetvrto_predavanje/fotosenzor_led/fotosenzor_led.ino @@ -0,0 +1,22 @@ +const int fotootpornik = A0; // Fotootpornik je povezan na analogni pin A0 +const int led = 13; // Dioda povezana na pin 13 +int value; // Prati napon na fotootporniku + +void setup() +{ + pinMode(led, OUTPUT); // Inicijalizuje pin 13 kao izlaz + digitalWrite(led, LOW); // Postavlja diodu kao isključenu (za svaki slučaj) + Serial.begin(9600); // Inicijalizuje komunikaciju sa računarom pri brzini od 9600 bit/s +} + +void loop() +{ + value = analogRead(fotootpornik); // Čita napon na otporniku + Serial.println(value); // Štampa vrednost na serijski monitor + if (value < 200) // Ako je vrednost manja od 200 uključi led + digitalWrite(led, HIGH); + else // Ako nije, isključi led + digitalWrite(led, LOW); + delay(50); // Pauza između očitavanja +} + diff --git a/cetvrto_predavanje/fotosenzor_led/scheme.png b/cetvrto_predavanje/fotosenzor_led/scheme.png new file mode 100644 index 0000000..382958c Binary files /dev/null and b/cetvrto_predavanje/fotosenzor_led/scheme.png differ diff --git a/cetvrto_predavanje/fotosenzor_led/sketch.yaml b/cetvrto_predavanje/fotosenzor_led/sketch.yaml new file mode 100644 index 0000000..5ab1bb8 --- /dev/null +++ b/cetvrto_predavanje/fotosenzor_led/sketch.yaml @@ -0,0 +1,2 @@ +default_port: /dev/ttyUSB0 +default_fqbn: arduino:avr:uno diff --git a/cetvrto_predavanje/temperatura_ds18b20/sketch.yaml b/cetvrto_predavanje/temperatura_ds18b20/sketch.yaml new file mode 100644 index 0000000..5ab1bb8 --- /dev/null +++ b/cetvrto_predavanje/temperatura_ds18b20/sketch.yaml @@ -0,0 +1,2 @@ +default_port: /dev/ttyUSB0 +default_fqbn: arduino:avr:uno diff --git a/cetvrto_predavanje/temperatura_ds18b20/temperatura_ds18b20.ino b/cetvrto_predavanje/temperatura_ds18b20/temperatura_ds18b20.ino new file mode 100644 index 0000000..8dec237 --- /dev/null +++ b/cetvrto_predavanje/temperatura_ds18b20/temperatura_ds18b20.ino @@ -0,0 +1,31 @@ +//https://randomnerdtutorials.com/guide-for-ds18b20-temperature-sensor-with-arduino/ + +#include +#include + +// Data wire is conntec to the Arduino digital pin 4 +#define ONE_WIRE_BUS 4 + +// Setup a oneWire instance to communicate with any OneWire devices +OneWire oneWire(ONE_WIRE_BUS); + +// Pass our oneWire reference to Dallas Temperature sensor +DallasTemperature sensors(&oneWire); + +void setup(void) +{ + // Start serial communication for debugging purposes + Serial.begin(9600); + // Start up the library + sensors.begin(); +} + +void loop(void){ + // Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus + sensors.requestTemperatures(); + + Serial.print("Celsius temperature: "); + // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire + Serial.println(sensors.getTempCByIndex(0)); + delay(1000); +} diff --git a/cetvrto_predavanje/temperatura_lm335a/LM135.pdf b/cetvrto_predavanje/temperatura_lm335a/LM135.pdf new file mode 100644 index 0000000..ca3121e Binary files /dev/null and b/cetvrto_predavanje/temperatura_lm335a/LM135.pdf differ diff --git a/cetvrto_predavanje/temperatura_lm335a/sketch.yaml b/cetvrto_predavanje/temperatura_lm335a/sketch.yaml new file mode 100644 index 0000000..5ab1bb8 --- /dev/null +++ b/cetvrto_predavanje/temperatura_lm335a/sketch.yaml @@ -0,0 +1,2 @@ +default_port: /dev/ttyUSB0 +default_fqbn: arduino:avr:uno diff --git a/cetvrto_predavanje/temperatura_lm335a/temperatura_lm335a.ino b/cetvrto_predavanje/temperatura_lm335a/temperatura_lm335a.ino new file mode 100644 index 0000000..d7b26a8 --- /dev/null +++ b/cetvrto_predavanje/temperatura_lm335a/temperatura_lm335a.ino @@ -0,0 +1,21 @@ +const int temp_sensor = A0; // Senzor je povezan na A0 + +float sensor_value; +float voltage; +float temperaturaK = 0; +float temperatura = 0; + +void setup() +{ + Serial.begin(9600); +} + +void loop() +{ + sensor_value = analogRead(temp_sensor); // Očitana vrednost sa ADC-a + voltage = sensor_value * 5000 / 1024; // Napon u milivoltima + temperaturaK = voltage / 10; // Temperatura u kelvinima + temperatura = temperaturaK - 273.16; // Temperatura u celzijusima + Serial.println(temperatura); + delay(100); +} diff --git a/trece_predavanje/rgb_led/aleksejevo_resenje.ino b/trece_predavanje/rgb_led/aleksejevo_resenje.ino new file mode 100644 index 0000000..d9ac330 --- /dev/null +++ b/trece_predavanje/rgb_led/aleksejevo_resenje.ino @@ -0,0 +1,57 @@ +int led_r = 9; +int led_g = 10; +int led_b = 11; + +int button = 7; +int ptm = A0; + +int color; +int value; + +bool pressed; + +void setup() { +pinMode(led_r, OUTPUT); +pinMode(led_g, OUTPUT); +pinMode(led_b, OUTPUT); + +pinMode(button, INPUT); +pinMode(ptm, INPUT); + +analogWrite(led_r, 0); +analogWrite(led_g, 0); +analogWrite(led_b, 0); + +color = 0; +pressed = false; + +Serial.begin(9600); +} + +void loop() { +if (digitalRead(button) == HIGH){ +if (pressed == false){ +color = (color + 1) % 3; +pressed = true; +} +} +if (digitalRead(button) == LOW){ +pressed = false; +} +value = analogRead(ptm); +if (value < 20) value = 0; +value = map(value, 0, 1023, 0, 255); +delay(1); + +if(color == 0){ +analogWrite(led_r, value); +} +if(color == 1){ +analogWrite(led_g, value); +} +if(color == 2){ +analogWrite(led_b, value); +} +Serial.println(value); +delay(100); +} diff --git a/trece_predavanje/rgb_led/rgb_led.ino b/trece_predavanje/rgb_led/rgb_led.ino new file mode 100644 index 0000000..478316d --- /dev/null +++ b/trece_predavanje/rgb_led/rgb_led.ino @@ -0,0 +1,54 @@ +const int led_r = 9; +const int led_g = 10; +const int led_b = 11; +const int touch_senzor = 12; +const int taster = 13; +const int pot = A0; + +float pot_value; + +/* +MOJA LED JE COMMON ANODE, TAKO DA SU VREDNOSTI ZA UPIS INVERTOVANE +AKO TREBA DA SVETLI CRVENA NA TOM PINU ĆE BITI NULA, A NA OSTALA DVA +ĆE BITI 255 (5 V) +*/ +void setup() +{ + pinMode(led_r, OUTPUT); + pinMode(led_g, OUTPUT); + pinMode(led_b, OUTPUT); + pinMode(touch_senzor, INPUT); + pinMode(taster, INPUT); + + analogWrite(led_r, 255); + analogWrite(led_g, 255); + analogWrite(led_b, 255); +} + +void loop() +{ + if (digitalRead(touch_senzor) == HIGH){ + while (digitalRead(taster) != HIGH){ + // Ljubičasta + pot_value = analogRead(pot); + setColor(map(pot_value, 0, 1023, 255, 0), 255, map(pot_value, 0, 1023, 255, 0)); + } + } + if (digitalRead(taster) == HIGH){ + while (digitalRead(touch_senzor) != HIGH){ + // Žuta + pot_value = analogRead(pot); + setColor(255 - 255*pot_value/1023, 255 - 255*pot_value/1023, 255); + //setColor(map(pot_value, 0, 1023, 255, 0), map(pot_value, 0, 1023, 255, 0), 255); + } + } + delay(1); +} + + +void setColor(int red_value, int green_value, int blue_value) +{ + analogWrite(led_r, red_value); + analogWrite(led_g, green_value); + analogWrite(led_b, blue_value); +} diff --git a/trece_predavanje/rgb_led/sketch.yaml b/trece_predavanje/rgb_led/sketch.yaml new file mode 100644 index 0000000..5ab1bb8 --- /dev/null +++ b/trece_predavanje/rgb_led/sketch.yaml @@ -0,0 +1,2 @@ +default_port: /dev/ttyUSB0 +default_fqbn: arduino:avr:uno