User Tools

Site Tools


projektas_nr.4

Skirtumai

Čia matote skirtumus tarp pasirinktos versijos ir esamo dokumento.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
projektas_nr.4 [2015/10/25 19:34]
193.219.47.27
projektas_nr.4 [2015/12/15 00:37] (esamas)
simonas
Linija 2: Linija 2:
  
 **Ką darome:** **Ką darome:**
-Mes privertėme vieną LED mirksėti, dabar laikas padidinti riziką. Sujunkime 8. Taip pat turėsime galimybę išplėsti Arduino sukurdami įvairius šviesos tęsinius. Ši grandinė taip pat puikiai tinka išbandyti savo programas ir pajusti, kaip Arduino veikia. ​+Mes privertėme vieną LED'​ą ​mirksėti, dabar laikas padidinti riziką. Sujunkime 8. Taip pat turėsime galimybę išplėsti ​Arduino“ sukurdami įvairius šviesos tęsinius. Ši grandinė taip pat puikiai tinka išbandyti savo programas ir pajusti, kaip Arduino“ veikia. ​
  
-Taip pat prie LED kontroliavimo mes pradedame žiūrėti į kelis paprastus programavimo metodus, kad išlaikytume programas mažas.+Taip pat prie LED'​ų ​kontroliavimo mes pradedame žiūrėti į kelis paprastus programavimo metodus, kad išlaikytume programas mažas.
    
 for() loops – kai norima paleisti kodą kelis kartus. for() loops – kai norima paleisti kodą kelis kartus.
Linija 10: Linija 10:
  
 **Grandinės dalys:** **Grandinės dalys:**
-CIRC-02 Surinkimo lapas x1 +  *CIRC-02 Surinkimo lapas x1 
-2 kontaktų kištukas x4 +  *2 kontaktų kištukas x4 
-5mm žalias LED x8 +  *5mm žalias LED x8 
-Laidas x3 +  *Laidas x3 
-560 Ohm Resistorius (Žalias-mėlynas-rudas) x8+  *560 Ohm Resistorius (Žalias-mėlynas-rudas) x8
  
