sources and files for the bombatuino project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.9 KiB

12 years ago
  1. #define encoder0PinA 2
  2. #define encoder0PinB 4
  3. #define encoder1PinA 3
  4. #define encoder1PinB 5
  5. void setup() {
  6. pinMode(encoder0PinA, INPUT);
  7. digitalWrite(encoder0PinA, HIGH); // turn on pullup resistor
  8. pinMode(encoder0PinB, INPUT);
  9. digitalWrite(encoder0PinB, HIGH); // turn on pullup resistor
  10. pinMode(encoder1PinA, INPUT);
  11. digitalWrite(encoder1PinA, HIGH); // turn on pullup resistor
  12. pinMode(encoder1PinB, INPUT);
  13. digitalWrite(encoder1PinB, HIGH); // turn on pullup resistor
  14. attachInterrupt(0, doEncoder0, CHANGE);
  15. attachInterrupt(1, doEncoder1, CHANGE);
  16. Serial.begin(9600);
  17. }
  18. void doEncoder0() {
  19. /* If pinA and pinB are both high or both low, it is spinning
  20. * forward. If they're different, it's going backward.
  21. *
  22. * For more information on speeding up this process, see
  23. * [Reference/PortManipulation], specifically the PIND register.
  24. */
  25. if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB)) {
  26. rotary_encoder_jogwheel_right_inc();
  27. } else {
  28. rotary_encoder_jogwheel_right_dec();
  29. }
  30. }
  31. void doEncoder1() {
  32. /* If pinA and pinB are both high or both low, it is spinning
  33. * forward. If they're different, it's going backward.
  34. *
  35. * For more information on speeding up this process, see
  36. * [Reference/PortManipulation], specifically the PIND register.
  37. */
  38. if (digitalRead(encoder1PinA) == digitalRead(encoder1PinB)) {
  39. rotary_encoder_jogwheel_left_inc();
  40. } else {
  41. rotary_encoder_jogwheel_left_dec();
  42. }
  43. }
  44. void loop() {
  45. delay(1000);
  46. Serial.println("sleep");
  47. }
  48. //left jogwheel
  49. void rotary_encoder_jogwheel_left_inc() {
  50. Serial.println("jogwheel_left_inc");
  51. }
  52. void rotary_encoder_jogwheel_left_dec() {
  53. Serial.println("jogwheel_left_dec");
  54. }
  55. //right jogwheel
  56. void rotary_encoder_jogwheel_right_inc() {
  57. Serial.println("jogwheel_right_inc");
  58. }
  59. void rotary_encoder_jogwheel_right_dec() {
  60. Serial.println("jogwheel_right_dec");
  61. }