질문게시판 > 슈퍼루프 구조 질문입니다.

TODAY503 TOTAL2,696,382
사이트 이용안내
Login▼/회원가입
최신글보기 질문게시판 기술자료 동영상강좌

아두이노 센서 ATMEGA128 PWM LED 초음파 AVR 블루투스 LCD UART 모터 적외선


BASIC4MCU | 질문게시판 | 슈퍼루프 구조 질문입니다.

페이지 정보

작성자 손문일 작성일2018-12-03 00:00 조회5,616회 댓글0건

첨부파일

본문

	

안녕하세요. 마스터님 항상 감사드립니다.

혼자 이것 저것 해보다 도저히 안되어서 질문 드립니다.

 

코딩내용

  슈퍼 루프 구조

    supersonic = 초음파 센서와 네오픽셀을 같이 넣었습니다. 

        (거리(distance)에 따라 네오픽셀을 다르게 하기 위해서 같은 루프안에 넣었습니다.)

    servomotor = 모터 구동 코드 

 

문제점

  1. 초음파 센서 = 시리얼 모니터 값이 조금 느리게 인식되어져 표시 됩니다.

     (초음파 센서 코딩만 따로 아두이노에 입력하면 잘나오는데 아래 코드로 하면 네오픽셀이 다 구동되고 나서 초음파를 쏘는듯합니다.)

  2. 네오픽셀 = 모터가 처음 동작 전에 직지직 거리면서 아주 약하게 불이 깜박입니다.

  3. 서보모터 = 처음 구동전에 혼자 직직직 거리고 난후에야 입력한데로 동작 됩니다.

 

아래에 동작 동영상도 포함해 넣었습니다.

 

void setup(){

  supersonic_setup();

  servomotor_setup();

}

 

void loop(){

  supersonic_loop();

  servomotor_loop();

}

 

#include <Adafruit_NeoPixel.h>                      //네오픽셀 라이브러리 불러오기

int PIN = 3;                                           //네오픽셀 3번핀에 고정

Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);  //위 pin3번이랑 대응

 

 

int supersonic_echo = 7;                               //초음파 센서 echo 7번핀

int supersonic_trig = 6;                               //초음파 센서 trig 6번핀

long supersonic_previousMillis = 0;                    //millis 함수

long supersonic_interval = 100;                        //millis 함수

 

 

void supersonic_setup() {

Serial.begin(115200);                                 //초음파 센서

  pinMode(supersonic_trig, OUTPUT);                    //초음파 센서

  pinMode(supersonic_echo, INPUT);                     //초음파 센서

 

  strip.begin();                                       //네오픽셀

  strip.show();                                        //네오픽셀 Initialize all pixels to 'off'

}

 

 

void supersonic_loop() {

  unsigned long currentMillis = millis();

 

  if(currentMillis - supersonic_previousMillis >= supersonic_interval) {

    supersonic_previousMillis = currentMillis;

 

 

float Length, distance;                                 //초음파 센서

  digitalWrite(supersonic_trig, HIGH);

  digitalWrite(supersonic_trig, LOW);

  

  Length = pulseIn(supersonic_echo, HIGH); 

  distance = ((float)(340 * Length) / 10000) / 2;  

  

  Serial.print(distance);

  Serial.println(" Cm");

 

 

 

if(distance < 30){

for(int i=0; i<=255; i+=1){

  strip.setPixelColor(0,strip.Color(0,50,255));  

  strip.setPixelColor(1,strip.Color(0,100,255)); 

  strip.setPixelColor(2,strip.Color(0,150,255));

  strip.setPixelColor(3,strip.Color(0,200,255));

  strip.setPixelColor(4,strip.Color(0,255,255));

  strip.setPixelColor(5,strip.Color(0,255,255));

  strip.setPixelColor(6,strip.Color(0,255,255));

  strip.setPixelColor(7,strip.Color(0,255,255)); //초록

  strip.setPixelColor(8,strip.Color(255,255,0)); //노랑  

  strip.show(); delay(10);

}

for(int i=0; i<=255; i+=1){

  strip.setPixelColor(0,strip.Color(0,50,255));  

  strip.setPixelColor(1,strip.Color(0,100,255)); 

  strip.setPixelColor(2,strip.Color(0,150,255));

  strip.setPixelColor(3,strip.Color(0,200,255));

  strip.setPixelColor(4,strip.Color(0,255,255));

  strip.setPixelColor(5,strip.Color(i,255-i,255-i));

  strip.setPixelColor(6,strip.Color(i,255,255-i));

  strip.setPixelColor(7,strip.Color(0,255,255)); //초록

  strip.setPixelColor(8,strip.Color(255,255,0)); //노랑  

  strip.show(); delay(10);

}

for(int i=255; i>=0; i-=1){

  strip.setPixelColor(0,strip.Color(0,50,255));  

  strip.setPixelColor(1,strip.Color(0,100,255)); 

  strip.setPixelColor(2,strip.Color(0,150,255));

  strip.setPixelColor(3,strip.Color(0,200,255));

  strip.setPixelColor(4,strip.Color(0,255,255));

  strip.setPixelColor(5,strip.Color(i,255-i,255-i));

  strip.setPixelColor(6,strip.Color(i,255,255-i));

  strip.setPixelColor(7,strip.Color(0,255,255)); //초록

  strip.setPixelColor(8,strip.Color(255,255,0)); //노랑

  strip.show(); delay(10);

}

}

 

else if (distance > 30){

for(int i=0; i<=255; i+=1){

  strip.setPixelColor(0,strip.Color(255,50,0));  

  strip.setPixelColor(1,strip.Color(255,100,0)); 

  strip.setPixelColor(2,strip.Color(255,150,0));

  strip.setPixelColor(3,strip.Color(255,200,0));

  strip.setPixelColor(4,strip.Color(255,255,0));

  strip.setPixelColor(5,strip.Color(255,255,0));

  strip.setPixelColor(6,strip.Color(255,255,0));

  strip.setPixelColor(7,strip.Color(255,255,0));         //초록

  strip.setPixelColor(8,strip.Color(255,255,0));         //노랑  

  strip.show(); delay(10);

}

}

}

}

 

 

#include <Servo.h>                   //servomotor         

Servo servomotor;                   //servomotor 

int servomotor_pos = 0;              //servomotor

long servomotor_previousMillis = 0;

long servomotor_interval = 1000;

 

 

void servomotor_setup(){

servomotor.attach(9);       //servomotor를 9번핀에 준비시킵니다.

}

 

void servomotor_loop(){

  unsigned long currentMillis = millis();

 

  if(currentMillis - servomotor_previousMillis >= servomotor_interval) {

    servomotor_previousMillis = currentMillis;

  

for(servomotor_pos = 0; servomotor_pos < 180; servomotor_pos++)

  {

    servomotor.write(servomotor_pos);             //servomotor.write(숫자)는 서보모터가 위치할 각입니다. 숫자가 90이면 90도로 이동합니다.

    delay(15);

  }

  for(servomotor_pos = 180; servomotor_pos > 0; servomotor_pos--)

  {

    servomotor.write(servomotor_pos);            //결과적으로 이 코드는 0~179도, 179~0도로 왕복합니다.

    delay(15);

  }

}

}

 

감사합니다.

  • BASIC4MCU 작성글 SNS에 공유하기
  • 페이스북으로 보내기
  • 트위터로 보내기
  • 구글플러스로 보내기

댓글 0

조회수 5,616

등록된 댓글이 없습니다.

질문게시판HOME > 질문게시판 목록

