====== Audio laser show ====== ~~META:description abstract=Sound based laser show~~ {{tag>laser microcontroller audio lighting}} Sound based laser show ===== Features ===== * High and Mid controls 2 lissajouss motors * Low controls duty * Sens. adj. from 0.1 to 10 ===== Electronics ===== {{schematic>schematic.svg}} ===== Source code ===== #define F_CPU 20000000 // Trigger on PD1 // Output on OC0A (PD6) // Low on ADC0 / PC0 // Mid on ADC1 / PC1 // High on ADC2 / PC2 #define ENABLE Bit(PORTB).bit0 // Fan1 on OC0A / PD6 // Fan2 on OC0B / PD5 // Duty on OC2A / PB3 (cfl MOSI !) //global volatile uint8_t g_ch = 0; volatile float g_offset[3] = {-560, -560, -560}; volatile float g_coef[3] = {0.57, 0.57, 0.57}; //init void init(void) { // Inputs PORTB = 0x01; // Pull-up on PB0 // Outputs sbi(DDRD, PD5); // Fan2 sbi(DDRD, PD6); // Fan1 sbi(DDRB, PB3); // Duty //Timer 0 TCCR0A = 0x03; // Fast PWM TCCR0B = 0x01; // Presc. = 1 OCR0A = 0x00; // 0% OCR0B = 0x00; // 0% //Timer 2 TCCR2A = 0x03; // Fast PWM TCCR2B = 0x01; // Presc. = 1 OCR2A = 0x00; // 0% } // Interrupts SIGNAL(ADC_CONV) { uint8_t v; v = g_coef[g_ch] * (ADCW + g_offset[g_ch]); switch(g_ch) { case 0 : OCR0A = v; break; case 1 : OCR0B = v; break; case 2 : OCR2A = v; break; } g_ch = (g_ch >= 2) ? 0 : g_ch + 1; ADMUX = g_ch; } // Main int main(void) { init(); while(1) { if(ENABLE) { TCCR0A = 0xa3; TCCR2A = 0x83; }else{ TCCR0A = 0x03; TCCR2A = 0x03; } _delay_ms(100); } return 0; } ===== How to ===== ===== Manual =====