NAVER

질문 아두이노 Serial함수 질문
비공개 조회수 1,524 작성일2018.10.19

저는 아두이노를 배우고 있는 학생입니다. 배우던 중 어려운 부분이  있어서 질문합니다.

 int note[] = {  1047,
     1174,
     1319,
     1397,
     1568,
     1760,
     1976,
     2093
 };
 void setup() {
  Serial.begin(9600);
  int elementCount = sizeof(note) / sizeof(note[0]);
  Serial.print("Number of Element in array = ");
  Serial.println(elementCount);

  for (int index = 0; index < elementCount; index++) {
   Serial.print("Index = ");
   Serial.println(index);
   Serial.print("note[index]=");
   Serial.println(note[index]);
   tone(9, note[index], 500);
   delay(750);
  }
 } void loop()
 {
 }




위 코드에서 Serial.print와 Serial.prinln이 의미하는 내용과 void setup()문 안에 있는 내용의 주석에 해당되는 내용을 알고싶습니다. 내공 100드리겠습니다.

프로필 사진

답변자님,

정보를 공유해 주세요.

1 개 답변
1번째 답변
프로필 사진
키트 박옥현
우주신
전기, 전자 공학 6위, 프로그래머 1위, 프로그래밍 22위 분야에서 활동
본인 입력 포함 정보


// MCU BASIC: https://www.basic4mcu.com
// DateTime : 2018-10-19 오후 2:50:55
// by Ok-Hyun Park
//
int note[]={1047,1174,1319,1397,1568,1760,1976,2093};
//
void setup(){
  Serial.begin(9600);
  int elementCount=sizeof(note)/sizeof(note[0]); // note 배열의 메모리크기 / 배열원소의크기 = 배열원소의갯수
  Serial.print("Number of Element in array="); Serial.println(elementCount); // 배열원소의갯수 출력
  //
  for(int index=0; index<elementCount; index++){
    Serial.print("Index=");       Serial.println(index);       // index 출력
    Serial.print("note[index]="); Serial.println(note[index]); // 배열[index] 내용 시리얼 출력
    tone(9,note[index],500);// 배열[index] 주파수 500ms 출력
    delay(750);// 무음 750ms 출력
  }
}
//
void loop(){ }
//
Serial.print() 문자로 출력
Serial.prinln() 문자로 출력 + 라인(lins)변경

1회만 동작시키기 위해서 setup() 함수에서 실행하고 있습니다.


// MCU BASIC: https://www.basic4mcu.com
// DateTime : 2018-10-19 오후 2:54:05
// by Ok-Hyun Park
//
int note[]={1047,1174,1319,1397,1568,1760,1976,2093};
//
void setup(){
  Serial.begin(9600);
}
//
void loop(){
  for(int index=0;i<8;i++){
    Serial.println(i); Serial.print("="); Serial.println(note[index]);  
    tone(9,note[index],500);
    delay(750);
  }
  delay(3000);
}

쓸데없는 것 빼버리고 계속해서 반복시키려면 이렇게 수정하면 되겠죠


추가문의는  https://www.basic4mcu.com


2018.10.19.

  • 채택

    질문자가 채택한 답변입니다.

도움이 되었다면 UP 눌러주세요!
UP이 많은 답변일수록 사용자들에게 더 많이 노출됩니다.