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.

87 lines
2.2 KiB

  1. #include "shiftRegButtonLib.h"
  2. shiftRegButton::shiftRegButton() {
  3. //init Pins
  4. shiftDatPORT &= ~shiftDatPin;
  5. shiftClkPORT &= ~shiftClkPin;
  6. //shiftInDDR &= ~shiftInPin;
  7. shiftDatDDR |= shiftDatPin;
  8. shiftClkDDR |= shiftClkPin;
  9. shiftInPORT |= shiftInPin;
  10. //init all flags
  11. shiftDatHi;
  12. for(uint8_t i = 0; i < numberOfButtons; i++, shiftClk()) {
  13. // buttonsPressed[i] = false;
  14. // buttonsCycle[i] = false;
  15. buttonsTime[i] = 0;
  16. // cycleFlag[i] = false;
  17. //init shiftreg outputs to all 1's
  18. }
  19. buttonsPressed = 0;
  20. buttonsCycle = 0;
  21. cycleFlag = 0;
  22. }
  23. shiftRegButton::checkButtons(void) {
  24. //this procedure is needed by the 74HC595, other shift registers' behaviour may differ. See the datasheet of your part for more informations.
  25. shiftDatLo; //
  26. shiftClk(); //zero to shift stage 0
  27. shiftDatHi; //
  28. shiftClk(); //zero to parallel output 0
  29. for(uint8_t i = 0; i < numberOfButtons; i++, shiftClk()) {
  30. //is button i actually pressed?
  31. if(buttonsInput()) {
  32. buttonsPressed |= 1 << i;
  33. // buttonsPressed[i] = true;
  34. // cycleFlag[i] = true;
  35. cycleFlag |= 1 << i;
  36. buttonsTime[i]++;
  37. } else {
  38. // buttonsPressed[i] = false;
  39. buttonsPressed &= ~(1 << i);
  40. buttonsTime[i] = 0;
  41. }
  42. checkButtonCycle(i);
  43. //increase the time button i is pressed, or clear if it is not pressed anymore
  44. }
  45. }
  46. bool shiftRegButton::checkButton(uint8_t n) {
  47. // return buttonsPressed[n];
  48. return buttonsPressed & (1 << n);
  49. }
  50. shiftRegButton::checkButtonCycle(uint8_t n) {
  51. // if(!buttonsPressed[n] && cycleFlag[n]) {
  52. if(!(buttonsPressed & (1 << n)) && (cycleFlag & (1 << n)) ) {
  53. // buttonsCycle[n] = true;
  54. buttonsCycle |= 1 << n;
  55. // cycleFlag[n] = false;
  56. cycleFlag &= ~(1 << n);
  57. }
  58. }
  59. shiftRegButton::clearButton(uint8_t buttonToBeCleared) {
  60. // buttonsCycle[buttonToBeCleared] = false;
  61. buttonsCycle &= ~(1 << buttonToBeCleared);
  62. }
  63. shiftRegButton::clearAllButtons() {
  64. for(uint8_t i = 0; i < numberOfButtons; i++) {
  65. // buttonsCycle[i] = false;
  66. buttonsCycle &= ~(1 << i);
  67. }
  68. }
  69. bool shiftRegButton::getButtonCycle(uint8_t n) {
  70. // return buttonsCycle[n];
  71. return buttonsCycle & (1 << n);
  72. }
  73. uint16_t shiftRegButton::getAnyPressed() {
  74. return buttonsPressed;
  75. }