Music Pet Bottle
・音楽に合わせて怪しげに光るペットボトルを作ってみた。
・簡単にいえば、小型MP3プレイヤー用のミニアンプ付スピーカを500mLのペットボトルの中に入れただけだ。MP3プレイヤーは市販のもので、ミニジャックを装備した軽いものならよいのではないかと思う。(確かめてはいないが。)
・ペットボトルを怪しく光らせるために、RGBフルカラーLEDを組み込んである。このLEDは、アンプの出力の大きさの応じて発光する色が変化する。LEDを制御しているのは、PICマイコンPIC12F1822だ。このマイコンのAD変換入力にはアンプからの音声信号が入力される。その信号の大きさをプログラムで読み取って、青→緑→赤と点灯するLEDの色を変えるようになっている。
使用部品
PICマイコン PIC12F1822
パワーアンプIC HT82V739
RGBフルカラーLED OSTA5131A
カーボン抵抗器 150Ω 1/4W
積層セラミックコンデンサ 0.1uF, 1uF×2個
電解コンデンサ 47uF
電池ボックス 単三電池3本用
バッテリースナップ
可変抵抗器 スイッチ付き10kΩ Aカーブ つまみ付き
ICソケット 8PIN×2個
スピーカ
ステレオミニプラグ
各種配線材
ペットボトル 500mL
回路図
ファームウェア (XC8 compiler用ソースコード)
/*
* File: adc-rgb-led-12f1822.c
* Author: kaimunantai
*
* Created on 2013/03/16, 18:01
*/
#include <xc.h>
#define ledRed() ( RA0 ^= 1 )
#define ledGreen() ( RA5 ^= 1 )
#define ledBlue() ( RA4 ^= 1 )
#define ledRedOff() ( RA0 = 0 )
#define ledGreenOff() ( RA5 = 0 )
#define ledBlueOff() ( RA4 = 0 )
#define ledRedOn() ( RA0 = 1 )
#define ledGreenOn() ( RA5 = 1 )
#define ledBlueOn() ( RA4 = 1 )
__CONFIG(
FOSC_INTOSC & WDTE_OFF & PWRTE_ON & MCLRE_OFF & CP_OFF
& CPD_OFF & BOREN_ON & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF
);
__CONFIG(PLLEN_OFF & STVREN_ON & WRT_OFF & BORV_HI & LVP_OFF);
void wait(volatile unsigned long t)
// Delay
{
while(t-- > 0) NOP();
}
unsigned int adc10(unsigned int channel)
// channel : ADC channel
{
unsigned int dh, dl, d;
ADCON0 = (channel<<2) | 0b01; //0:unimp, , 0:GOnDone, 1:ADC enable
ADCON1 = 0b11000000; //1:Right jutified (10bit res.), 100:Fosc/4 ,0:Reserved, 00:AVDD=VREF
//ADC
wait(10);
GO_nDONE = 1;
while (GO_nDONE);
dh = ADRESH & 0b00000011;
dl = ADRESL & 0b11111111;
d = (dh<<8) | dl;
return d;
}
#define ADCPORT 2
int main(void)
{
unsigned int v, v0 = 508; // v0:no signal level
unsigned long delay = 0;
//Initialization
// OSCCON = 0b01101010; // PLL disable, 4MHz internal clock
OSCCON = 0b01111010; // PLL disable, 8MHz internal clock
GIE = 1;
//Interrupt enable
ANSELA = 0b00000100; //RA2 Analog port, others digital port
ADCON0 = 0b00001001; //0:unimp, 00010:AN2, 0:GOnDone, 1:ADC enable
ADCON1 = 0b11000000; //1:Right jutified (10bit res.), 100:Fosc/4 ,0:Reserved, 00:AVDD=VREF
CM1CON0 = 0x00; //Comparator disable
// 76543210
TRISA = 0b00001010;
//I/O Direction. RA1,3:input, RA0,2,4,5 : output
LATA
= 0b00000000; // PORTA Latch Settings
ledRedOff(); ledGreenOff(); ledBlueOff();
while(1){
v = adc10(ADCPORT);
if(v > v0 + 10) {
ledRedOn();
ledGreenOn();
ledBlueOn();
} else if (v > v0 + 8) {
ledRedOn();
ledGreenOff();
ledBlueOff();
} else if (v > v0 + 6 ) {
ledRedOff();
ledGreenOn();
ledBlueOff();
} else if (v > v0 + 4) {
ledRedOff();
ledGreenOff();
ledBlueOn();
} else if (v > v0) {
ledRedOff();
ledGreenOff();
if (delay < 2 ) {
ledBlueOn();
} else {
ledBlueOff();
}
} else {
ledRedOff();
ledGreenOff();
ledBlueOff();
}
if (delay > 100) {
delay = 0;
} else {
delay++;
}
}
return 0;
}