MCU, AVR, 아두이노 등 전자공학에 관련된 질문을 무료회원가입 후 작성해주시면 전문가가 답변해드립니다.
ATMEGA128PWMLED초음파
아두이노AVR블루투스LCD
UART모터적외선ATMEGA
전체 스위치 센서
질문게시판 목록
제목 작성자 작성일 조회
공지 MCU, AVR, 아두이노 등 전자공학에 관련된 질문은 질문게시판에서만 작성 가능합니다. 스태프 19-01-15 19707
공지 사이트 이용 안내댓글[28] master 17-10-29 34156
질문 생애 첫 A 대표팀에 승선한 유럽파 미드필더 "우리홍" 홍현석의 올시즌 스탯.jpg 새글 rpHkJ847 08:39 0
질문 아두이노 리니어 제어 모듈 설계중입니다. 도와주세요 새글 갓비타 23-06-06 15
질문 dc모터 제어 관련 질문 드려요 ㅠㅠ!! 새글 dpwl 23-06-06 15
질문 pixy2 cam 을 이용한 색상인식 모터 제어 새글 가나다라 23-06-05 13
질문 안녕하세요 제품 품목 이름에 대해서 궁금합니다. 이미지새글첨부파일 알려주시면감사합니다 23-06-05 18
질문 Atmega128 온도센서로 led제어 질문드려요 이미지새글첨부파일 얍얍 23-06-05 23
질문 아구이노 코드를 atmega 128 코드로 변환 하고 싶습니다 ㅠㅠ 새글 기로롱 23-06-05 22
질문 atmega128 uart 질문입니다. bme12 23-06-05 25
질문 라즈베리파이에 풀 프레임 이미지센서 활용에 대한 질문이 있습니다. 이미지첨부파일 KYLO 23-06-04 19
질문 아두이노 시리얼 번호를 이용해 led 제어 wnion 23-06-04 21
질문 ATMEGA128 혹시 여기서 왜 인터럽트 기능이 안되는지 알 수 있나요 IEEE 23-06-04 34
질문 stm32f767을 이용해서 자이로가속도 센서의 값 받아오기 rlchwjswk 23-06-03 22
질문 아두이노 모터제어 관련해서 질문드립니다!댓글[1] 이미지첨부파일 아두이노어렵잖아 23-06-03 46
질문 atmega128 디지털조도센서 코드오류댓글[1] 이미지 까미 23-06-02 41
질문 atmega128 디지털 조도 센서댓글[1] 까미 23-06-02 41
질문 적외선리모콘으로 부저를제어 하는방법 질문입니다.댓글[4] Tell 23-06-02 24
질문 lora 무선 모듈에 관한 질문입니다.댓글[1] 로이스10 23-06-01 23
질문 적외선 송수신기 DC모터2개 제어 질문입니다.댓글[5] Tell 23-06-01 40
질문 스텝모터 제어 코드 질문댓글[5] pmh11 23-05-31 46
질문 초음파 센서를 이용한 인원 카운팅댓글[1] 초음파야 23-05-31 39
질문 모터 Hall 스위치 연결 문의댓글[1] 오후 23-05-31 26
질문 아두이노 lcd 문자 스크롤디스플레이 wnion 23-05-31 34
답변 답변글 답변 : 아두이노 lcd 문자 스크롤디스플레이댓글[1] master 23-05-31 34
질문 아두이노 타이머 인터럽트 미ㅏㄴㅇ 23-05-30 48
답변 답변글 답변 : 아두이노 타이머 인터럽트댓글[7] master 23-05-30 56
질문 THC-Soil Sensor with TTL 모듈 아두이노 센서값 받아오기댓글[1] ppiickle 23-05-30 34
질문 stm32 psd센서구동 질문댓글[2] 수포자 23-05-29 31
질문 앱인벤터 아두이노 보드 LCD 글씨 나타내기 질문댓글[7] 이미지 당찬병아리 23-05-29 52
게시물 검색

2022년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2021년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2020년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2019년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2018년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
Privacy Policy
MCU BASIC ⓒ 2020
모바일버전으로보기