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/26 13:10] – 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 ====== | ||
Line 44: | Line 44: | ||
// Koodrite arv | // Koodrite arv | ||
#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 81: | 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 104: | Line 105: | ||
} | } | ||
- | // Valitud | + | // Valitud |
void encoder_reset_pulses(unsigned char index) | void encoder_reset_pulses(unsigned char index) | ||
{ | { | ||
Line 112: | Line 113: | ||
} | } | ||
- | // Koodri | + | // Koodri |
unsigned short encoder_get_pulses(unsigned char index) | unsigned short encoder_get_pulses(unsigned char index) | ||
{ | { | ||
Line 136: | 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 153: | Line 154: | ||
// 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)) | ||
{ | { |