Advertisement
Guest User

Hobbyprojekt

a guest
Oct 2nd, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <nRF24L01.h>
  3. #include <RF24.h>
  4. #include "Adafruit_GFX.h"
  5. #include "Adafruit_ILI9341.h"
  6.  
  7. #define TFT_DC 9
  8. #define TFT_CS 10
  9. #define TFT_RST 8
  10. #define TFT_MISO 12
  11. #define TFT_MOSI 11
  12. #define TFT_CLK 13
  13. Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI,TFT_CLK, TFT_RST, TFT_MISO);
  14.  
  15. RF24 radio(3, 4); // CE, CSN
  16. unsigned long FPS;
  17. int FS_taster = A0;
  18. int tasterstatusFS;
  19. int NP_taster = A1;
  20. int tasterstatusNP;
  21. int vibration = 2;
  22. int taccap = 0;
  23. int magcap = 0;
  24. int counter = 0;
  25. int maxcounter = 0;
  26.  
  27. const byte addresse[6] = "00001";
  28.  
  29. void setup() {
  30. Serial.begin(9600);
  31. tft.begin();
  32. tft.setRotation(1);
  33. tft.fillScreen(ILI9341_WHITE);
  34. tft.setTextColor(ILI9341_BLACK,ILI9341_WHITE);
  35. radio.begin();
  36. radio.openReadingPipe(0, addresse);
  37. radio.setPALevel(RF24_PA_MIN);
  38. radio.startListening();
  39. pinMode(vibration, OUTPUT);
  40. pinMode(FS_taster, INPUT);
  41. pinMode(NP_taster, INPUT);
  42.  
  43. }
  44.  
  45. void loop(void) {
  46.  
  47. if (radio.available()) {
  48. counter = counter +1;
  49. maxcounter = maxcounter +1;
  50. radio.read(&FPS, sizeof(unsigned long));
  51. magcap = taccap - counter;
  52. }
  53. if (digitalRead(FS_taster)==HIGH){
  54. taccap = 19;
  55. tasterstatusFS = HIGH;
  56. tasterstatusNP = LOW;
  57. }
  58. if (digitalRead(NP_taster)==HIGH){
  59. taccap = 21;
  60. tasterstatusFS = LOW;
  61. tasterstatusNP = HIGH;
  62. }
  63.  
  64. tft.setTextSize(5);
  65. tft.setCursor(20, 10);
  66. tft.print("ChronyPLUS");
  67. tft.setTextSize(3);
  68. tft.setCursor(20, 60);
  69. tft.print("Magazin:");
  70. tft.setCursor(170, 60);
  71. tft.print(magcap);
  72. tft.setCursor(20, 110);
  73. tft.print("FPS:");
  74. tft.setCursor(170, 110);
  75. tft.print(FPS);
  76. tft.setCursor(20, 160);
  77. tft.print("Bullets:");
  78. tft.setCursor(170, 160);
  79. tft.print(maxcounter);
  80.  
  81. if (digitalRead(FS_taster)==HIGH && counter == 19){
  82. sequenz();
  83. }
  84. else if (digitalRead(NP_taster)==HIGH && counter == 21){
  85. sequenz();
  86. }
  87. else {
  88. digitalWrite(vibration, LOW);
  89. }
  90. delay(200);
  91. }
  92.  
  93. void sequenz (){
  94. digitalWrite(vibration, HIGH);
  95. delay(2000);
  96. digitalWrite(vibration, LOW);
  97. delay(1000);
  98. digitalWrite(vibration, HIGH);
  99. delay(2000);
  100. digitalWrite(vibration, LOW);
  101. delay(1000);
  102. counter =0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement