서보모터와 스위치에 관해 문의드립니다.

sm**** 2018-06-07 (목) 23:16 5년전 1809  
서보모터와 스위치를 이용해 로봇팔을 만들고 싶은데요, motor5라는 오른팔을 이용해 180도까지 움직였다가 다시 반대 방향으로 움직이면서 팔에 달려있는 스위치가 눌러진다면 특정 동작을 수행하고 안눌러지면 motor4를 다시 구동시키고 싶은데 이 것을 어떻게 소스를 짜야할지 모르겠습니다.
--------------------------------------------------------------------
Servo motor3;
Servo motor4;
Servo motor5;
const int inputPin1 = 6;
const int inputPin2 = 7;

void setup() {
Serial.begin(9600);
motor3.attach(3);
motor4.attach(4);
motor5.attach(5);
motor3.write(90);
motor4.write(90);
motor5.write(90);
pinMode(inputPin1, INPUT_PULLUP);
pinMode(inputPin2, INPUT_PULLUP);
}

void loop() {

motor5.write(180);
delay(500);
while()

}
메카리워즈 Image Map

메이커 2018-08-19 (일) 23:52 5년전
스위치가 digital 핀에 연결되어 있는 상태에서 if문으로 digitalRead(pin번호)가 반환하는 값이 1 혹은 0이면 motor5.write(180);
위와 같은 식으로 하면 될 것 같습니다.
주소

모바일 버전으로 보기