Last active
December 13, 2015 21:28
-
-
Save Miceuz/4977105 to your computer and use it in GitHub Desktop.
Some arduino / avr code to read a rotary encoder and drive a single 7 segment display.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setup() { | |
DDRD = 0xFF; | |
PORTD = 1; | |
pinMode(8, INPUT); | |
pinMode(9, INPUT); | |
} | |
byte digits[] = { | |
0b00000011,//0 | |
0b11110011,//1 | |
0b10000101,//2 | |
0b00001101,//3 | |
0b00111001,//4 | |
0b01001001,//5 | |
0b01000001,//6 | |
0b00011111,//7 | |
0b00000001,//8 | |
0b00001001,//9 | |
}; | |
byte t = 0; | |
byte lastVal = 0; | |
byte b = 1; | |
byte digit = 0; | |
void loop() { | |
PORTD = digits[digit] | ~(0x01 << b); | |
b++; | |
if(b > 7) { | |
b = 1; | |
} | |
byte val = PINB & 0x03; | |
if(val != lastVal) { | |
if((val == 3 && lastVal == 2) ) { | |
t++; | |
if(4 == t) { | |
t = 0; | |
digit++; | |
if(10 == digit) { | |
digit = 0; | |
} | |
} | |
} else if ((val == 2 && lastVal == 3) ) { | |
if(0 == t) { | |
t = 4; | |
if(0 == digit) { | |
digit = 10; | |
} | |
digit --; | |
} | |
t--; | |
} | |
lastVal = val; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment