Advertisement
mayorBanana

Untitled

May 4th, 2024
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. #define LED_PIN 6
  4. #define WIDTH 16
  5. #define HEIGHT 16
  6. #define NUM_LEDS (WIDTH * HEIGHT)
  7. CRGB leds[NUM_LEDS];
  8.  
  9. // https://pastebin.com/r7e28UuM
  10. int index(int x, int y) {
  11. if (y % 2 == 0)
  12. return y * WIDTH + WIDTH - x - 1;
  13. else
  14. return y * WIDTH + x;
  15. }
  16.  
  17. float bail_x = 0;
  18. float bail_y = 0;
  19.  
  20. float bail_vx = 0;
  21. float bail_vy = 0;
  22.  
  23. int player_1 = 0;
  24. int player_2 = 0;
  25.  
  26. int MAX_BR = 255;
  27. int X_pos = 1;
  28. int X_pos_2 = WIDTH - 2;
  29. int palca = 3;
  30.  
  31. #define rezistor_1 A0
  32. #define rezistor_2 A1
  33.  
  34. void setup() {
  35. Serial.begin(115200);
  36. FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS);
  37. FastLED.setBrightness(50);
  38. pinMode(rezistor_1, INPUT);
  39. pinMode(rezistor_2, INPUT);
  40. bail_x = WIDTH / 2;
  41. bail_y = HEIGHT / 2;
  42. bail_vx = 0.01;
  43. bail_vy = 0.05;
  44. }
  45.  
  46. void loop() {
  47. player_1 = map(analogRead(rezistor_1), 0, 1023, 0, HEIGHT - palca + 1);
  48. player_2 = map(analogRead(rezistor_2), 0, 1023, 0, HEIGHT - palca + 1);
  49. float bail_x_new = bail_x + bail_vx;
  50. float bail_y_new = bail_y + bail_vy;
  51. if (bail_y_new < 0 || bail_y_new >= HEIGHT) {
  52. bail_vy = -bail_vy;
  53. bail_y_new = bail_y + bail_vy;
  54. }
  55.  
  56. bail_x = bail_x_new;
  57. bail_y = bail_y_new;
  58.  
  59. for (int i = 0; i < palca; i++) {
  60. leds[index(X_pos, i + player_1)].setRGB(0, 0, MAX_BR);
  61. leds[index(X_pos_2, i + player_2)].setRGB(MAX_BR, 0, 0);
  62. }
  63.  
  64. leds[index(bail_x, bail_y)].setRGB(MAX_BR, MAX_BR, MAX_BR);
  65. FastLED.show();
  66.  
  67. for (int i = 0; i < palca; i++) {
  68. leds[index(X_pos, i + player_1)].setRGB(0, 0, 0);
  69. leds[index(X_pos_2, i + player_2)].setRGB(0, 0, 0);
  70. }
  71.  
  72.  
  73. leds[index(bail_x, bail_y)].setRGB(0, 0, 0);
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement