User Tools

Site Tools


projektas_nr.2

Čia yra sena dokumento versija!


Projektas Nr. 2. Sukiojame. Potenciometrai

Ką darome

Kartu su skaitmeniniais kontaktais, Arduino taip pat turi 6 kontaktus kurie gali būti panaudoti analoginei įvesčiai. Šios įvestys paima įtampą (nuo 0 iki 5 voltų) ir konvertuoja ja į skatmeninį numerį nuo 0 (0 voltų) iki 1023 (5 voltų) (10 bitų gebos). Labai naudingas prietaisas, skirtas išnaudoti šias įvestis yra potenciometras (dar vadinamas kintamo dydžio rezistoriumi). Kai jis prijungiamas prie 5 voltų per išorinius kontaktus, vidurinysis kontaktas nuskaito vertę nuo 0 iki 5 voltų, priklausomai nuo kampo, kuriuo jis yra pasuktas (pavyzdžiui, 2,5 voltų viduryje). Mes taipogi galime naudoti grąžinamąsias vertes kaip kintamąjį mūsų programoje.

Grandinės dalys:

  • CIRC-01 Grandinės šablonasx1
  • 2 kontaktų kištukasx4
  • Potenciometras 10 kΩx1
  • Laidaix3 Green LEDx1
  • 560 Ω rezistorius(žalias-mėlynas-rudas)x1

Grandinės schema:

surinkimo šablonas- http://ardx.org/BBLS08, surinkimo filmukas - http://ardx.org/VIDE08

Code File > Examples > 3.Analog > AnalogInput (example from the great arduino.cc site, check it out for other great ideas)

/*

Analoginė įvestis

Parodo analoginį įėjimą skaitant analoginį daviklį iš  analoginio pin 0 ir 
įjungiant ir išjungiant šviesą spinduliuojantį šviesos diodą (LED), prijungtą prie skaitmeninės pin 13. 

Kiek laiko LED bus įjungtas ir išjungtas priklauso nuo jo vertės, gautos iš analogRead ()

Potenciometras pridedamas prie analoginio įėjimo 0

  • Ašis į analoginį pin potenciometrą
  • Viena pusė pin (arba vienas) su korpusu
  • Kitos pusės pin 5 V
  • LED anodus (ilgom kojom), pritvirtinam prie skaitmeninės produkcijos 13
  • LED katodus (trumpom kojom), pritvirtintam prie žemės
  • Pastaba: kadangi dauguma Arduinų yra įterpti LED pridėtam

pin 13 ant lentos, LED neprivaloma.

http://arduino.cc/en/Tutorial/AnalogInput

*/

int sensorPin = 0; pasirinkite įvesties pin potenciometrą int ledPin = 13; pasirinkite pin LED’ui int sensorValue = 0; kintamasis saugoti vertės ateina iš daviklio void setup() { parankame ledipin’ui galia:

pinMode(ledPin, OUTPUT);  

}

void loop() {

// skaitykite vertę nuo jutiklio:
sensorValue = analogRead(sensorPin);    
// įjunkite ledPin  
digitalWrite(ledPin, HIGH);  
// sustabdykite programa kelioms milisekundėmis:
delay(sensorValue);          
// išjunkite ledPin :        
digitalWrite(ledPin, LOW);   
// sustabdykite programą kelioms milisikundėmis:
delay(sensorValue);                  

}

Neveikia? (3 dalykai bandymui)

Not Working Make sure you haven't accidentally connected the potentiometer's wiper to digital pin 2 rather than analog pin 2. (the row of pins beneath the power pins)

Still Backward You can try operating the circuit upside down. Sometimes this helps.

Making it Better?

Threshold Switching: Sometimes you will want to switch an output when a value exceeds a certain threshold. To do this with a potentiometer change the loop() code to.

void loop() {

int threshold = 512; 
if(analogRead(potPin) > threshold){ digitalWrite(ledPin, HIGH);} 
else{ digitalWrite(ledPin, LOW);} 

}

This will cause the LED to turn on when the value is above 512 (about halfway), you can adjust the sensitivity by changing the threshold value.

Fading: Lets control the brightness of an LED directly from the potentiometer. To do this we need to first change the pin the LED is connected to. Move the wire from pin 13 to pin 9 and change one line in the code.

int ledPin = 13; ----> int ledPin = 9; 

Then change the loop code to.

void loop() {

int value = analogRead(potPin) / 4; 
analogWrite(ledPin, value); 

}

Upload the code and watch as your LED fades in relation to your potentiometer spinning. (Note: the reason we divide the value by 4 is the analogRead() function returns a value from 0 to 1024 (10 bits), and analogWrite() takes a value from 0 to 255 (8 bits) )

Controlling a Servo: This is a really neat example and brings a couple of circuits together. Wire up the servo like you did in CIRC-04, then open the example program Knob (File > Examples > Library-Servo > Knob ), then change one line of code.

int potpin = 0; ----> int potpin = 2; 

Upload to your Arduino and then watch as the servo shaft turns as you turn the potentiometer.

Kitas projektas. Spalvotos šviesos gavimas naudojant RGB šviesos diodą.

Atgal į projektus

projektas_nr.2.1445789049.txt.gz · Keista: 2015/10/25 18:04 vartotojo 193.219.47.27