-**Grandinėschema:**+**Principinė schema** 
 + 
 +{{:ardu_pro4.jpg?​300|}} 
 + 
 +**Surinkimo šablonas** 
 + 
 +{{:​ardu_pro41.jpg?​300|}} 
 + 
 +**Surinkta grandinė** 
 + 
 +{{:​ardu_pro42.png?​600|}} 
 + 
 +**Šaltiniai** 
 + 
 +[[http://​ardx.org/​BBLS02|Surinkimo šablonas]] 
 +[[http://​ardx.org/​VIDE02|Surinkimo video]] 
 + 
 +**Kodas:** Kodą galima nukopijuoti į tuščią „Arduino“ sketch'​ą 
 + 
 +<​code>​ 
 + 
 +/*     ​--------------------------------------------------------- 
 + ​* ​    ​| ​ „Arduino“ Experimentation Kit Example Code             | 
 + ​* ​    ​| ​ CIRC-02 .: 8 LED Fun :. (Multiple LEDs)   | 
 + ​* ​    ​--------------------------------------------------------- 
 + ​* ​  
 + ​* ​ Keletas paprastų LED'ų animacijų 
 + * 
 + * Daugiau apie šią grandinę žiūrėkite http://​tinyurl.com/​d2hrud 
 + * 
 + */ 
 +  
 +//LED Pin Variables 
 +int ledPins[] = {2,​3,​4,​5,​6,​7,​8,​9};​ //Masyvas kaiščių sujungtas su LED'​ais 
 +                                   //​i.e. LED #0 sujungiamas su 2 kaiščiu, LED #1 --> 3; ir taip toliau 
 +                                   //​kreiptis į veikiantį masyvą: ledPins[0] yra lygus 2 
 +                                   //o ledPins[7] yra lygus 9 
 +  
 +/* 
 + * setup() - ši funkcija pradeda veikti, kai yra įjungiamas „Arduino“ 
 + * trys kaiščiai naudojami išvestims 
 + */ 
 +void setup() 
 +
 +   
 +  //​Nustatykite kiekvieną su LED lempute sujungtą kaištį, į išvesties rėžimą (pulling high (on) or low (off) 
 +  for(int i = 0; i < 8; i++){         //​šis ciklas kartosis 8 kartus 
 +      pinMode(ledPins[i],​OUTPUT);​ //šią funkciją naudojame nustatyti kiekvieną LED kaištį į išvesties rėžimus 
 +  }                                   //the code this replaces is below 
 +  
 +  /* (commented code will not run) 
 +   * these are the lines replaced by the for loop above they do exactly the 
 +   * same thing the one above just uses less typing 
 +  pinMode(ledPins[0],​OUTPUT);​ 
 +  pinMode(ledPins[1],​OUTPUT);​ 
 +  pinMode(ledPins[2],​OUTPUT);​ 
 +  pinMode(ledPins[3],​OUTPUT);​ 
 +  pinMode(ledPins[4],​OUTPUT);​ 
 +  pinMode(ledPins[5],​OUTPUT);​ 
 +  pinMode(ledPins[6],​OUTPUT);​ 
 +  pinMode(ledPins[7],​OUTPUT);​ 
 +  (end of commented code)*/ 
 +
 +  
 +  
 +/* 
 + * loop() - this function will start after setup finishes and then repeat 
 + * we call a function called oneAfterAnother(). if you would like a different behaviour 
 + * uncomment (delete the two slashes) one of the other lines 
 + */ 
 +void loop() ​                    // run over and over again 
 +
 +  oneAfterAnotherNoLoop(); ​  //​this will turn on each LED one by one then turn each off 
 +  //​oneAfterAnotherLoop(); ​  //​does the same as oneAfterAnotherNoLoop but with  
 +                             //​much less typing 
 +  //​oneOnAtATime(); ​         //this will turn one LED on then turn the next one 
 +                             //on turning the  
 +                             //​former off (one LED will look like it is scrolling  
 +                             //​along the line 
 +  //​inAndOut(); ​             //lights the two middle LEDs then moves them out then back  
 +                             //in again 
 +
 +  
 +/* 
 + * oneAfterAnotherNoLoop() - Will light one LED then delay for delayTime then light 
 + * the next LED until all LEDs are on it will then turn them off one after another 
 + * 
 + * this does it without using a loop which makes for a lot of typing.  
 + * oneOnAtATimeLoop() does exactly the same thing with less typing 
 + */ 
 +void oneAfterAnotherNoLoop(){ 
 +  int delayTime = 100; //the time (in milliseconds) to pause between LEDs 
 +                       //​make smaller for quicker switching and larger for slower 
 +  digitalWrite(ledPins[0],​ HIGH); ​ //Turns on LED #0 (connected to pin 2 ) 
 +  delay(delayTime); ​               //waits delayTime milliseconds 
 +  digitalWrite(ledPins[1],​ HIGH); ​ //Turns on LED #1 (connected to pin 3 ) 
 +  delay(delayTime); ​               //waits delayTime milliseconds 
 +  digitalWrite(ledPins[2],​ HIGH); ​ //Turns on LED #2 (connected to pin 4 ) 
 +  delay(delayTime); ​               //waits delayTime milliseconds 
 +  digitalWrite(ledPins[3],​ HIGH); ​ //Turns on LED #3 (connected to pin 5 ) 
 +  delay(delayTime); ​               //waits delayTime milliseconds 
 +  digitalWrite(ledPins[4],​ HIGH); ​ //Turns on LED #4 (connected to pin 6 ) 
 +  delay(delayTime); ​               //waits delayTime milliseconds 
 +  digitalWrite(ledPins[5],​ HIGH); ​ //Turns on LED #5 (connected to pin 7 ) 
 +  delay(delayTime); ​               //waits delayTime milliseconds 
 +  digitalWrite(ledPins[6],​ HIGH); ​ //Turns on LED #6 (connected to pin 8 ) 
 +  delay(delayTime); ​               //waits delayTime milliseconds 
 +  digitalWrite(ledPins[7],​ HIGH); ​ //Turns on LED #7 (connected to pin 9 ) 
 +  delay(delayTime); ​               //waits delayTime milliseconds ​  
 +  
 +//Turns Each LED Off 
 +  digitalWrite(ledPins[7],​ LOW);  //Turns on LED #0 (connected to pin 2 ) 
 +  delay(delayTime); ​               //waits delayTime milliseconds 
 +  digitalWrite(ledPins[6],​ LOW);  //Turns on LED #1 (connected to pin 3 ) 
 +  delay(delayTime); ​               //waits delayTime milliseconds 
 +  digitalWrite(ledPins[5],​ LOW);  //Turns on LED #2 (connected to pin 4 ) 
 +  delay(delayTime); ​               //waits delayTime milliseconds 
 +  digitalWrite(ledPins[4],​ LOW);  //Turns on LED #3 (connected to pin 5 ) 
 +  delay(delayTime); ​               //waits delayTime milliseconds 
 +  digitalWrite(ledPins[3],​ LOW);  //Turns on LED #4 (connected to pin 6 ) 
 +  delay(delayTime); ​               //waits delayTime milliseconds 
 +  digitalWrite(ledPins[2],​ LOW);  //Turns on LED #5 (connected to pin 7 ) 
 +  delay(delayTime); ​               //waits delayTime milliseconds 
 +  digitalWrite(ledPins[1],​ LOW);  //Turns on LED #6 (connected to pin 8 ) 
 +  delay(delayTime); ​               //waits delayTime milliseconds 
 +  digitalWrite(ledPins[0],​ LOW);  //Turns on LED #7 (connected to pin 9 ) 
 +  delay(delayTime); ​               //waits delayTime milliseconds ​  
 +
 +  
 +/* 
 + * oneAfterAnotherLoop() - Will light one LED then delay for delayTime then light 
 + * the next LED until all LEDs are on it will then turn them off one after another 
 + * 
 + * this does it using a loop which makes for a lot less typing.  
 + * than oneOnAtATimeNoLoop() does exactly the same thing with less typing 
 + */ 
 +void oneAfterAnotherLoop(){ 
 +  int delayTime = 100; //the time (in milliseconds) to pause between LEDs 
 +                       //​make smaller for quicker switching and larger for slower 
 +  
 +//Turn Each LED on one after another 
 +  for(int i = 0; i <= 7; i++){ 
 +    digitalWrite(ledPins[i],​ HIGH); ​ //Turns on LED #i each time this runs i 
 +    delay(delayTime); ​               //gets one added to it so this will repeat  
 +  }                                  //8 times the first time i will = 0 the final 
 +                                     //​time i will equal 7; 
 +  
 +//Turn Each LED off one after another 
 +  for(int i = 7; i >= 0; i--){  //same as above but rather than starting at 0 and counting u 
 +                    //p 
 +                                //we start at seven and count down 
 +    digitalWrite(ledPins[i],​ LOW);  //Turns off LED #i each time this runs i 
 +    delay(delayTime); ​               //gets one subtracted from it so this will repeat  
 +  }                                  //8 times the first time i will = 7 the final 
 +                                     //​time it will equal 0 
 +                                      
 +                                      
 +
 +  
 +/* 
 + * oneOnAtATime() - Will light one LED then the next turning off all the others 
 + */ 
 +void oneOnAtATime(){ 
 +  int delayTime = 100; //the time (in milliseconds) to pause between LEDs 
 +                       //​make smaller for quicker switching and larger for slower 
 +   
 +  for(int i = 0; i <= 7; i++){ 
 +    int offLED = i - 1;  //Calculate which LED was turned on last time through 
 +    if(i == 0) {         //for i = 1 to 7 this is i minus 1 (i.e. if i = 2 we will 
 +      offLED = 7;        //turn on LED 2 and off LED 1) 
 +    }                    //however if i = 0 we don't want to turn of led -1 (doesn'​t exist) 
 +                         //​instead we turn off LED 7, (looping around) 
 +    digitalWrite(ledPins[i],​ HIGH); ​    //​turn on LED #i 
 +    digitalWrite(ledPins[offLED],​ LOW); //turn off the LED we turned on last time 
 +    delay(delayTime);​ 
 +  } 
 +
 +  
 +/* 
 + * inAndOut() - This will turn on the two middle LEDs then the next two out 
 + * making an in and out look 
 + */ 
 +void inAndOut(){ 
 +  int delayTime = 100; //the time (in milliseconds) to pause between LEDs 
 +                       //​make smaller for quicker switching and larger for slower 
 +   
 +  //runs the LEDs out from the middle 
 +  for(int i = 0; i <= 3; i++){ 
 +    int offLED = i - 1;  //Calculate which LED was turned on last time through 
 +    if(i == 0) {         //for i = 1 to 7 this is i minus 1 (i.e. if i = 2 we will 
 +      offLED = 3;        //turn on LED 2 and off LED 1) 
 +    }                    //however if i = 0 we don't want to turn of led -1 (doesn'​t exist) 
 +                         //​instead we turn off LED 7, (looping around) 
 +    int onLED1 = 3 - i;       //​this is the first LED to go on ie. LED #3 when i = 0 and LED 
 +                    //  
 +                             //#0 when i = 3  
 +    int onLED2 = 4 + i;       //​this is the first LED to go on ie. LED #4 when i = 0 and LED 
 +                    //  
 +                             //#7 when i = 3  
 +    int offLED1 = 3 - offLED; //turns off the LED we turned on last time 
 +    int offLED2 = 4 + offLED; //turns off the LED we turned on last time 
 +     
 +    digitalWrite(ledPins[onLED1],​ HIGH); 
 +    digitalWrite(ledPins[onLED2],​ HIGH); ​    
 +    digitalWrite(ledPins[offLED1],​ LOW);     
 +    digitalWrite(ledPins[offLED2],​ LOW);         
 +    delay(delayTime);​ 
 +  } 
 +  
 +  //runs the LEDs into the middle 
 +  for(int i = 3; i >= 0; i--){ 
 +    int offLED = i + 1;  //Calculate which LED was turned on last time through 
 +    if(i == 3) {         //for i = 1 to 7 this is i minus 1 (i.e. if i = 2 we will 
 +      offLED = 0;        //turn on LED 2 and off LED 1) 
 +    }                    //however if i = 0 we don't want to turn of led -1 (doesn'​t exist) 
 +                         //​instead we turn off LED 7, (looping around) 
 +    int onLED1 = 3 - i;       //​this is the first LED to go on ie. LED #3 when i = 0 and LED 
 +                    //  
 +                             //#0 when i = 3  
 +    int onLED2 = 4 + i;       //​this is the first LED to go on ie. LED #4 when i = 0 and LED 
 +                    //  
 +                             //#7 when i = 3  
 +    int offLED1 = 3 - offLED; //turns off the LED we turned on last time 
 +    int offLED2 = 4 + offLED; //turns off the LED we turned on last time 
 +     
 +    digitalWrite(ledPins[onLED1],​ HIGH); 
 +    digitalWrite(ledPins[onLED2],​ HIGH); ​    
 +    digitalWrite(ledPins[offLED1],​ LOW);     
 +    digitalWrite(ledPins[offLED2],​ LOW);         
 +    delay(delayTime);​ 
 +  } 
 +
 +</​code>​ 
 + 
 +**Neveikia? Trys galimos išeitys:​** 
 +  *Kai kurie LED'ai neužsidega - Lengva įstatyti LED'ą ne ta puse. Patikrinkite neveikiančius LED'us ir įsitikinkite,​ kad jie įdėti reikiama puse. 
 + 
 +  *Laidų klaida - jungiant 8 laidus lengva susipainioti. Dar kartą patikrinkite,​ ar pirmasis LED'as yra įstatytas į 2 kontaktą ir t.t. 
 + 
 +  *Pradėti iš naujo - lengva įdėti laidą ne ten kur reikia. Viską ištraukite iš plokštės ir bandykite iš naujo - dažnai tai lengviausias būdas ištaisyti klaidą. 
 + 
 +**Norite geriau?** 
 +Pakeisti Loops:  
 +loop() yra keturios eilutės. Paskutinės 3 prasideda dviem pasviraisiais brūkšniais,​ tai reiškia kad su eilute yra elgiamasi kaip su komentaru (neveikti). Pakeisti programą, kad veiktu eilutė void loop() kodu: 
 + 
 +<​code>​ 
 +//​oneAfterAnotherNoLoop();​ 
 +       ​oneAfterAnotherLoop();​ 
 +              //​oneOnAtATime();​ 
 +                     //​inAndOut();​ 
 +</​code>​ 
 + 
 +Įkėlę programą pastebime, kad niekas nepasikeitė. Galite pažiūrėti į dvi funkcijas, kiekviena kažką daro, bet naudoja skirtingus priėjimus. 
 +  
 +**Kitos animacijos:​**  
 +Pavargote nuo tos pačios animacijos? Tada pabandykite kitas dvi animacijas. Nukopijuokite jų eilutes ir įkelkite programą į lentelę ir mėgaukitės nauja animacija. (ištrinkite pasvyruosius brūkšnelius prieš 3 ir 4 eilutes)  
 + 
 +**Savo paties sukurtos animacijos bandymas:**  
 +Pažvelkite į įtrauktus kodus ir pradėkite po truputį juos keisti. Pagrindinis tikslas yra panaudoti LED'us darbe, naudokite:  
 +  
 +<​code>​ 
 +digitalWrite(pinNumber,​ HIGH); 
 +</​code>​ 
 + 
 +Tada jį išjunkite naudodami;  
 + 
 +<​code>​ 
 +digitalWrite(pinNumber,​ LOW); 
 +</​code>​ 
 + 
 +Nebijokite viską keisti, nesvarbu, ką parašysite,​ nieko nesugadinsite. ​
  
-{{:​ardu_pro4.jpg?​300|}}{{:​ardu_pro41.jpg?​300|}}{{:​ardu_pro42.png?​300|}} 
  
 [[projektas_nr.5|Kitas projektas. Mygtukai.]] [[projektas_nr.5|Kitas projektas. Mygtukai.]]
  
 [[arduivadas_projektai|Atgal į projektus]] [[arduivadas_projektai|Atgal į projektus]]
projektas_nr.4.1445794486.txt.gz · Keista: 2015/10/25 19:34 vartotojo 193.219.47.27