블로그 이미지
개발자로서 현장에서 일하면서 새로 접하는 기술들이나 알게된 정보 등을 정리하기 위한 블로그입니다. 운 좋게 미국에서 큰 회사들의 프로젝트에서 컬설턴트로 일하고 있어서 새로운 기술들을 접할 기회가 많이 있습니다. 미국의 IT 프로젝트에서 사용되는 툴들에 대해 많은 분들과 정보를 공유하고 싶습니다.
솔웅

최근에 받은 트랙백

글 보관함

calendar

        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  


Grew up like this in 4 days. :)





In a meanwhile, I've updated the source code.


/*
* For Automated Mung Bean Sprouts growing machine
*
* Watering every 2 hours
* play music when watering
*
 * Relay pin 12
* speaker pin 8
*
 * created 22 Jan 2017
 *
 * updated 24 Jan 2017
 * -Added one more song (Butterfly)
 * -Randomly select a song (Schoolbell or Butterfly)
 * -watering every an hour from every 2 hours.
 * -increase watering time (Schoolbell - play 3 times, Butterfly - play 2 times)
*
 *by Douglas Changsoo Park
*
 */
 
#include <SimpleTimer.h>
#include "pitches.h"
 
int relay = 12;
int melodyPin = 8;
 
SimpleTimer timer;
 
int schoolbell_melody[] = {
  NOTE_G4,  NOTE_G4,  NOTE_A4,  NOTE_A4,  NOTE_G4,  NOTE_G4,  NOTE_E4,  NOTE_G4,  NOTE_G4,  NOTE_E4,  NOTE_E4,  NOTE_D4,  0,
  NOTE_G4,  NOTE_G4,  NOTE_A4,  NOTE_A4,  NOTE_G4,  NOTE_G4,  NOTE_E4,  NOTE_G4,  NOTE_E4,  NOTE_D4,  NOTE_E4,  NOTE_C4,  0 };
 
int schoolbell_noteDurations[] = {  1,1,1,1,  1,1,2,  1,1,1,1,  3,1,  1,1,1,1,  1,1,2,  1,1,1,1,  3,1  };

int butterfly_melody[] = {
  NOTE_G4,NOTE_E4,NOTE_E4,NOTE_F4,NOTE_D4,NOTE_D4,NOTE_C4,NOTE_D4,NOTE_E4,NOTE_F4,NOTE_G4,NOTE_G4,NOTE_G4,
  NOTE_G4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_F4,NOTE_D4,NOTE_D4,NOTE_C4,NOTE_E4,NOTE_G4,NOTE_G4,NOTE_E4,NOTE_E4,NOTE_E4,0,
  NOTE_D4,NOTE_D4,NOTE_D4,NOTE_D4,NOTE_D4,NOTE_E4,NOTE_F4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_F4,NOTE_G4,
  NOTE_G4,NOTE_E4,NOTE_E4,NOTE_F4,NOTE_D4,NOTE_D4,NOTE_C4,NOTE_E4,NOTE_G4,NOTE_G4,NOTE_E4,NOTE_E4,NOTE_E4,0
};

int butterflyNoteDurations[] = {
  1,1,2,1,1,2, 1,1,1,1,1,1,2,  1,1,1,1,1,1,2, 1,1,1,1,1,1,3,1,
  1,1,1,1,1,1,2,1,1,1,1,1,1,2,  1,1,2,1,1,2,1,1,1,1,1,1,3,1
};

void setup() {
  // put your setup code here, to run once:
  pinMode(relay, OUTPUT);
 digitalWrite(relay, HIGH);
  //timer.setInterval(7200000, watering);
  timer.setInterval(3600000, watering);
  //timer.setInterval(25000, watering); // Test Mode
}
 
void loop() {
  // put your main code here, to run repeatedly:
  timer.run();
}
 
void watering() {
  digitalWrite(relay, LOW);
  int song = random(1,3);
  if(song == 1) {
    music_schoolBell();
    music_schoolBell();
    music_schoolBell();
  } else {
    music_butterfly();
    music_butterfly();
  }
  digitalWrite(relay, HIGH);
  noTone(8);
}
 
void music_schoolBell() {
    int size = sizeof(schoolbell_melody) / sizeof(int);
  for(int thisNote = 0; thisNote < size; thisNote++) {
      int noteDuration = 250 * schoolbell_noteDurations[thisNote];
      tone(melodyPin, schoolbell_melody[thisNote], noteDuration);
      int pauseBetweenNotes = noteDuration * 1.30;
      delay(pauseBetweenNotes);
      noTone(melodyPin);
  }
}

void music_butterfly(){
  int size = sizeof(butterfly_melody) / sizeof(int);
  for (int thisNote = 0; thisNote < size; thisNote++) {
      int noteDuration = 250 * butterflyNoteDurations[thisNote];
      tone(melodyPin, butterfly_melody[thisNote], noteDuration);
      int pauseBetweenNotes = noteDuration * 1.30;
      delay(pauseBetweenNotes);
      noTone(melodyPin);
  }
}


저작자 표시 비영리 동일 조건 변경 허락
신고

티스토리 툴바