※ブレッドボードチャレンジ2014[BC14-07,08]として開発中。
・4Bの鉛筆で、ちょっと濃いめに色を塗りつぶすと、その電気抵抗は数百kΩオーダーになる。
・これに電圧をかけてやれば、ちょっと変わった可変抵抗器として使える。
・電線が鉛筆の線を触る位置によって音の周波数が変化する回路を作ってみた。
・定番タイマIC LMC555をつかったものと、PICマイコンPIC12F1822を使ったものと2種類を試作した。
ミニブレッドボードを使用している。赤と黒の線は、バッテリースナップ。
タイマIC LMC555
炭素被膜固定抵抗器 1kΩ, 51Ω×2個
積層セラミックコンデンサ 0.1μF (104) , 2200pF (222)
圧電スピーカまたはインピーダンス8Ωのスピーカに100μFの電解コンデンサを直列接続したもの
ブレッドボード
ジャンパワイヤ
バッテリースナップと電池ボックス(単3電池2本用)
※写真では、回路図にはない0.01μFが555の5番PINに接続されている。
マイコン PIC12F1822
炭素被膜固定抵抗器 150Ω, 51Ω
みの虫クリップ 2個
圧電スピーカ
LED
ブレッドボード
ジャンパワイヤ
バッテリースナップと電池ボックス(単3電池3本用)
/** * File: adc-pencil-sounder-test-12f1822.c * Author: kaimu * * Created on 2014/11/03, 15:13 *//* * I/O Configration * Input: * AN1 (PIN6) : A/D convertor input * * Output: * RA2 (PIN5) : PWM Sound Output ( Piezo Speaker ) * RA5 (PIN2) : LED (1..ON, 0..OFF) */#include <xc.h>#define led() ( RA5 ^= 1 )#define ledOn() ( RA5 = 1 )#define ledOff() ( RA5 = 0 )#pragma config FOSC = INTOSC // Internal Oscillation#pragma config WDTE = OFF // Watch dog timer - OFF#pragma config PWRTE = ON // Power up Timer - ON#pragma config MCLRE = OFF // Master Clear - OFF , use RA5 as I/O#pragma config CP = OFF // Program Code protection - OFF#pragma config CPD = OFF // Data code protection - OFF#pragma config LVP = OFF // low voltage programming - OFF#pragma config BOREN = OFF // 4V brown out reset - OFF#pragma config CLKOUTEN = OFF // Clock out enabel - OFFvoid wait(volatile unsigned long t)// Delay{while(t-- > 0) NOP();
}void initIo(void){ /* Initialize I/O Port * */ OSCCON = 0b01101010; // PLL disable, 4MHz internal clock ANSELA = 0b00000010; //RA1 Analog port, others digital port ADCON0 = 0b00000101; //0:unimp, 00001:AN1, 0:GOnDone, 1:ADC enable ADCON1 = 0b01000000; //0:Left jutified (8bit res.), 100:Fosc/4 ,0:Reserved, 00:AVDD=VREF CM1CON0 = 0x00; //Comparator disable // 76543210
TRISA = 0b00001010; //I/O Direction. RA0,2,4,5 : output, RA1, 3 : Input
LATA = 0b00000000; // PORTA Latch Settings
}void initPwm(void){ //Timer2 settings for PWM standard mode PR2 = 0; // PWM Period = [(PR2) +1 ]*4*(1/FOSC)*(Timer2 Prescale value) T2CON = 0b00000010; //00 = Prescaler is 1, 01 = Prescaler is 4 10 = Prescaler is 16 11 = Prescaler is 64 APFCON &= ~(1<<CCP1SEL); //CCP1 function is on RA2 CCP1CON = 0b00001100; //PWM mode: P1A, P1C active-high; P1B, P1D active-high CCPR1L = 64; // PWM Duty Cycle (CCPR1L:CCP1CON<5:4>)*(1/FOSC)*(TMR2 Prescale Value) //Start PWM TMR2 = 0; TMR2ON = 1;}unsigned int adConv(void){ unsigned int d; //ADC wait(10); GO_nDONE = 1; while (GO_nDONE); d = ADRESH; return d;}void soundNote(unsigned char melody)// Melody format/* * (example) 0x12 ... first '1' is 'C', second '2' is length of sound (no sense) * first digit : 1 2 3 4 5 6 7 8 0 * sound name : C D E F G A B C rest */{ unsigned int freq[] = {0, 238, 212, 188, 178, 158, 141, 125, 118}; volatile unsigned int oto; oto = (int)(melody & 0xf0)>>4; PR2 = freq[oto];}void adcSound(void){ unsigned int adcdata; // A/D coverted data adcdata = adConv(); if ( adcdata >= 0x70 ) { soundNote(0x14); led(); } else if (adcdata > 0x60) { soundNote(0x24); led(); } else if (adcdata > 0x50) { soundNote(0x34); led(); } else if (adcdata > 0x40) { soundNote(0x44); led(); } else if (adcdata > 0x30) { soundNote(0x54); led(); } else if (adcdata > 0x20) { soundNote(0x64); led(); } else if (adcdata > 0x10) { soundNote(0x74); led(); } else if (adcdata > 0x04) { soundNote(0x84); led(); } else { soundNote(0x00); ledOff(); }}void startMessage(void) { volatile int i; ledOff(); for (i = 0; i < 3; i++ ) { led(); wait(3000); } ledOff();}void main(void){ initIo(); initPwm(); startMessage();// Starting Message while (1) { adcSound(); }}