Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define pinA 2
- #define pinB 4
- volatile int counts = 0;
- void setup(){
- pinMode(pinA, INPUT);
- pinMode(pinB, INPUT);
- digitalWrite(pinA, HIGH); // turn on pull-up resistor
- digitalWrite(pinB, HIGH); // turn on pull-up resistor
- attachInterrupt(0, doEncoder, RISING); // encoder pin on interrupt 0 - pin 2
- Serial.begin(9600);
- Serial.println("start"); // a personal quirk
- }
- void loop(){
- Serial.println(counts, DEC);
- }
- void doEncoder(){
- if(digitalRead(pinB)){
- counts++;
- }else{
- counts--;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement