Ein Roboter mit bürstenlosem Antrieb, differenzial und NRF24L01 Funk. Großflächig gebaut um ein großes Solarpanel aufzunehmen. https://gitlab.informatik.hs-fulda.de/fdai5253/roboter
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.

86 lines
2.3 KiB

  1. #pragma once
  2. #ifndef shiftRegButtonLib_h
  3. #define shiftRegButtonLib_h
  4. #include <Arduino.h>
  5. #define numberOfButtons 11
  6. //definitions for buttons
  7. #define buttonUp 0
  8. #define buttonLeft 2
  9. #define buttonRight 1
  10. #define buttonDown 3
  11. #define buttonL1 4
  12. #define buttonStart 5
  13. #define buttonSelect 6
  14. #define buttonR1 7
  15. #define buttonA 9
  16. #define buttonB 10
  17. #define buttonC 8
  18. //Pin and PORT assignments for shiftRegister(s)
  19. #define shiftDatPin 0x01 //D8
  20. #define shiftClkPin 0x40 //D6
  21. #define shiftInPin 0x02 //D9
  22. #define shiftDatPORT PORTB
  23. #define shiftDatDDR DDRB // Should be DDRx, x = port name (B, C, D, etc.)
  24. #define shiftClkPORT PORTD
  25. #define shiftClkDDR DDRD
  26. #define shiftInPIN PINB
  27. #define shiftInPORT PORTB
  28. #define shiftInDDR DDRB
  29. //Macros
  30. #define shiftDatLo (shiftDatPORT &= ~shiftDatPin)
  31. #define shiftDatHi (shiftDatPORT |= shiftDatPin)
  32. //74HC595 needs rising edge for sampling data
  33. inline void shiftClk(void)
  34. {
  35. shiftClkPORT |= shiftClkPin;
  36. shiftClkPORT &= ~shiftClkPin;
  37. }
  38. inline bool buttonsInput(void)
  39. {
  40. if((shiftInPIN &= shiftInPin) == 0) {
  41. return true;
  42. } else {
  43. return false;
  44. }
  45. }
  46. class shiftRegButton {
  47. public:
  48. shiftRegButton();
  49. checkButtons(void);
  50. //returns the state of a certain button
  51. bool checkButton(uint8_t n);
  52. checkButtonCycle(uint8_t n);
  53. //clears the cycle flag of a certain button
  54. clearButton(uint8_t buttonToBeCleared);
  55. //clears all cycle flags
  56. clearAllButtons();
  57. //return, if a certain button has been pressed (complete cycle, Hi-Lo-Hi)
  58. bool getButtonCycle(uint8_t n);
  59. //was any button pressed?
  60. uint16_t getAnyPressed();
  61. private:
  62. // volatile bool buttonsPressed[numberOfButtons]; //flags to represent the actual (debounced) state of a button, no clearing needed
  63. volatile uint16_t buttonsPressed; //flags to represent the actual (debounced) state of a button, no clearing needed
  64. // volatile bool buttonsCycle[numberOfButtons]; //flags to represent if a button did a whole hi-lo-hi cycle, clearing needed
  65. volatile uint16_t buttonsCycle; //flags to represent if a button did a whole hi-lo-hi cycle, clearing needed
  66. uint8_t buttonsTime[numberOfButtons]; //the time in milliseconds a button was actually pressed, no clearing needed, no overflow detection (max = 255ms)
  67. // volatile bool cycleFlag[numberOfButtons];
  68. volatile uint16_t cycleFlag;
  69. };
  70. #endif