BASIC4MCU | 질문게시판 | 아두이노 터치센서,스텝모터
페이지 정보
작성자 아두이노굿 작성일2019-05-14 23:49 조회682회 댓글5건본문
아두이노 UNO를 활용하여
touchsensor 10개를 연결하여 스텝모터를 제어하는 코딩을 하려고 합니다.
그런데 스텝모터 예제와 터치센서 예제들을 찾아보며 모두 해보았는데 잘안됩니다...
touchsensor 가 모두 터치 안되었을때 스텝모터가 시계방향으로 계속 돌고
터치센서가 단 1개라도 터치가 되었을때 스텝모터가 반시계방향으로 3초 돌고 멈추는 상황을 만드려고 합니다.
어찌 코딩을 해야할까요.. 부탁드립니다 알려주세요...
1달째 이것만 하는데 잘 안됩니다..
댓글 5
조회수 682master님의 댓글
master 작성일작성중인 코드를 첨부해보세요
아두이노굿님의 댓글
아두이노굿 작성일
int touchSensor1 = 1;
int touchSensor2 = 2;
int touchSensor3 = 3;
int touchSensor4 = 4;
int touchSensor5 = 5;
int touchSensor6 = 6;
int touchSensor7 = 7;
int touchSensor8 = 8;
#include <Stepper.h>
const int stepPerRevolution = 1024;
Stepper myStepper(stepsPerRevolution,13,12,11,10);
void setup() {
Serial.begin(9600);
myStepper.setSpeed(11);
pinMode(touchSensor1,INPUT);
pinMode(touchSensor2,INPUT);
pinMode(touchSensor3,INPUT);
pinMode(touchSensor4,INPUT);
pinMode(touchSensor5,INPUT);
pinMode(touchSensor6,INPUT);
pinMode(touchSensor7,INPUT);
pinMode(touchSensor8,INPUT);
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
pinMode(10,OUTPUT);
}
void loop() {
int touchValue1 = digitalRead(touchSensor1);
int touchValue2 = digitalRead(touchSensor2);
int touchValue3 = digitalRead(touchSensor3);
int touchValue4 = digitalRead(touchSensor4);
int touchValue5 = digitalRead(touchSensor5);
int touchValue6 = digitalRead(touchSensor6);
int touchValue7 = digitalRead(touchSensor7);
int touchValue8 = digitalRead(touchSensor8);
if(touchValue1 == LOW
touchValue2 == LOW
touchValue3 == LOW
touchValue4 == LOW
touchValue5 == LOW
touchValue6 == LOW
touchValue7 == LOW
touchValue8 == LOW
)
{
myStepper.step(stepsPerRevolution);
Serial.println("STOP")
}
else
{
myStepper.step(-stepsPerRevolution);
delay(300);
noTone(myStepper.step);
Serial.println("GO")
}
}
이렇게 짯습니다... 제가 기계쪽인데 아두이노도 관심이 있어서 해보는 건데 몇개 다니까 어렵네요..
master님의 댓글
master 작성일
int touchSensor1 = 1;
1번핀을 사용하면 안됩니다.
0,1번핀은 업로드 및 시리얼모니터에서 사용하므로 다른핀을 사용하세요
아두이노굿님의 댓글
아두이노굿 작성일저 위에 코드에서 stepsPerRevolution이 정의가 안되어있다고 하는데 어찌하나요 ㅠㅠ
master님의 댓글
master
const int stepPerRevolution = 1024;
변수 선언이 있습니다.