Advertisement
pidgezero_one

Untitled

Aug 27th, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1.  
  2.  
  3. #define LATCH_BIT 0 //white
  4. #define CLOCK_BIT 1 //yellow
  5. #define DATA_BIT 2
  6. #define LATCH_PIN A0
  7. #define CLOCK_PIN A1
  8. #define DATA_PIN A2
  9.  
  10. #define FIXED_TIME 0
  11. void initPins();
  12.  
  13. void sendButtons();
  14. void setup()
  15. {
  16. initPins();
  17. disableTimers();
  18. noInterrupts();
  19. }
  20.  
  21. #define readLatch() ((PINC & (1 << LATCH_BIT)) ? HIGH : LOW )
  22. #define readClock() ((PINC & (1 << CLOCK_BIT)) ? HIGH : LOW )
  23. #define sendButtonState(btns) PORTC = (PORTC & (~(1<<DATA_BIT))) | ((btns & 1) << DATA_BIT); btns = (btns >> 1)
  24.  
  25. #define waitForClockCycle() while(readClock() == HIGH);while(readClock() == LOW)
  26.  
  27. void loop()
  28. {
  29. if(readLatch() != HIGH) {
  30. return;
  31. }
  32.  
  33. unsigned int pind = B11111100;
  34. unsigned int pinb = B00111011;
  35. //unsigned int left = B00000010;
  36. //unsigned int right = B00000001;
  37. unsigned int buttonsLow = pind >> 2;
  38. unsigned int buttonsHigh = pinb & B00111111;
  39.  
  40. while( readLatch() == HIGH);
  41.  
  42.  
  43. sendButtonState(buttonsLow);
  44. waitForClockCycle();
  45. sendButtonState(buttonsLow);
  46. waitForClockCycle();
  47. sendButtonState(buttonsLow);
  48. waitForClockCycle();
  49. sendButtonState(buttonsLow);
  50. waitForClockCycle();
  51. sendButtonState(buttonsLow);
  52. waitForClockCycle();
  53. sendButtonState(buttonsLow);
  54. waitForClockCycle();
  55. sendButtonState(buttonsHigh);
  56. waitForClockCycle();
  57. sendButtonState(buttonsHigh);
  58. waitForClockCycle();
  59. sendButtonState(buttonsHigh);
  60. waitForClockCycle();
  61. sendButtonState(buttonsHigh);
  62. waitForClockCycle();
  63. sendButtonState(buttonsHigh);
  64. waitForClockCycle();
  65. sendButtonState(buttonsHigh);
  66. waitForClockCycle();
  67. PORTC |= (1<<DATA_BIT);
  68.  
  69. }
  70.  
  71. void initPins() {
  72. pinMode(LATCH_PIN, INPUT);
  73. pinMode(CLOCK_PIN, INPUT);
  74. pinMode(DATA_PIN, OUTPUT);
  75. digitalWrite(DATA_PIN, LOW);
  76.  
  77. }
  78.  
  79. void disableTimers() {
  80. TCCR0A = 0;
  81. TCCR0B = 0;
  82. TCCR1A = 0;
  83. TCCR1B = 0;
  84. TCCR2A = 0;
  85. TCCR2B = 0;
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement