본문 바로가기

Embedded/Arduino

lilyPad-v211025

Leah Buechley : Ted Talk

https://www.ted.com/talks/leah_buechley_how_to_sketch_with_electronics?language=ko 

 

레아 뷰크리(Leah Buechley): 전자장치로 "스케치"하기

전자장치를 디자인하는 것은 보통 꽤나 번거롭고 비용이 많이 든다 -- 최소한 레아 뷰크리와 그녀의 MIT 팀이 전자장치를 종이와 펜처럼 다룰 수 있는 도구를 개발하기 전까지는 그랬다. TEDYouth 20

www.ted.com

 

Instructables 에서 lilypad 사용하기

https://c11.kr/t845

 

Google Docs - 온라인에서 문서를 작성하고 수정할 수 있으며 무료입니다.

하나의 계정으로 모든 Google 서비스를 문서로 이동하려면 로그인하세요.

accounts.google.com

피에조 스피커 테스트

#define NOTE_C4  262
#define NOTE_G3  196
#define NOTE_A3  220
#define NOTE_B3  247
#define NOTE_C4  262


// notes in the melody:
int melody[] = {
  NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  4, 8, 8, 4, 4, 4, 4, 4
};

void setup() {
  // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 8; thisNote++) {

    // to calculate the note duration, take one second
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000 / noteDurations[thisNote];
    tone(2, melody[thisNote], noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(2);
  }
}

void loop() {
  // no need to repeat the melody.
}

소리가 나는 동안 LED 켜기

#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 PIEZO_PIN 2
 
//notes in the melody:
int melody[] = {
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_E4,
  0,
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_E4,
  0,
  NOTE_A4, NOTE_G4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_E4,  
};
 
// note durations: 4 = quarter note, 8 = eighth note, etc
int noteDurations[] = {
  2, 2, 4, 4, 4, 8, 4, 8, 4,
  4, 4, 4, 4, 4, 8, 4, 8, 4,
  4, 4, 4, 4, 4, 8, 4, 8, 4, 4, 4, 2,
  2, 
  2, 2, 4, 4, 4, 8, 4, 8, 4,
  4, 4, 4, 4, 4, 8, 4, 8, 4,
  4, 4, 4, 4, 4, 8, 4, 8, 4, 4, 4, 2, 
  2, 
  2, 2, 4, 4, 4, 8, 4, 8, 4,
  4, 4, 4, 4, 4, 8, 4, 8, 4,
  4, 4, 4, 4, 4, 8, 4, 8, 4, 4, 4, 2, 
};
 
void setup(){
  pinMode(3, OUTPUT);
  digitalWrite(3,HIGH);
  for (int thisNote = 0; thisNote < sizeof(melody) / sizeof(melody[0]); thisNote++) {
    int noteDuration = 1000/noteDurations[thisNote];
    tone(PIEZO_PIN, melody[thisNote],noteDuration);
 
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    
    noTone(PIEZO_PIN); 
  }
  digitalWrite(3,LOW);
}
 
void loop()
{
}

 

아기상어 + LED 깜빡이기

const int tonePin = 2;

unsigned long blink_previousMillis = 0;
unsigned long blink_interval = 100;
int blink_state = LOW;
 
#define NOTE_C4  262
#define NOTE_D4  294
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_G4  392
#define NOTE_A4  440
 
//notes in the melody:
int melody[] = {
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_E4,
  0,
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_E4,
  0,
  NOTE_A4, NOTE_G4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_E4,  
};
 
// note durations: 4 = quarter note, 8 = eighth note, etc
int noteDurations[] = {
  2, 2, 4, 4, 4, 8, 4, 8, 4,
  4, 4, 4, 4, 4, 8, 4, 8, 4,
  4, 4, 4, 4, 4, 8, 4, 8, 4, 4, 4, 2,
  2, 
  2, 2, 4, 4, 4, 8, 4, 8, 4,
  4, 4, 4, 4, 4, 8, 4, 8, 4,
  4, 4, 4, 4, 4, 8, 4, 8, 4, 4, 4, 2, 
  2, 
  2, 2, 4, 4, 4, 8, 4, 8, 4,
  4, 4, 4, 4, 4, 8, 4, 8, 4,
  4, 4, 4, 4, 4, 8, 4, 8, 4, 4, 4, 2, 
};
 
 
unsigned long previousMillis = 0;
unsigned long currentMillis;
 
boolean outputTone = false;                // Records current state
 
int melodyLength = sizeof(melody) / sizeof(melody[0]);
int melodyIndex = 0;
void setup() {
  pinMode(3,OUTPUT);
}
void loop() {
  currentMillis = millis();
  PlayMelody();
  if (currentMillis - blink_previousMillis >= blink_interval) {
  	blink_previousMillis = currentMillis;
    if(blink_state == HIGH)        
    	blink_state = LOW;
    else
    	blink_state = HIGH;
    digitalWrite(3, blink_state);
  }
}
void PlayMelody() {
  if (outputTone) {
    if (currentMillis - previousMillis >= (1000/noteDurations[melodyIndex])) {
      previousMillis = currentMillis;
      noTone(tonePin);
      outputTone = false;
      melodyIndex = melodyIndex + 1;
      if (melodyIndex >= melodyLength) {
        melodyIndex = 0;
      }
    }
  } else { //최초로 outputTone이 false로 시작
    if (currentMillis - previousMillis >= (300/noteDurations[melodyIndex])) {
      previousMillis = currentMillis;
      tone(tonePin, melody[melodyIndex], 1000/noteDurations[melodyIndex]);
      outputTone = true;
    }
  }
}

 

아기상어 + FADE

const int tonePin = 2;

unsigned long fade_previousMillis = 0;
unsigned long fade_interval = 20;
int pwm_value = 0;
int pwm_signal = 1;
 
#define NOTE_C4  262
#define NOTE_D4  294
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_G4  392
#define NOTE_A4  440
 
//notes in the melody:
int melody[] = {
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_E4,
  0,
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_E4,
  0,
  NOTE_A4, NOTE_G4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4,
  NOTE_C4, NOTE_D4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_E4,  
};
 
// note durations: 4 = quarter note, 8 = eighth note, etc
int noteDurations[] = {
  2, 2, 4, 4, 4, 8, 4, 8, 4,
  4, 4, 4, 4, 4, 8, 4, 8, 4,
  4, 4, 4, 4, 4, 8, 4, 8, 4, 4, 4, 2,
  2, 
  2, 2, 4, 4, 4, 8, 4, 8, 4,
  4, 4, 4, 4, 4, 8, 4, 8, 4,
  4, 4, 4, 4, 4, 8, 4, 8, 4, 4, 4, 2, 
  2, 
  2, 2, 4, 4, 4, 8, 4, 8, 4,
  4, 4, 4, 4, 4, 8, 4, 8, 4,
  4, 4, 4, 4, 4, 8, 4, 8, 4, 4, 4, 2, 
};
 
 
unsigned long previousMillis = 0;
unsigned long currentMillis;
 
boolean outputTone = false;                // Records current state
 
int melodyLength = sizeof(melody) / sizeof(melody[0]);
int melodyIndex = 0;
void setup() {
  pinMode(3,OUTPUT);
  Serial.begin(9600);
}
void loop() {
  currentMillis = millis();
  PlayMelody();
  if (currentMillis - fade_previousMillis >= fade_interval) {
      fade_previousMillis = currentMillis;
      analogWrite(3, pwm_value);
      if(pwm_value ==255 && pwm_signal == 1){
        pwm_signal = -1;          
      }
      else if(pwm_value == 0 && pwm_signal ==-1){
        pwm_signal = 1;          
      }
      pwm_value += (pwm_signal*5);
      Serial.println(pwm_value);
  }
}
void PlayMelody() {
  if (outputTone) {
    if (currentMillis - previousMillis >= (1000/noteDurations[melodyIndex])) {
      previousMillis = currentMillis;
      noTone(tonePin);
      outputTone = false;
      melodyIndex = melodyIndex + 1;
      if (melodyIndex >= melodyLength) {
        melodyIndex = 0;
      }
    }
  } else { //최초로 outputTone이 false로 시작
    if (currentMillis - previousMillis >= (300/noteDurations[melodyIndex])) {
      previousMillis = currentMillis;
      tone(tonePin, melody[melodyIndex], 1000/noteDurations[melodyIndex]);
      outputTone = true;
    }
  }
}

'Embedded > Arduino' 카테고리의 다른 글

lilyPad-v211026 #2  (0) 2021.10.26
lilyPad-v211026  (0) 2021.10.26
Arduino-v211022  (0) 2021.10.22
Arduino-v211021  (0) 2021.10.21
Arduino-v211020  (0) 2021.10.20