Seriova linka

Serial.begin(9600)

10, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200, 128000 and 256000

10, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200, 128000 and 256000

Baudrate predstavuje rýchlosť komunikácie (bity za sekundu)

Inicializacia komunikácie pomocou príkazu begin()

Serial.print("string")

10, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200, 128000 and 256000

Príkaz print() odošle parameter na sériovu linku

Serial.println("string")

Príkaz println() odošle parameter na sériovu linku a CR NL (novy riadok)

Hello

void setup()
{
	Serial.begin(9600);
    Serial.println("Arduino sa prave zaplo");
}

void loop() 
{
	Serial.println("Hello);
    delay(1000)
}

analogRead(A0)

10, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200, 128000 and 256000

Vracia analógovú hodnotu na pine

Analog Read

 

void setup()
{
	Serial.begin(9600);
}

void loop() 
{
	int = analogRead(A0);
	Serial.println(A0);
	delay(1000)
}

Serial.available()

10, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200, 128000 and 256000

Vracia počet neprečítaných znakov v buffri

Ovládanie LED pomocou seriovej linky

void setup()
{
	pinMode(13, OUTPUT);
	Serial.begin(9600);
    Serial.println("Input 1 to Turn LED on and 2 to off");
}

void loop() 
{
	if (Serial.available())
    {
		int state = Serial.parseInt();
      	if (state == 1)
    	{
          digitalWrite(4, HIGH);
          Serial.println("Command completed LED turned ON");
        }
		if (state == 2)
		{
          digitalWrite(4, LOW);
          Serial.println("Command completed LED turned OFF");
        }
    }
}
Made with Slides.com