#include <Servo.h>
Servo myservo;
int sw1 = 0, pot1 = 0;
unsigned long skr = 0;
void setup() {
  Serial.begin(9600);
  myservo.attach(5);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, OUTPUT);
}
void loop() {
  int sw = !digitalRead(2);//a
  if (sw != sw1) {
    Serial.print("a");
    Serial.println(sw);
  }
  sw1 = sw;
  int pot = analogRead(A0);//c
  if (millis() - skr > 2000 && pot != pot1) {
    skr = millis();
    Serial.print("c");
    Serial.println(analogRead(A0));
  }
  pot1 = pot;
}
void serialEvent() {
  while (Serial.available()) {
    char awal = Serial.read();
    int nilai = Serial.parseInt();
    if (Serial.read() == char(13)) {
      if (awal == 'b') digitalWrite(3, nilai);
      if (awal == 'd') myservo.write(nilai);
    }
  }
}