This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
et:examples:sensor:encoder [2015/02/25 14:01] – raivo.sell | et:examples:sensor:encoder [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ~~PB~~ | + | < |
====== Kooder ====== | ====== Kooder ====== | ||
- | //Vajalikud teadmised: [HW] [[et: | + | //Vajalikud teadmised: |
+ | [HW] [[et: | ||
+ | [LIB] [[et: | ||
+ | [LIB] [[et: | ||
+ | [AVR] [[et: | ||
===== Teooria ===== | ===== Teooria ===== | ||
Line 41: | Line 45: | ||
#define NUM_ENCODERS 2 | #define NUM_ENCODERS 2 | ||
- | // Koodri | + | // Koodri |
#define ENCODER_TICKS (F_CPU / 8 / 256) | #define ENCODER_TICKS (F_CPU / 8 / 256) | ||
Line 66: | Line 70: | ||
// Katkestused | // Katkestused | ||
- | ISR(INT6_vect) | + | ISR(INT6_vect) { |
- | { | + | |
encoder_pulse(0); | encoder_pulse(0); | ||
} | } | ||
- | ISR(INT7_vect) | + | ISR(INT7_vect) { |
- | { | + | |
encoder_pulse(1); | encoder_pulse(1); | ||
} | } | ||
Line 80: | Line 82: | ||
void encoder_init(unsigned char index) | void encoder_init(unsigned char index) | ||
{ | { | ||
- | // Viigud sisendistamine väljundiks | + | // Viigu sisendiks seadistamine koos pull-up takistite lubamisega |
pin_setup_input_with_pullup(encoder_pins[index]); | pin_setup_input_with_pullup(encoder_pins[index]); | ||
Line 103: | Line 105: | ||
} | } | ||
- | // Valitud | + | // Valitud |
void encoder_reset_pulses(unsigned char index) | void encoder_reset_pulses(unsigned char index) | ||
{ | { | ||
Line 111: | Line 113: | ||
} | } | ||
- | // Koodri | + | // Koodri |
unsigned short encoder_get_pulses(unsigned char index) | unsigned short encoder_get_pulses(unsigned char index) | ||
{ | { | ||
Line 121: | Line 123: | ||
<code c> | <code c> | ||
- | // Kodulabori koodri kasutamise | + | // Kodulabori koodri kasutamise |
// LCD-le kuvatakse koodri pulsside arv | // LCD-le kuvatakse koodri pulsside arv | ||
#include < | #include < | ||
Line 135: | Line 137: | ||
char text[16]; | char text[16]; | ||
- | // Nupu seadmistamine | + | // Nupu seadistamine |
pin_setup_input_with_pullup(S2); | pin_setup_input_with_pullup(S2); | ||
Line 146: | Line 148: | ||
// LCD ekraani algseadistamine | // LCD ekraani algseadistamine | ||
lcd_gfx_init(); | lcd_gfx_init(); | ||
- | lcd_gfx_clear(); | + | lcd_gfx_clear(); |
- | lcd_gfx_backlight(true); | + | lcd_gfx_backlight(true); |
- | lcd_gfx_goto_char_xy(3, | + | lcd_gfx_goto_char_xy(3, |
lcd_gfx_write_string(" | lcd_gfx_write_string(" | ||
// Lõputu tsükkel | // Lõputu tsükkel | ||
- | while (true) | + | while (1) |
{ | { | ||
pulses = encoder_get_pulses(1); | pulses = encoder_get_pulses(1); | ||
// Teksti moodustamine. | // Teksti moodustamine. | ||
- | sprintf(text, | + | sprintf(text, |
lcd_gfx_goto_char_xy(0, | lcd_gfx_goto_char_xy(0, | ||
lcd_gfx_write_string(text); | lcd_gfx_write_string(text); | ||
- | // Nupp S2 alla vajutatud ? | + | // Nupp S2 alla vajutatud? |
if(button_read(S2)) | if(button_read(S2)) | ||
{ | { |