Warning: Use of undefined constant archives - assumed 'archives' (this will throw an Error in a future version of PHP) in /home/stufimedia/public_html/berbagi/wp-content/themes/cordobo-green-park-2/archive.php on line 17

Warning: Use of undefined constant page - assumed 'page' (this will throw an Error in a future version of PHP) in /home/stufimedia/public_html/berbagi/wp-content/themes/cordobo-green-park-2/archive.php on line 17

Warning: A non-numeric value encountered in /home/stufimedia/public_html/berbagi/wp-content/themes/cordobo-green-park-2/archive.php on line 17

Warning: A non-numeric value encountered in /home/stufimedia/public_html/berbagi/wp-content/themes/cordobo-green-park-2/archive.php on line 17
class="post-160 post type-post status-publish format-standard hentry category-stumpino">

Contoh penggunaan rotary encoder

07/09/2013

#include <avr/io.h>

#define PIN_A (PINB&1)
#define PIN_B ((PINB>>1)&1)

int main(void){
uint8_t st0 = 0;
uint8_t st1 = 0;
uint8_t dir = 0;
uint8_t temp = 0;
uint8_t counter = 0;
DDRD = 0xFF;
DDRB = 0;
while(1){
if(dir == 0){
if(PIN_A & (!PIN_B)){
dir = 2;
}else if(PIN_B & (!PIN_A)){
dir = 4;
}else{
dir = 0;
}
}else if(dir == 2){
if(PIN_A & (!PIN_B)){
dir = 2;
}else if((!PIN_A) & (!PIN_B)){
counter–;
dir = 0;
}else{
dir = 0;
}
}else if(dir == 4){
if(PIN_B & (!PIN_A)){
dir = 4;
}else if((!PIN_A) & (!PIN_B)){
counter++;
dir = 0;
}else{
dir = 0;
}
}else if(PIN_B & PIN_A){
dir = 0;
}
PORTD = ~counter;
}
return 0;
}