RC카 만들기 꿈의 대학 6주차이지만 과정 운영이 만만치 않다. 참가학생들 개인 사정으로 인해 진도가 틀어져 버려 거의 12대의 자작 RC카를 운영하는 셈이 되어 버렸다. 말이 쉬워 12대이지 RC카별로 일대일 튜토링이 쉽지는 않다.
이 프로그램을 업로딩 후 USB 케이블을 연결한 채로 시리얼 모니터에서 문자 F,B,L,R,S를 입력 전송 버튼을 눌러 RC카의 바퀴가 돌아감을 확인하자.
잘 돌지 않으면 mspd=255 로 수정 업로딩 후 다시 해 보자.
Play Store에서 앱을 다운받자(※EvArt 로 검색 후 3번째 앱) 어떤 학생의 경우는 6번째에서 찾을 수 있었다.
바퀴가 생각대로 잘 돌면 USB 케이블을 뽑고 아래의 블루투스 배선 작업을 하자.
9V 전지를 연결하면 블루투스 보드의 LED가 점멸한다. 스마트폰에서 Pairing 작업을 진행한다. 앱에서 윗부분을 누르면 검은색 화면에 블루투스 주소가 뜬다. 블루투스 Pairing 작업에서는 한 사람씩 진행하여 혼선을 피하도록 한다. 이 단계에서 의외로 젊은 스마트폰 컴맹들이 많았다. 하지만 거의 100% 성공에 가까운 듯 하다.
//FOF4YFTIA0WX947_F_BT_01
#include <AFMotor.h>
AF_DCMotor motor1(3);
AF_DCMotor motor2(4);
int mspd = 160;
char command;
void setup() {
Serial.begin(9600);
Stop();
}
void loop(){
if(Serial.available() > 0){
command = Serial.read();
if( command == 'F') {
forward();
delay(1000);
}
if( command == 'B') {
back();
delay(1000);
}
if( command == 'L') {
left();
delay(1000);
}
if( command == 'R') {
right();
delay(1000);
}
if( command == 'S') {
Stop();
delay(1000);
}
}
}
void forward() {
motor1.setSpeed(mspd); //Define maximum velocity
motor1.run(FORWARD); //rotate the motor clockwise
motor2.setSpeed(mspd); //Define maximum velocity
motor2.run(FORWARD); //rotate the motor clockwise
}
void back() {
motor1.setSpeed(mspd);
motor1.run(BACKWARD); //rotate the motor counterclockwise
motor2.setSpeed(mspd);
motor2.run(BACKWARD); //rotate the motor counterclockwise
}
void left() {
motor1.setSpeed(mspd); //Define maximum velocity
motor1.run(FORWARD); //rotate the motor clockwise
motor2.setSpeed(0);
motor2.run(RELEASE); //turn motor2 off
}
void right() {
motor1.setSpeed(0);
motor1.run(RELEASE); //turn motor1 off
motor2.setSpeed(mspd); //Define maximum velocity
motor2.run(FORWARD); //rotate the motor clockwise
}
void Stop() {
motor1.setSpeed(0);
motor1.run(RELEASE); //turn motor1 off
motor2.setSpeed(0);
motor2.run(RELEASE); //turn motor2 off
}
//끝
안녕하세요 codingart님
좋은 하루 보내세요!!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
예전 워크샵에서 자동차 만들던 기억이 새록새록 납니다
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
경험이 있으시군요!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit