ã§ã¯ãArduino ã使ã£ã¦ä¸çè´è¨ºå¨ http://swikis.ddo.jp/WorldStethoscope/2 ãä½ã£ã¦ããã¾ããä¸çè´è¨ºå¨ã¨ã¯ãã¢ããã°å ¥åã®é»å§ãå ã«å¨æ³¢æ°ãå¤åãããããªç©ã§ãããããã ãã ã¨å®ã¯ Arduino ã§å®ç¾ããã®ã¯è¶ ããããã§ããä¾ãã° http://todbot.com/blog/bionicarduino/ ã«ãã Theremin ã®ãµã³ãã«ãåãããããã§ããdigitalWrite() é¢æ°ã§å ¥åãããé»å§ãå ã« delayMicroseconds() ã§ã¦ã¨ã¤ãããããªããåºåä¿¡å·ã ON/OFF ããã ãã§ãã
ããããã®ã¾ã¾ã§ã¯ä¸çè´è¨ºå¨ã¨ãã¦ã¯ä½¿ãã¾ãããã¿ã¤ãã³ã°ãå³å¯ã§ã¯ãªãé³ããã¿ãã¤ã®ã¨ãå¨æ³¢æ°ã§ã¯ãªããæ³¢é·ãé»å§ã«æ¯ä¾ãã¦ããããã§ããå¨æ³¢æ°ã¨é»å§ãæ¯ä¾ããã¨ããã®ã¯ãé«ãé»å§ã§é«ãé³ãé³´ã£ãæ¹ãç´æçã ã¨ããé¿é¨ããã®ãã ãããªã®ã ããã¨æãã¾ãããå°éãã¦ãã®ã¾ã¾ä½ãã¾ãã以ä¸ã®ããã°ã©ã 㯠Analog 1 ãå ¥åãDigital 9 ãé³å£°åºåã«ãªã£ã¦ãã¾ãã5V - å ã»ã³ãµ - Analog1 - æµæ - GND ã®ããã«æ¥ç¶ããã¨ããã«ãã³ã¿ããã«éã¹ã¾ããããã¡ããä¸çè´è¨ºå¨ã¢ã¼ãã§ããã£ã¡ãåãã¾ãã
ä»å㯠Output Compare Register A ã¨ããã®ã使ã£ã¦ãããªã¹ã±ã¼ã« 32 ã®ã«ã¦ã³ã¿ã 4 å¨æåºå®ã§åãã¦ãã¾ããããã¨ã«ã¦ã³ã¿å¨æ㯠16MHz / 32 / 4 = 125KHz ã¨ãªãããããåºæºå¨æ³¢æ°ã¨ãã¦ã欲ããå¨æ³¢æ°ãä½ãåºãã¾ãã125KHz ãã説æãã«ããã®ã§ãããã åºæºå¨æ³¢æ°ã 10KHz ã§æ¬²ããå¨æ³¢æ°ã 4KHz ã ã¨ããã¨ã
- ã¢ã«ã´ãªãºã
- åæå¤:
- ä½åå¨æ³¢æ° := åºæºå¨æ³¢æ°
- ç®çå¨æ³¢æ° := é³´ããããå¨æ³¢æ° * 2 (ON/OFF ãåãæ¿ããã®ã§)
- ã¿ã¤ãçºç: ä½åå¨æ³¢æ° := ä½åå¨æ³¢æ° - ç®çå¨æ³¢æ°
- ä½åå¨æ³¢æ° < 0 ãªãä¸åä¼ã¿
- ä½åå¨æ³¢æ° >= 0 ãªã
- ãã°ã«
- ä½åå¨æ³¢æ° := åºæºå¨æ³¢æ° + ä½åå¨æ³¢æ°
- åæå¤:
- ä¾: 4KHz ã欲ããæã¯ã4KHz ã®åã® 8KHz ãç®çå¨æ³¢æ°ã¨ãã¦
- 10KHz + 0KHz - 8KHz = 2KHz å¾ ã¡
- 2KHz - 8KHz = -6KHz ON
- 10KHz + -6Hz - 8KHz = -4KHz OFF
- 10KHz + -4Hz - 8KHz = -2KHz ON
- 10KHz + -2Hz - 8KHz = 0KHz OFF
- 10KHz + 0Hz - 8KHz = 2KHz å¾ ã¡
- 2Hz - 8KHz = -6KHz ON
ã®ããã«ããã¨ã10Hz ã® 2/5 ããªãã¡ 4KHz ã®ç©å½¢æ³¢ã足ãç®ã¨å¼ãç®ã ãã§ä½ãäºãåºæ¥ã¾ããéä¸ã§æ³¢é·ãæ±ããªãã¦è¯ãã®ããã½ã§ããæé«ã§ã 5KHz åºããã°è¯ãã®ã§åºæºå¨æ³¢æ°ã¨ã㦠10KHz ããã°ååããã§ããããªããé³ãæ±ãã£ãã®ã§ãããã試ã㦠125KHz ã«ãã¾ãããããã§ãã¾ã å¤ãªé³ãæ··ããã¾ãããã«ãã¡ã¼ã¿ã¼ã§æ¸¬ãã¨å²ã¨ã¡ããã¨æã£ãéãå¨æ³¢æ°ãã¨ããã®ã§ããã§è¯ãã¨ããäºã«ãã¾ãã
ã©ãããããã ãææ°çã®éçºç°å¢ã§ã¯åãããArduino 0010 ã使ãã¾ããã
// World Stethoscope Clone // for Arduino 0010 #define PRESCALE 32 #define COUNTER_MAX 4 #define PRECISION 1024 #define FREQ_SIGNAL_MAX (5000L * 2) #define PIN_OUTPUT 9 #define PIN_INPUT 1 long SAMPLING_RATE = F_CPU / PRESCALE / COUNTER_MAX; long margin = SAMPLING_RATE; long frequency = FREQ_SIGNAL_MAX; long nextFrequency = FREQ_SIGNAL_MAX; char signal = 0; void setup() { pinMode(PIN_OUTPUT, OUTPUT); TCCR2A = 1 <<WGM21 | 0<<WGM20; // Clear Timer on Compare Match TCCR2B = 0<<WGM22 | 0<<CS22 | 1<<CS21 | 1<<CS20; // clk/32 prescale OCR2A = COUNTER_MAX - 1; // Output Compare Register A TIMSK2 = 1<<OCIE2A; // Timer/Counter2 Output Compare Match A Interrupt Enable TCNT2 = 0; // Reset Timer/Counter2 } ISR(TIMER2_COMPA_vect) { // Timer/Counter2 Overflow margin -= frequency; if (margin <= 0) { margin += SAMPLING_RATE; digitalWrite(PIN_OUTPUT, signal); // Output signal signal ^= 1; frequency = nextFrequency; } } void loop() { int inputValue = analogRead(PIN_INPUT) + 1; // 1 ... 1024 long freq = inputValue * FREQ_SIGNAL_MAX / PRECISION; nextFrequency = freq; }
追è¨
nekosan ããã®ããã° http://brown.ap.teacup.com/nekosan0/382.html ã§ç´¹ä»ãã¦é ãã¾ãããæãé£ããããã¾ããï¼ã§ãã½ã¼ã¹ãåãã件ã§ãããã¯ã¦ãªãã¤ã¢ãªã¼ã®ãã°ã®ããã§ãããåç¾æ¹æ³ãåããã¾ãããã¨ããããä¸ã§ã¯ TCCR2A ã®è¡ã® 1<< ã 1 << ã«å¤ããã¨ãªããã¾ãããä»ã«ã使ã£ã¦ãé¨åããã®ã«ããªãã§ããª???