Compare commits

...

4 Commits

Author SHA1 Message Date
46a1b15c2c Dodao materijale iz tehnicke skole 2024-06-03 12:53:57 +02:00
44c02255b4 Dodajem treće i četvrto predavanje. 2024-04-10 09:13:23 +02:00
2e95796816 Sav materijal sa drugog predavanja. 2024-03-12 06:38:32 +01:00
580e2b315c Sklonio drugo predavanje na kratko. 2024-03-12 06:36:31 +01:00
57 changed files with 255 additions and 0 deletions

View File

@@ -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
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

View File

@@ -0,0 +1,2 @@
default_port: /dev/ttyUSB0
default_fqbn: arduino:avr:uno

View File

@@ -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
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

View File

@@ -0,0 +1,2 @@
default_port: /dev/ttyUSB0
default_fqbn: arduino:avr:uno

View File

@@ -0,0 +1,2 @@
default_port: /dev/ttyUSB0
default_fqbn: arduino:avr:uno

View File

@@ -0,0 +1,31 @@
//https://randomnerdtutorials.com/guide-for-ds18b20-temperature-sensor-with-arduino/
#include <OneWire.h>
#include <DallasTemperature.h>
// 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);
}

Binary file not shown.

View File

@@ -0,0 +1,2 @@
default_port: /dev/ttyUSB0
default_fqbn: arduino:avr:uno

View File

@@ -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);
}

View File

@@ -0,0 +1,26 @@
const int led_pin = 3; // Dioda je povezana na pin 3
int i = 0; // Brojač za PWM
int smer = 1; // Prati da li PWM raste ili opada
void setup()
{
pinMode(led_pin, OUTPUT); // Inicijalizuje pin 3 kao izlaz
}
void loop()
{
analogWrite(led_pin, i); // Izbacuje PWM signal na pinu
switch (i) {
case 0: // Ako je stiglo do nule, počinje da uvećava
smer = 1;
break;
case 255: // Ako je stiglo do maksimuma počinje da smanjuje
smer = -1;
break;
}
i = i + smer;
delay(5); // Pauza (koliko dugo svetli na jednoj vrednosti PWM)
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@@ -0,0 +1,2 @@
default_fqbn: arduino:avr:uno
default_port: /dev/ttyUSB0

View File

@@ -0,0 +1,16 @@
const int pot = A0; // Potenciometar je povezan na analogni pin A0
const int led_pin = 3; // Dioda je povezana na pin 3
int value; // Prati očitani napon
void setup()
{
pinMode(led_pin, OUTPUT); // Inicijalizuje pin 3 kao izlaz
}
void loop()
{
value = analogRead(pot); // Čita vrednost sa potenciometra
value = map(value, 0, 1024, 0, 255); // Prebacuje vrednost u rang 0-255
analogWrite(led_pin, value); // Izbacuje očitanu vrednost PWM-a na diodu
delay(1); // Pauza pre sledećeg čitanja
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

View File

@@ -0,0 +1,2 @@
default_port: /dev/ttyUSB0
default_fqbn: arduino:avr:uno

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -0,0 +1,2 @@
default_port: /dev/ttyUSB0
default_fqbn: arduino:avr:uno