질문게시판 > 답변 : 아두이노 소프트웨어 시리얼 질문

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

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


BASIC4MCU | 질문게시판 | 답변 : 아두이노 소프트웨어 시리얼 질문

페이지 정보

작성자 master 작성일2019-01-15 10:36 조회26,043회 댓글5건

본문

	

아두이노 소프트웨어 시리얼을 이용해서 LED잔상시계를 만들고 있는데여.

 

ATMEGA328P가 2개인데 하나는 RTC와 블루투스 모듈이 연결되어있고 다른 하나는 LED와 연결되어있습니다.(RTC로 받은 시간 데이터를 LED를 이용하여 시계로 표현)

 

회로도는 위와 같습니다. 

 

프로그램은 대강 이렇게 만들었는데여.

 

RTC 연결부분

 

#include

#include "RTClib.h"

#include

SoftwareSerial mySerial(14,15);

RTC_DS1307 RTC;

int hh=0,mm=0,ss=0,RXdata=0;

 

void setup() {

  Serial.begin(9600);

  mySerial.begin(9600);

  Wire.begin();

  RTC.begin();

  RTC.adjust(DateTime(__DATE__, __TIME__));

}

 

void loop() {

  if(mySerial.available()){

    char r = mySerial.read();

    Serial.write(r);

  }

  DateTime now = RTC.now();

  hh=now.hour();

  mm=now.minute();

  ss=now.second();

 

  if(!RTC.isrunning()){

    Serial.println("RTC is NOT running!");

  }

  else{

    DateTime now = RTC.now();

    Serial.print(now.year(),DEC);

    Serial.print('/');

    Serial.print(now.month(),DEC);

    Serial.print('/');

    Serial.print(now.day(),DEC);

    Serial.print('/');

    Serial.print(now.hour(),DEC);

    Serial.print('/');

    Serial.print(now.minute(),DEC);

    Serial.print('/');

    Serial.print(now.second(),DEC);

    Serial.print('/');

  }

  delay(1000);

}

 

수신 부분 (LED시계표시 부분)

 

//#include

//#include

#include

#include "RTClib.h"

#include

SoftwareSerial mySerial(14,15);

#define PBS1 16

RTC_DS1307 RTC;

 

int _sec;

int _min;

int _hour;

 

int hour;

int minute;

int second;

 

volatile int col_no;

volatile unsigned int pos;

volatile unsigned long last_time;

volatile unsigned int one_column_time;

volatile bool int_enable = true;

volatile unsigned long duration;

unsigned long last_time_update = 0;

 

void ISR1() {

  unsigned long tme = micros();

  {

    duration = tme - last_time;

    one_column_time = ((float)duration / (float)col_no);

    pos = 0;

    last_time = tme;

    detachInterrupt(0);

    int_enable = false;

    return;

  }

}

 

void setup() {

  Serial.begin(9600);

  mySerial.begin(9600);

  Wire.begin();

  RTC.begin();

  RTC.adjust(DateTime(__DATE__, __TIME__));

  DDRD = B11111111;

  DDRB = B001111;

  DateTime now = RTC.now();

  hour = now.hour();

  minute = now.minute();

  second = now.second();

}

void loop() {

  int sri = digitalRead(PBS1);

  if (((micros() - last_time) > 30000) && (int_enable == false))

  {

    int_enable = true;

    attachInterrupt(0, ISR1, LOW);

  }

  unsigned long time_gap = micros() - last_time;

  pos = (float)time_gap / (float)one_column_time;

  pos = min(pos, col_no);

 

 

  if ((millis() - last_time_update) > 1000) {

    _hour = hour;

    _min = minute;

    _sec = second;

    if (_hour > 12) _hour -= 12;

    last_time_update = millis();

  }

  col_no = 60;

 

if (sri == LOW) {

 

  if (pos == _sec) {

    PORTD = B00000011;

    PORTB = B110000;

  }

  //PORTD = B11111111;

  //PORTB = B110111;

 

  if (pos == _min) {

    PORTD = B00000111;

    PORTB = B110000;

  }

  //PORTD = B11111111;

  //PORTB = B110111;

 

  if (pos == _hour * 5 + _min / 12) {

    PORTD = B00001111;

    PORTB = B110000;

  }

  //PORTD = B11111111;

  //PORTB = B110111;

  if ((millis() / 5) % 2 == 0)

  {

    PORTD = B11111101;

    PORTB = B110111;

  }

  else {

    PORTD = B11111111;

    PORTB = B111111;

  }

}

 

}

 

처음 제작하는 거라서 모르는 부분이 많네여;;;

 

//

 

 

// MCU BASIC: https://www.basic4mcu.com
// DateTime : 2019-01-15 오전 10:40:08
// by Ok-Hyun Park
//-------------------RTC 연결부분
#include <SoftwareSerial.h>
SoftwareSerial mySerial(14,15);
//
#include "RTClib.h"
#include <Wire.h>
RTC_DS1307 RTC;
//
int hh=0,mm=0,ss=0,RXdata=0;
//
void setup(){
  Serial.begin(9600);
  mySerial.begin(9600);
  Wire.begin();
  RTC.begin();
  RTC.adjust(DateTime(__DATE__,__TIME__));
}
//
void loop(){
  if(mySerial.available()){ char r=mySerial.read(); Serial.write(r); }
  DateTime now=RTC.now();
  hh=now.hour(); mm=now.minute(); ss=now.second();
  //
  if(!RTC.isrunning()){ Serial.println("RTC is NOT running!"); }
  else{
    DateTime now=RTC.now();
    Serial.print(now.year(),DEC);   Serial.print('/');
    Serial.print(now.month(),DEC);  Serial.print('/');
    Serial.print(now.day(),DEC);    Serial.print('/');
    Serial.print(now.hour(),DEC);   Serial.print('/');
    Serial.print(now.minute(),DEC); Serial.print('/');
    Serial.print(now.second(),DEC); Serial.print('/');
  }
  delay(1000);
}
//-------------------수신 부분(LED시계표시 부분)
//#include 
//#include 
#include <SoftwareSerial.h>
SoftwareSerial mySerial(14,15);
//
#include "RTClib.h"
#include <Wire.h>
RTC_DS1307 RTC;
//
#define PBS1 16
//
int _sec,_min,_hour;
int hour,minute,second;
//
volatile int col_no;
volatile unsigned int  pos;
volatile unsigned int  one_column_time;
volatile unsigned long last_time;
volatile unsigned long duration;
volatile unsigned long last_time_update=0;
volatile bool int_enable=true;
//
void ISR1(){
  unsigned long tme=micros();
  //
  duration=tme-last_time;
  one_column_time=((float)duration /(float)col_no);
  pos=0;
  last_time=tme;
  detachInterrupt(0);
  int_enable=false;
  return;
}
//
void setup(){
  Serial.begin(9600);
  mySerial.begin(9600);
  Wire.begin();
  RTC.begin();
  RTC.adjust(DateTime(__DATE__,__TIME__));
  //
  DDRD=B11111111DDRB=B001111;
  //
  DateTime now=RTC.now();
  hour=now.hour(); minute=now.minute(); second=now.second();
}
//
void loop(){
  int sri=digitalRead(PBS1);
  //
  if(((micros()-last_time)>30000)&&(int_enable==false)){
    int_enable=trueattachInterrupt(0,ISR1,LOW);
  }
  unsigned long time_gap=micros()-last_time;
  pos=(float)time_gap/(float)one_column_time;
  pos=min(pos,col_no);
  //
  if((millis()-last_time_update)>1000){
    _hour=hour_min=minute_sec=second;
    if(_hour>12)_hour-=12;
    last_time_update=millis();
  }
  col_no=60;
  if(sri==LOW){
    if(pos==_sec)           { PORTD=B00000011PORTB=B110000; } //PORTD=B11111111; PORTB=B110111;  
    if(pos==_min)           { PORTD=B00000111PORTB=B110000; } //PORTD=B11111111; PORTB=B110111;
    if(pos==_hour*5+_min/12){ PORTD=B00001111PORTB=B110000; } //PORTD=B11111111; PORTB=B110111;
    //
    if((millis()/5)%2==0){ PORTD=B11111101PORTB=B110111; }
    else                 { PORTD=B11111111PORTB=B111111; }
  }
}

 

잔상시계라면 두 개의 아두이노가 블루투스로 연결될까요?

회로도는 직접 연결되어 있군요

회전체에는 LED에 표시할 세그먼트 폰트도 있어야하고

원점센서 입력도 있어야하고

빠져있는 부분이 많이 보입니다.

 

웹검색해서 LED POV 예제를 찾아보세요

 

https://www.google.com/search?q=%EC%95%84%EB%91%90%EC%9D%B4%EB%85%B8+LED+POV&oq=%EC%95%84%EB%91%90%EC%9D%B4%EB%85%B8+LED+POV&aqs=chrome..69i57.4609j0j7&sourceid=chrome&ie=UTF-8 

 

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

댓글 5

조회수 26,043

hktsakura님의 댓글

hktsakura 작성일

시계는 아날로그 시계로 출력하고 원점센서는 포토트랜지스터를 사용합니다.

master님의 댓글

master 댓글의 댓글 작성일

원래 참고한 예제가 있지 않나요?
웹자료면 링크 첨부해보세요

hktsakura님의 댓글

hktsakura 댓글의 댓글 작성일

위 수신부분이 참고한 예제입니다. PBS1 16으로 지정한게 포토트랜지스터 부분입니다.

master님의 댓글

master 댓글의 댓글 작성일

웹주소는 없나요?

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

MCU, AVR, 아두이노 등 전자공학에 관련된 질문을 무료회원가입 후 작성해주시면 전문가가 답변해드립니다.
ATMEGA128PWMLED초음파
아두이노AVR블루투스LCD
UART모터적외선ATMEGA
전체 스위치 센서
질문게시판 목록
제목 작성자 작성일 조회
공지 MCU, AVR, 아두이노 등 전자공학에 관련된 질문은 질문게시판에서만 작성 가능합니다. 스태프 19-01-15 19704
공지 사이트 이용 안내댓글[28] master 17-10-29 34155
질문 아두이노 리니어 제어 모듈 설계중입니다. 도와주세요 새글 갓비타 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
질문 atmega128 led와 fan댓글[3] 이라 23-05-28 56
게시물 검색

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
모바일버전으로보기