Soros kommunikáció - alapkérdések...

Processing/Wiring (illetve C) nyelvű programozási fogások, tippek. (AVR-Duino, Arduino, EthDuino, Diecimila, Severino, Nano, LilyPad)
Válasz küldése
Avatar
benzinkutas
DrótVégénSzéndarab
Hozzászólások: 31
Csatlakozott: 2011. április 30. szombat, 6:00

Hozzászólás Szerző: benzinkutas »

Mit Jelentenek? Már több helyen találkoztam velük. Az ardunio honlapján is nézegettem fordítón keresztül de nem sikerült megfeljeni mit is csinálnak.

serial.begin(9600)
serial.println
serial.print
Avatar
kapu48
Elektronbűvölő
Hozzászólások: 3375
Csatlakozott: 2008. augusztus 29. péntek, 6:00

Hozzászólás Szerző: kapu48 »

Beállítja a soros port sebességét 9600 Baudra: serial.begin(9600)
A ki küldőt string végéhez csatolja a sorvége, újsor ASCII jeleket: serial.println
Ki küldi a soros portra a Stringet : serial.print („String”);

file://localhost/C:/Program%20Files/arduino-1.0/reference/Serial.html
8)
Avatar
benzinkutas
DrótVégénSzéndarab
Hozzászólások: 31
Csatlakozott: 2011. április 30. szombat, 6:00

Nem értem!

Hozzászólás Szerző: benzinkutas »

Ez a kis programocskát az arduino.cc-ről másoltam ki. Egy led fény erejét változtatja a potméter ellenállásától függően. Ezt én úgy oldottam meg hogy a nullás analóg bemeneten olvastam a poti értékét majd néggyel való osztás után az eredményt egy PWM kimenetre Írtam. Kérdés: miéer jobb ez így és ebben a példában mit csinál serial.begin(9600) serial.println, serial.print, map(sensorValue, 0, 1023, 0, 255);? Minek a soros portját állítja be? És hol vannak itt stringek?

const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to

int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}

void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);

// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);

// wait 10 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(10);
}
Avatar
Yoda
Újonc
Újonc
Hozzászólások: 10
Csatlakozott: 2012. április 24. kedd, 6:00

Re: Nem értem!

Hozzászólás Szerző: Yoda »

Sziasztok,

nem vagyok egy C guru, de ez egyszerűnek tűnik:
Ugyan azt csinálja mint a te programod:
analogRead = Analóg bemenet beolvasása
Map = ez egy hozzá rendelés (MAP-pelés) gyakorlatilag itt 4-el való osztás
nem ismerem pontosan a map függvényt de egy lineáris megfeleltetést végez (0 nak a 0 felel meg, 1023 nak a 255)
rajzold fel és meglátod

AnalogWrite = gondolom ez a pwm kimenet

Pluszban kiküldi mind a mért mind a pwm értékét soros buszon

Üdv,
Csaba

benzinkutas írta:Ez a kis programocskát az arduino.cc-ről másoltam ki. Egy led fény erejét változtatja a potméter ellenállásától függően. Ezt én úgy oldottam meg hogy a nullás analóg bemeneten olvastam a poti értékét majd néggyel való osztás után az eredményt egy PWM kimenetre Írtam. Kérdés: miéer jobb ez így és ebben a példában mit csinál serial.begin(9600) serial.println, serial.print, map(sensorValue, 0, 1023, 0, 255);? Minek a soros portját állítja be? És hol vannak itt stringek?

const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to

int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}

void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);

// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);

// wait 10 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(10);
}
Avatar
kapu48
Elektronbűvölő
Hozzászólások: 3375
Csatlakozott: 2008. augusztus 29. péntek, 6:00

Hozzászólás Szerző: kapu48 »

Ha ennyire kezdő vagy ajánlom a Fő oldalon levő „Bascom leírás illetve könyv” olvasását!
http://avr.tavir.hu/modules.php?name=Co ... ies&cid=15
8) :arrow:

És +: Felhasználói dokumentáció
http://avr.tavir.hu/modules.php?name=Do ... oad&cid=10

:wink:
Válasz küldése