질문게시판 > 아두이노 코드 질문!

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

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


BASIC4MCU | 질문게시판 | 아두이노 코드 질문!

페이지 정보

작성자 Lami 작성일2018-12-10 09:08 조회25,524회 댓글6건

본문

	

지식인에서 답변이 와서 회로를 고쳤더니 작동은 했지만, 시계를 만들어야 하는 코드가 작동하질 않았네요...

혹시 코드를 봐주실 수 있으신가요?

 

회로 사진을 첨부하고, 코드는 대충 지금 있는게 이럽니다

 

/*

 ###  simplest ever Arduino UNO digital clock  ###

 

 This clock needs only a 1602 LCD 2X16 and 2 push buttons 

 

 No Potentiometer for contrast, no resistors for pull-up or backlight !!!!

 

 * The simplest clock ever made with a Arduino UNO *    

 

 Button Functions:

 

 - short stroke on one of the buttons put Backlight on for 30 s

 

 Time settings

 - Press on H increments the Hours

 - Press on M increments the Minutes and resets the seconds

*/

 

 

#include "LiquidCrystal.h"

 

// This defines the LCD wiring to the DIGITALpins

const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

 

// Digital LCD Constrast setting

int cs=9;// pin 9 for contrast PWM

const int contrast = 100;// default contrast

 

// initial Time display is 12:59:45 PM

int h=12;

int m=59;

int s=45;

int flag=1; //PM

 

// Time Set Buttons

int button1;

int button2;

 

// Pins definition for Time Set Buttons

int hs=0;// pin 0 for Hours Setting

int ms=1;// pin 1 for Minutes Setting

 

// Backlight Time Out 

const int Time_light=150;

int bl_TO=Time_light;// Backlight Time-Out

int bl=10; // Backlight pin

const int backlight=120; // no more then 7mA !!!

 

// For accurate Time reading, use Arduino Real Time Clock and not just delay()

static uint32_t last_time, now = 0; // RTC

 

 

void setup()

{

  lcd.begin(16,2);

  pinMode(hs,INPUT_PULLUP);// avoid external Pullup resistors for Button 1

  pinMode(ms,INPUT_PULLUP);// and Button 2

  analogWrite(cs,contrast);// Adjust Contrast VO

  analogWrite(bl,backlight);// Turn on Backlight

  now=millis(); // read RTC initial value  

}

 

 

void loop()

  lcd.begin(16,2);// every second

// Update LCD Display

// Print TIME in Hour, Min, Sec + AM/PM

 lcd.setCursor(0,0);

 lcd.print("Time ");

 if(h<10)lcd.print("0");// always 2 digits

 lcd.print(h);

 lcd.print(":");

 if(m<10)lcd.print("0");

 lcd.print(m);

 lcd.print(":");

 if(s<10)lcd.print("0");

 lcd.print(s);

 

 if(flag==0) lcd.print(" AM");

 if(flag==1) lcd.print(" PM");

 

 lcd.setCursor(0,1);// for Line 2

 lcd.print("Precision clock");

 

 

// improved replacement of delay(1000) 

// Much better accuracy, no more dependant of loop execution time

 

for ( int i=0 ;i<5 ;i++)// make 5 time 200ms loop, for faster Button response

{

 

  while ((now-last_time)<200) //delay200ms

  { 

    now=millis();

  }

 // inner 200ms loop

 last_time=now; // prepare for next loop 

 

 // read Setting Buttons

 button1=digitalRead(hs);// Read Buttons

 button2=digitalRead(ms);

 

 //Backlight time out 

 bl_TO--;

 if(bl_TO==0)

 {

  analogWrite(bl,0);// Backlight OFF

  bl_TO++;

 }

 

 // Hit any to activate Backlight 

 if(  ((button1==0)|(button2==0)) & (bl_TO==1)  )

 {

  bl_TO=Time_light;

  analogWrite(bl,backlight);

  // wait until Button released

  while ((button1==0)|(button2==0))

  {

   button1=digitalRead(hs);// Read Buttons

   button2=digitalRead(ms);

  }

 }

 else

 // Process Button 1 or Button 2 when hit while Backlight on 

 {

  if(button1==0){

   h=h+1;

   bl_TO=Time_light;

   analogWrite(bl,backlight);

  }

 

 if(button2==0){

  s=0;

  m=m+1;

  bl_TO=Time_light;

  analogWrite(bl,backlight);

  }

 

/* ---- manage seconds, minutes, hours am/pm overflow ----*/

 if(s==60){

  s=0;

  m=m+1;

 }

 if(m==60)

 {

  m=0;

  h=h+1;

 }

 if(h==13)

 {

  h=1;

  flag=flag+1;

  if(flag==2)flag=0;

 }

 

 

 if((button1==0)|(button2==0))// Update display if time set button pressed

 {

  // Update LCD Display

  // Print TIME in Hour, Min, Sec + AM/PM

  lcd.setCursor(0,0);

  lcd.print("Time ");

  if(h<10)lcd.print("0");// always 2 digits

  lcd.print(h);

  lcd.print(":");

  if(m<10)lcd.print("0");

  lcd.print(m);

  lcd.print(":");

  if(s<10)lcd.print("0");

  lcd.print(s);

 

  if(flag==0) lcd.print(" AM");

  if(flag==1) lcd.print(" PM");

 

  lcd.setCursor(0,1);// for Line 2

  lcd.print("Precision clock");

 }

 

 

 } // end if else

}// end for

 

 

 

// outer 1000ms loop

 

 s=s+1; //increment sec. counting

    

    

// ---- manage seconds, minutes, hours am/pm overflow ----

 if(s==60){

  s=0;

  m=m+1;

 }

 if(m==60)

 {

  m=0;

  h=h+1;

 }

 if(h==13)

 {

  h=1;

  flag=flag+1;

  if(flag==2)flag=0;

 } 

 

 

 

// Loop end

}

 

감사합니다!

Drop here!
G
M
T
Detect languageAfrikaansAlbanianAmharicArabicArmenianAzerbaijaniBasqueBelarusianBengaliBosnianBulgarianCatalanCebuanoChichewaChinese (Simplified)Chinese (Traditional)CorsicanCroatianCzechDanishDutchEnglishEsperantoEstonianFilipinoFinnishFrenchFrisianGalicianGeorgianGermanGreekGujaratiHaitian CreoleHausaHawaiianHebrewHindiHmongHungarianIcelandicIgboIndonesianIrishItalianJapaneseJavaneseKannadaKazakhKhmerKoreanKurdishKyrgyzLaoLatinLatvianLithuanianLuxembourgishMacedonianMalagasyMalayMalayalamMalteseMaoriMarathiMongolianMyanmar (Burmese)NepaliNorwegianPashtoPersianPolishPortuguesePunjabiRomanianRussianSamoanScots GaelicSerbianSesothoShonaSindhiSinhalaSlovakSlovenianSomaliSpanishSundaneseSwahiliSwedishTajikTamilTeluguThaiTurkishUkrainianUrduUzbekVietnameseWelshXhosaYiddishYorubaZulu
AfrikaansAlbanianAmharicArabicArmenianAzerbaijaniBasqueBelarusianBengaliBosnianBulgarianCatalanCebuanoChichewaChinese (Simplified)Chinese (Traditional)CorsicanCroatianCzechDanishDutchEnglishEsperantoEstonianFilipinoFinnishFrenchFrisianGalicianGeorgianGermanGreekGujaratiHaitian CreoleHausaHawaiianHebrewHindiHmongHungarianIcelandicIgboIndonesianIrishItalianJapaneseJavaneseKannadaKazakhKhmerKoreanKurdishKyrgyzLaoLatinLatvianLithuanianLuxembourgishMacedonianMalagasyMalayMalayalamMalteseMaoriMarathiMongolianMyanmar (Burmese)NepaliNorwegianPashtoPersianPolishPortuguesePunjabiRomanianRussianSamoanScots GaelicSerbianSesothoShonaSindhiSinhalaSlovakSlovenianSomaliSpanishSundaneseSwahiliSwedishTajikTamilTeluguThaiTurkishUkrainianUrduUzbekVietnameseWelshXhosaYiddishYorubaZulu
Text-to-speech function is limited to 200 characters
  • BASIC4MCU 작성글 SNS에 공유하기
  • 페이스북으로 보내기
  • 트위터로 보내기
  • 구글플러스로 보내기

댓글 6

조회수 25,524

master님의 댓글

master 작성일

const int hs=0,ms=1;
가급적 D0,D1핀은 사용하지 않는 것이 좋습니다.
남는핀이 있으면 변경하세요
const int hs=11,ms=12;
11번핀과 12번핀이 좋겠군요

master님의 댓글

master 작성일

LCD 표시는 되는데
자동으로 시간 증가가 안된다는 건가요?
스위치로 시간 증가가 안된다는 건가요?

Lami님의 댓글

Lami 댓글의 댓글 작성일

늦늦게 확인해서 정말 죄송합니다!
작동하지 않는다는게, 저기 올린 사진처럼 아무것도 LCD에 뜨지 않는다는 소리에요!
주신 코드를 넣어봐도 위의 사진처럼 아무것도 안 뜨네요...

master님의 댓글

master 댓글의 댓글 작성일

rs=2
질문 사진은 이 핀 연결이 빠져있습니다.

Lami님의 댓글

Lami 댓글의 댓글 작성일

호에에에 감사합니다!
죄송하지만 하나만 더 여쭤볼게유
  while(millis()-blTime>=3000){ // 2초 후
    analogWrite(bl,0);          // Backlight OFF
  }
이 코딩은 넣은 이유가 뭔가요? 초보자라 잘 모르겠지만 이 코드 때문에 2초가 지나면 멈추더라고요...
감사합니다!

master님의 댓글

master 댓글의 댓글 작성일

질문 소스는 아니군요?
  if(millis()-blTime>=3000){ // 2초 후
    analogWrite(bl,0);          // Backlight OFF
  }
해당 코드만 보면 위처럼 수정하면 됩니다.

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

MCU, AVR, 아두이노 등 전자공학에 관련된 질문을 무료회원가입 후 작성해주시면 전문가가 답변해드립니다.
ATMEGA128PWMLED초음파
아두이노AVR블루투스LCD
UART모터적외선ATMEGA
전체 스위치 센서
질문게시판 목록
제목 작성자 작성일 조회
공지 MCU, AVR, 아두이노 등 전자공학에 관련된 질문은 질문게시판에서만 작성 가능합니다. 스태프 19-01-15 19813
공지 사이트 이용 안내댓글[28] master 17-10-29 34162
질문 압력센서에 따른 진동모터를 버튼으로 제어 회로도 질문 새글 도와주세용용 23-06-07 18
질문 아두이노 리니어 제어 모듈 설계중입니다. 도와주세요 새글 갓비타 23-06-06 17
답변 답변글 답변 : 아두이노 리니어 제어 모듈 설계중입니다. 도와주세요 새글 master 23-06-07 13
질문 dc모터 제어 관련 질문 드려요 ㅠㅠ!!댓글[2] 새글 dpwl 23-06-06 27
답변 답변글 답변 : dc모터 제어 관련 질문 드려요 ㅠㅠ!! 새글 master 23-06-07 13
질문 pixy2 cam 을 이용한 색상인식 모터 제어댓글[1] 가나다라 23-06-05 14
질문 안녕하세요 제품 품목 이름에 대해서 궁금합니다. 이미지첨부파일 알려주시면감사합니다 23-06-05 19
질문 Atmega128 온도센서로 led제어 질문드려요댓글[1] 이미지첨부파일 얍얍 23-06-05 27
질문 아구이노 코드를 atmega 128 코드로 변환 하고 싶습니다 ㅠㅠ댓글[1] 기로롱 23-06-05 26
질문 atmega128 uart 질문입니다.댓글[1] bme12 23-06-05 32
질문 라즈베리파이에 풀 프레임 이미지센서 활용에 대한 질문이 있습니다.댓글[1] 이미지첨부파일 KYLO 23-06-04 21
질문 아두이노 시리얼 번호를 이용해 led 제어 wnion 23-06-04 22
답변 답변글 답변 : 아두이노 시리얼 번호를 이용해 led 제어 새글 master 23-06-07 11
질문 ATMEGA128 혹시 여기서 왜 인터럽트 기능이 안되는지 알 수 있나요댓글[1] IEEE 23-06-04 35
질문 stm32f767을 이용해서 자이로가속도 센서의 값 받아오기댓글[1] rlchwjswk 23-06-03 24
질문 아두이노 모터제어 관련해서 질문드립니다!댓글[1] 이미지첨부파일 아두이노어렵잖아 23-06-03 47
질문 atmega128 디지털조도센서 코드오류댓글[1] 이미지 까미 23-06-02 41
질문 atmega128 디지털 조도 센서댓글[1] 까미 23-06-02 43
질문 적외선리모콘으로 부저를제어 하는방법 질문입니다.댓글[4] Tell 23-06-02 27
질문 lora 무선 모듈에 관한 질문입니다.댓글[1] 로이스10 23-06-01 24
질문 적외선 송수신기 DC모터2개 제어 질문입니다.댓글[5] Tell 23-06-01 40
질문 스텝모터 제어 코드 질문댓글[6] pmh11 23-05-31 49
질문 초음파 센서를 이용한 인원 카운팅댓글[1] 초음파야 23-05-31 41
질문 모터 Hall 스위치 연결 문의댓글[1] 오후 23-05-31 29
질문 아두이노 lcd 문자 스크롤디스플레이 wnion 23-05-31 38
답변 답변글 답변 : 아두이노 lcd 문자 스크롤디스플레이댓글[1] master 23-05-31 36
질문 아두이노 타이머 인터럽트 미ㅏㄴㅇ 23-05-30 48
답변 답변글 답변 : 아두이노 타이머 인터럽트댓글[8] master 23-05-30 61
게시물 검색

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