ChaOSzz

Джойстик Рисовалка .ino

Feb 8th, 2022 (edited)
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <MD_MAX72xx.h>
  2.  
  3. #define MAX_DEVICES 2
  4.  
  5. const int maxX = 15;
  6. const int maxY = 7;
  7.  
  8. #define CS_PIN      10
  9.  
  10. #define VERT_PIN A0
  11. #define HORZ_PIN A1
  12. #define SEL_PIN  2
  13.  
  14. MD_MAX72XX mx = MD_MAX72XX(MD_MAX72XX::PAROLA_HW, CS_PIN, MAX_DEVICES);
  15.  
  16. int x = 0;
  17. int y = 0;
  18.  
  19. void setup() {
  20.   mx.begin();
  21.   mx.control(MD_MAX72XX::INTENSITY, MAX_INTENSITY / 2);
  22.   mx.clear();
  23.  
  24.   pinMode(VERT_PIN, INPUT);
  25.   pinMode(HORZ_PIN, INPUT);
  26.   pinMode(SEL_PIN, INPUT_PULLUP);
  27. }
  28.  
  29. void loop() {
  30.   int horz = analogRead(HORZ_PIN);
  31.   int vert = analogRead(VERT_PIN);
  32.   if (vert < 300) {
  33.     y = min(y + 1, maxY);
  34.   }
  35.   if (vert > 700) {
  36.     y = max(y - 1, 0);
  37.   }
  38.   if (horz > 700) {
  39.     x = min(x + 1, maxX);
  40.   }
  41.   if (horz < 300) {
  42.     x = max(x - 1, 0);
  43.   }
  44.   if (digitalRead(SEL_PIN) == LOW) {
  45.     mx.clear();
  46.   }
  47.   mx.setPoint(y, x, true);
  48.   mx.update();
  49.   delay(100);
  50. }
  51.  
Add Comment
Please, Sign In to add comment