Arduino 13 - nastavovanie serva

From DT^2
Revision as of 09:10, 31 July 2019 by Palo (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
#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);
  }
}