This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
en:examples:sensor:mic [2015/12/28 13:38] – created kaupo.raid | en:examples:sensor:mic [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
- | //Vajalikud teadmised: | + | //Necessary knowledge: |
- | [HW] [[et: | + | [HW] [[en: |
[AVR] [[et: | [AVR] [[et: | ||
- | [LIB] [[et: | + | [LIB] [[en: |
- | [LIB] [[et: | + | [LIB] [[en: |
- | ===== Teooria | + | ===== Theory |
- | [{{ :et: | + | [{{ :en: |
- | ===== Praktika | + | ===== Practice |
<code c> | <code c> | ||
- | // Kodulabori mikrofoni näidisprogramm | + | // Homelab microphone example |
- | // LCD ekraanil kuvatakse helitugevuse graafik ja teatud helitugevusest süüdatakse LED | + | // Microphone sound level graph is shown on LCD and when sound level exceeds threshold an led lights up. |
#include < | #include < | ||
#include < | #include < | ||
Line 24: | Line 24: | ||
#define ADC_CHANNEL 12 | #define ADC_CHANNEL 12 | ||
- | // Põhiprogramm | + | // Main program |
int main(void) | int main(void) | ||
{ | { | ||
Line 30: | Line 30: | ||
BYTE n; | BYTE n; | ||
- | // LCD ekraani seadistamine | + | // LCD setup function |
lcd_gfx_init(); | lcd_gfx_init(); | ||
Line 36: | Line 36: | ||
adc_init(ADC_REF_AVCC, | adc_init(ADC_REF_AVCC, | ||
- | // LED-i viigu väljundiks seadmine | + | // Set LED pin as output |
pin_setup_output(led_yellow); | pin_setup_output(led_yellow); | ||
pin_set(led_yellow); | pin_set(led_yellow); | ||
- | // Ekraani päise joonistamine | + | // LCD background draw |
FgColor = BLUE; | FgColor = BLUE; | ||
BkColor = YELLOW; | BkColor = YELLOW; | ||
Line 49: | Line 49: | ||
FgColor = RED; | FgColor = RED; | ||
- | // Lõputu tsükkel | + | // Infinite loop |
while (1) | while (1) | ||
{ | { | ||
- | // Graafiku ala kustutamine | + | // Clear graph area from LCD |
lcd_gfx_fillRect(0, | lcd_gfx_fillRect(0, | ||
- | // Graafiku joonistamine. Ekraani laius on 128 pikslit. | + | // Drawing the graph on LCD. Width of LCD is 128 pixels. |
for (n = 0; n <= 128; n++) | for (n = 0; n <= 128; n++) | ||
{ | { | ||
- | // Mikrofoni | + | // Microphone |
mic = map(adc_get_value(ADC_CHANNEL), | mic = map(adc_get_value(ADC_CHANNEL), | ||
- | // Punkti graafikule kandmine | + | // Draw value on graph as dot |
lcd_gfx_drawPixel(n, | lcd_gfx_drawPixel(n, | ||
- | // LED-i süütamine, | + | // Light up LED if value exceeds threshold (30) |
if(mic > 30) | if(mic > 30) | ||
{ | { |