This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
et:examples:sensor:mic [2015/11/25 08:38] – tekitatud raivo.sell | et:examples:sensor:mic [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Mikrofon ====== | ====== Mikrofon ====== | ||
+ | //Vajalikud teadmised: | ||
+ | [HW] [[et: | ||
+ | [AVR] [[et: | ||
+ | [LIB] [[et: | ||
+ | [LIB] [[et: | ||
+ | |||
+ | ===== Teooria ===== | ||
+ | [{{ : | ||
+ | |||
+ | ===== Praktika ===== | ||
+ | |||
+ | |||
+ | <code c> | ||
+ | // Kodulabori mikrofoni näidisprogramm | ||
+ | // LCD ekraanil kuvatakse helitugevuse graafik ja teatud helitugevusest süüdatakse LED | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | #define ADC_CHANNEL 12 | ||
+ | |||
+ | // Põhiprogramm | ||
+ | int main(void) | ||
+ | { | ||
+ | signed short mic; | ||
+ | BYTE n; | ||
+ | |||
+ | // LCD ekraani seadistamine | ||
+ | lcd_gfx_init(); | ||
+ | |||
+ | // ADC muunduri seadistamine | ||
+ | adc_init(ADC_REF_AVCC, | ||
+ | |||
+ | // LED-i viigu väljundiks seadmine | ||
+ | pin_setup_output(led_yellow); | ||
+ | pin_set(led_yellow); | ||
+ | |||
+ | // Ekraani päise joonistamine | ||
+ | FgColor = BLUE; | ||
+ | BkColor = YELLOW; | ||
+ | lcd_gfx_fillScreen(YELLOW); | ||
+ | lcd_gfx_goto_char_xy(6, | ||
+ | lcd_gfx_write_string(" | ||
+ | lcd_gfx_drawLine(0, | ||
+ | FgColor = RED; | ||
+ | |||
+ | // Lõputu tsükkel | ||
+ | while (1) | ||
+ | { | ||
+ | // Graafiku ala kustutamine | ||
+ | lcd_gfx_fillRect(0, | ||
+ | |||
+ | // Graafiku joonistamine. Ekraani laius on 128 pikslit. | ||
+ | for (n = 0; n <= 128; n++) | ||
+ | { | ||
+ | // Mikrofoni ADC kanali lugemine ja väärtuse sobivasse vahemikku teisendamine | ||
+ | mic = map(adc_get_value(ADC_CHANNEL), | ||
+ | |||
+ | // Punkti graafikule kandmine | ||
+ | lcd_gfx_drawPixel(n, | ||
+ | |||
+ | // LED-i süütamine, | ||
+ | if(mic > 30) | ||
+ | { | ||
+ | pin_toggle(led_yellow); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | } | ||
+ | } | ||
+ | |||
+ | </ |