이메일

구글 : kdj777ehdwns@gmail.com
네이버 : kdj777ehdwns@naver.com
epsckr2016.blogspot.com

2016년 9월 22일 목요일

[아두이노] 빛에따라 도,레,미,파,솔,라,시,도 출력



#define NOTE_C4 262 
#define NOTE_D4 294 
#define NOTE_E4 330 
#define NOTE_F4 349 
#define NOTE_G4 392 
#define NOTE_A4 440 
#define NOTE_B4 494
#define NOTE_C5 523 

int speakerSensor=8;
int noteDuration=100;

int cdsPin=0;
int cdsValue=0;
int noteValue=0;

void setup() {
  pinMode(speakerSensor, OUTPUT);
  Serial.begin(9600);
}


void loop() {
  cdsValue=analogRead(cdsPin);
  
  if(cdsValue<40)
  {
    noteValue=NOTE_C4;
  } else if(cdsValue>40 && cdsValue<65){
    noteValue=NOTE_D4;
  } else if(cdsValue>65 && cdsValue<90){
    noteValue=NOTE_E4;
  } else if(cdsValue>90 && cdsValue<115){
    noteValue=NOTE_F4;
  } else if(cdsValue>115 && cdsValue<140){
    noteValue=NOTE_G4;
  } else if(cdsValue>140 && cdsValue<165){
    noteValue=NOTE_A4;
  } else if(cdsValue>165 && cdsValue<190){
    noteValue=NOTE_B4;
  } else if(cdsValue<190){
     noteValue=NOTE_C5;
  }
       
  
    Serial.println(cdsValue);
    tone(speakerSensor, noteValue, noteDuration);
    delay(100);
    }


날짜 : 2016년 9월 22일

댓글 없음:

댓글 쓰기