About Us About Embedded Introduce Editorial Contributions Location Document Android Application Embedded Linux Processor Arduino AVR Devices Resource Android Application Embedded Linux Processor Arduino AVR Devices Education 교육과정안내 교재 프로젝트 자료실 Reference Community 공지사항 제품광고 구인광고
DC 모터의 가변저항과 스위치 방향 제어하기 작성자 임베디드코리아 작성일25-05-15 23:53 조회185회 댓글0건 첨부파일 DCmotor_Direction_Speed.ino (706byte) 0회 다운로드 DATE : 2025-05-18 00:50:07 이전글 다음글 목록 <* DC 모터의 가변저항과 스위치 방향 제어 *> - 두 핀 모두 연결하여 출력 값을 조절해 DC모터의 회전 방향을 바꿀 수 있다. ---- < DC 모터의 가변저항과 스위치 방향 제어 소스 코드 > ----------------------- int convertedPin = A0; int convertedValue=0; int speedValue = 0; int inputValue = 0; void setup() { pinMode(Motor_PinA, OUTPUT); pinMode(Motor_PinB, OUTPUT); pinMode(convertedPin, INPUT); pinMode(switchPin, INPUT); } void loop() { /* 가변저항의 입력 값 읽기 */ convertedValue = analogRead(convertedPin); /* 입력 값 범위를 0 ~ 255로 변환*/ speedValue = map(convertedValue, 0, 1023, 0, 255); if (inputValue ==LOW) { analogWrite(Motor_PinA, speedValue); analogWrite(Motor_PinB, 0); } else { analogWrite(Motor_PinA, 0); analogWrite(Motor_PinB, speedValue); } delay(100); } 이전글 다음글 목록