Toggle navigation
Toggle navigation
This project
Loading...
Sign in
이다은
/
raspberry
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
daeun
2021-04-22 22:50:08 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
14c2319e6e029e4092bdaa44fc2f0d3a08a39fe9
14c2319e
1 parent
f3049f5d
modify
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
example/lab2-5_2.c
example/lab2-5_2.c
0 → 100644
View file @
14c2319
#include <wiringPi.h> // GPIO Access Library 헤더파일 선언
#include <softPwm.h> // Software PWM library 헤더파일 선언
// Motor 핀 설정
#define MOTOR_MT_N_PIN 17
#define MOTOR_MT_P_PIN 4
// Motor 회전 방향 정의
#define LEFT_ROTATE 1
#define RIGHT_ROTATE 2
// Motor 정지 함수
void
MotorStop
()
{
softPwmWrite
(
MOTOR_MT_N_PIN
,
0
);
softPwmWrite
(
MOTOR_MT_P_PIN
,
0
);
}
// Motor 속도 조절 함수
void
MotorControl
(
int
speed
)
{
digitalWrite
(
MOTOR_MT_P_PIN
,
LOW
);
softPwmWrite
(
MOTOR_MT_N_PIN
,
speed
);
}
int
main
(
void
)
{
if
(
wiringPiSetupGpio
()
==
-
1
)
return
1
;
// Motor 핀 출력으로 설정
pinMode
(
MOTOR_MT_N_PIN
,
OUTPUT
);
pinMode
(
MOTOR_MT_P_PIN
,
OUTPUT
);
// Motor 핀 PWM 제어 핀으로 설정
// 주기: 100ms
softPwmCreate
(
MOTOR_MT_N_PIN
,
0
,
100
);
softPwmCreate
(
MOTOR_MT_P_PIN
,
0
,
100
);
while
(
1
)
{
MotorControl
(
25
);
// Duty Cycle 25% 동작
delay
(
2000
);
MotorStop
();
// Motor 정지
delay
(
2000
);
MotorControl
(
50
);
// Duty Cycle 50% 동작
delay
(
2000
);
MotorStop
();
// Motor 정지
delay
(
2000
);
MotorControl
(
75
);
// Duty Cycle 75% 동작
delay
(
2000
);
MotorStop
();
// Motor 정지
delay
(
2000
);
}
return
0
;
}
\ No newline at end of file
Please
register
or
login
to post a comment