BASIC4MCU | 질문게시판 | 아두이노 코딩해결해주실분..
페이지 정보
작성자 닉네1257679 작성일2018-06-06 21:13 조회8,463회 댓글0건본문
1.밑에 코딩에서 스텝모터 초기값 3Turns로설정하여 정회전 역회전을 반복한다
스텝모터의 속도를 60rpm으로 설정한다
2.8개의 스위치중에서 한개를 누르면 해당스위치대해 LED를 점등한다.
이떄 눌러진 스위치 번호 (1~8)에 해당하는 값을 스텝모터의 방향전환 변수로 변경한다. (모름)
3.누른 스위치를 떼더라도 직전에 눌러졌던 스위치에 대한 LED는 점등상태를 유지한다.(모름)
4.아두이노 보드의 i/o 번호는
스위치:23,25,27,29,31,33,35,37
LED: 22,24,26,28,30,32,34,36
step motor : A/A, B,/B : 38,42,40,44
1,2,3,4코딩 완성시켜줄 아두이노 고수분.... 찾습니다
#include <Stepper.h>
#include <MsTimer2.h>
// total number of steps this motor can take
#define STEPS 100
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 38,42,40,44);
volatile int mystep = 1;
#define DIR_CHANHE_CNT 2 //방향전환카운트
volatile byte ecd_cnt = 0;
volatile boolean flag=false; //챕터링방지
volatile byte flag_cnt=0;
2)
void setup()
{
// set the speed of the motor to 30 RPMs
stepper.setSpeed(30); <<<<<<<<<<<<<<<<<<<<< 1번 내용 //이걸 60으로 바꾸면대나요??
attachInterrupt(0, blink, FALLING); // Int0 => pin 2
MsTimer2::set(20, flash); // 20ms period
MsTimer2::start();
}
3)
void loop()
{
// step the motor to step number 0, 1, 2, or 3:
stepper.step(mystep); // step one step:
}
4)
void blink()
{
flag = true;//자기장센서챕터링방지하기위함.
if(ecd_cnt == DIR_CHANHE_CNT)
{
mystep*=-1;
ecd_cnt = 0;
}
}
5)
void flash()
{
if(flag == true) //자기장센서챕터링방지가설정되면
flag_cnt++; //카운트시작 ,적어도자기장센서가반응하는범위를벗어날떄까지카운트
if(flag_cnt == 10){
flag = false;
flag_cnt = 0; //범위를벗어나면플래그해제
ecd_cnt++;
}
}
댓글 0
조회수 8,463등록된 댓글이 없습니다.