This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:arduino [2015/12/10 12:46] – kaupo.raid | en:arduino [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 12: | Line 12: | ||
| */ | */ | ||
| - | ====== Näide 1 Digital I/O ====== | ||
| - | ===== Näide | + | ====== References ====== |
| + | |||
| + | [[http:// | ||
| + | [[http:// | ||
| + | |||
| + | ====== Example 1 Digital I/O ====== | ||
| + | |||
| + | ===== Example | ||
| <code c> | <code c> | ||
| - | /* | + | |
| - | Nimetus: Näide #1.1 Digitaalsed sisend-väljundid | + | |
| - | Kirjeldus: Programm demonstreerib nupu ja LED-i kasutamist | + | |
| - | Autor: Raivo Sell | + | |
| - | Kuupäev: 15.01.2013 | + | |
| - | */ | + | |
| // Constants | // Constants | ||
| const int nupp = A0; // Viik kuhu on ühendatud nupp | const int nupp = A0; // Viik kuhu on ühendatud nupp | ||
| Line 46: | Line 47: | ||
| </ | </ | ||
| - | ===== Näide | + | ===== Example |
| <code c> | <code c> | ||
| // First part of code copy from example #1.1 | // First part of code copy from example #1.1 | ||
| Line 58: | Line 59: | ||
| </ | </ | ||
| - | ===== Näide | + | ===== Example |
| <code c> | <code c> | ||
| // First part of code copy from example #1.1 | // First part of code copy from example #1.1 | ||
| Line 79: | Line 80: | ||
| 0 %).*/ | 0 %).*/ | ||
| - | ====== | + | ====== |
| - | ===== Näide | + | ===== Example |
| <code c> | <code c> | ||
| - | /* | ||
| - | Nimetus: Näide #2.1 Analoog inputs | ||
| - | Kirjeldus: Programm demonstreerib analoogsisendi kasutamist | ||
| - | Autor: Raivo Sell | ||
| - | */ | ||
| // Set threshold value at which the LED turns on | // Set threshold value at which the LED turns on | ||
| const int nivoo = 512; | const int nivoo = 512; | ||
| - | int pote_sisend = A1; // set potentiometer input pin | + | int pote_sisend = A0; // set potentiometer input pin |
| - | int led = A5; // set LED pin | + | int led = 13; // set LED pin |
| int pote = 0; // integer variable to hold potentiometer value | int pote = 0; // integer variable to hold potentiometer value | ||
| Line 110: | Line 106: | ||
| </ | </ | ||
| - | ===== Näide | + | ===== Example |
| <code c> | <code c> | ||
| - | /* | ||
| - | Nimetus: Näide #2.2 Analoog sisendi teisendamine ajaks | ||
| - | Kirjeldus: Programm demonstreerib analoogsisendi kasutamist | ||
| - | Autor: David Cuartielles | ||
| - | Täiendused: | ||
| - | Kohandused: Raivo Sell | ||
| - | OriginaalURL: | ||
| - | */ | ||
| - | int pote_sisend = A1; // set potentiometer pin | + | int pote_sisend = A0; // set potentiometer pin |
| - | int led = A5; // set LED pin | + | int led = 13; // set LED pin |
| int pote = 0; // integer variable to hold potentiometer value | int pote = 0; // integer variable to hold potentiometer value | ||
| Line 139: | Line 127: | ||
| </ | </ | ||
| - | ===== Harjutus | + | ===== Task #2 ===== |
| Modify example program so that its possible to change LED brifgtness with potentiometer. Use delay functions. | Modify example program so that its possible to change LED brifgtness with potentiometer. Use delay functions. | ||
| / | / | ||
| - | ====== | + | ====== |
| - | ===== Näide | + | Connect LCD shield to Arduino board. Before attaching remove all connections from the board. |
| + | |||
| + | ===== Example | ||
| <code c> | <code c> | ||
| - | /* | ||
| - | Nimetus: Näide #3.1 LCD kasutamine | ||
| - | Kirjeldus: | ||
| - | Autor: Tom Igoe | ||
| - | Modifikatsioon: | ||
| - | Kuupäev: 4.06.2014 | ||
| - | Versioon: 1.0 | ||
| - | */ | ||
| #include < | #include < | ||
| Line 178: | Line 160: | ||
| </ | </ | ||
| - | ===== Näide | + | ===== Example |
| <code c> | <code c> | ||
| - | /* | ||
| - | Nimetus: Näide #3.2 LCD kasutamine analoogsisendiga | ||
| - | Kirjeldus: | ||
| - | Kasutab LiquidCrystal.h teeki ja ITEAD Studio 2x16 teksti laiendusplaati | ||
| - | Autor: Tom Igoe | ||
| - | Modifikatsioon: | ||
| - | Kuupäev: 4.06.2014 | ||
| - | Versioon: 1.0 | ||
| - | */ | ||
| #include < | #include < | ||
| Line 213: | Line 186: | ||
| </ | </ | ||
| - | ===== Harjutus | + | ===== Task #3.1 ===== |
| Make a program that on button press changes LCD row. Potentiometer value has to be printed only on the new row. | Make a program that on button press changes LCD row. Potentiometer value has to be printed only on the new row. | ||
| Line 220: | Line 193: | ||
| - | ====== | + | ====== |
| - | ===== Näide | + | ===== Example |
| Line 247: | Line 220: | ||
| // Initsialiseerime LCD koos vastavate viikude ühendamisega | // Initsialiseerime LCD koos vastavate viikude ühendamisega | ||
| LiquidCrystal lcd(8, 9, 4, 5, 6, 7); | LiquidCrystal lcd(8, 9, 4, 5, 6, 7); | ||
| - | int andur = A4; // määrame potentsiomeetri sisendviigu | + | int andur = A1; // set thermistor input pin |
| void setup() { | void setup() { | ||
| Line 306: | Line 279: | ||
| void loop() | void loop() | ||
| { | { | ||
| - | // Read the input on analog pin 0 and digital pin 10: | + | // Read the input on analog pin 2 and 3 |
| - | int AnalogSensorValue = analogRead(A0); | + | int AnalogSensorValue = analogRead(A2); |
| - | int DigitalSensorValue = digitalRead(10); | + | int DigitalSensorValue = digitalRead(A3); |
| | | ||
| Serial.println(AnalogSensorValue); | Serial.println(AnalogSensorValue); | ||
| Line 320: | Line 293: | ||
| ===== Harjutus #4.1 ===== | ===== Harjutus #4.1 ===== | ||
| Modifitseerida programmi nii, et potentsiomeetriga määratakse temperatuuri nivoo, mis salvestatakse nupuga programmi mällu ja selle nivoo hilisemal ületamisel käivitatakse täiturmehhanism (milleks on LED). | Modifitseerida programmi nii, et potentsiomeetriga määratakse temperatuuri nivoo, mis salvestatakse nupuga programmi mällu ja selle nivoo hilisemal ületamisel käivitatakse täiturmehhanism (milleks on LED). | ||
| + | **Extra:** | ||
| + | Kombineerida LED-i heleduse programm ja eelnev temperatuuri juhtimise programm, kus LED-i heledus sõltub sellest, kui palju nivootemperatuuri ületati (1 kraad: heledus 25 %, 2 kraadi: heledus 50 %, 3 kraadi: heledus 75 % ja 5 kraadi: heledus 10 | ||
| ===== Harjutus #4.2 ===== | ===== Harjutus #4.2 ===== | ||
| - | Kombineerida LED-i heleduse programm ja eelnev temperatuuri juhtimise programm, kus LED-i heledus sõltub sellest, kui palju nivootemperatuuri ületati (1 kraad: heledus 25 %, 2 kraadi: heledus 50 %, 3 kraadi: heledus 75 % ja 5 kraadi: heledus 10 | + | Modify distance sensor example so that it would print values on the LCD in centimeters (+-5cm accuracy). If no measureing tool is available then use the sensor datasheet graph. |
| ====== Näide #5 Mootor ====== | ====== Näide #5 Mootor ====== | ||
| + | |||
| + | Disconnect the LCD shield before using motors. Before disconnecting remove all connections from shield and Arduino board. | ||
| ===== Näide #5.1 Servomootor ===== | ===== Näide #5.1 Servomootor ===== | ||
| Line 377: | Line 354: | ||
| ===== Harjutus #5.1 ===== | ===== Harjutus #5.1 ===== | ||
| - | Luua programm, mis võimaldab servomootori positsiooni muuta vastavalt | + | Luua programm, mis võimaldab servomootori positsiooni muuta vastavalt |
| ===== Harjutus #5.2 ===== | ===== Harjutus #5.2 ===== | ||
| - | Luua programm, mis servomootori baasil ehitatud radariga ja fotoanduriga | + | Luua programm, mis servomootori baasil ehitatud radariga ja analoog kaugusanduriga |
| ====== Näide 6 Kommunikatsioon ====== | ====== Näide 6 Kommunikatsioon ====== | ||