Difference between revisions of "Arduino 13 - nastavovanie serva"

From DT^2
Jump to: navigation, search
(Created page with "<syntaxhighlight lang="C++"> #include <Servo.h> Servo motor; int uhol; void setup() { motor.attach(2); uhol = 90; motor.write(90); Serial.begin(9600); } void loop() {...")
 
m
 
Line 13: Line 13:
 
   if (Serial.available())
 
   if (Serial.available())
 
   {
 
   {
 +
    char c = Serial.read();
 
     if (c == 'a')  
 
     if (c == 'a')  
 
       if (uhol < 180) uhol++;
 
       if (uhol < 180) uhol++;

Latest revision as of 07:10, 31 July 2019

#include <Servo.h>
Servo motor;
int uhol;

void setup() {
  motor.attach(2);
  uhol = 90;
  motor.write(90);
  Serial.begin(9600);
}
void loop() {
  if (Serial.available())
  {
    char c = Serial.read();
    if (c == 'a') 
      if (uhol < 180) uhol++;
    if (c == 'z')
      if (uhol > 0) uhol--;
    Serial.println(uhol);
    motor.write(uhol);
  }
}