This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
et:examples:sensor:mic [2015/11/25 08:48] – raivo.sell | et:examples:sensor:mic [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 8: | Line 8: | ||
===== Teooria ===== | ===== Teooria ===== | ||
- | + | [{{ :et: | |
- | [{{ : | + | |
===== Praktika ===== | ===== Praktika ===== | ||
Line 15: | Line 14: | ||
<code c> | <code c> | ||
- | // Kodulabori | + | // Kodulabori |
- | // LCD ekraanil kuvatakse | + | // LCD ekraanil kuvatakse |
+ | #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); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | } | ||
+ | } | ||
</ | </ |