Advertisement
mayorBanana

Untitled

Apr 29th, 2024
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 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.  
  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. int bail_x = 0;
  18. int bail_y = 0;
  19.  
  20. int bail_vx = 0;
  21. int 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. }
  41.  
  42. void loop() {
  43. player_1 = map(analogRead(rezistor_1), 0, 1023, 0, HEIGHT - palca + 1);
  44. player_2 = map(analogRead(rezistor_2), 0, 1023, 0, HEIGHT - palca + 1);
  45.  
  46. for (int i = 0; i < palca; i++) {
  47. leds[index(X_pos, i + player_1)].setRGB(0, 0, MAX_BR);
  48. }
  49. for (int i = 0; i < palca; i++) {
  50. leds[index(X_pos_2, i + player_2)].setRGB(MAX_BR, 0,0 );
  51. }
  52.  
  53. FastLED.show();
  54. for (int i = 0; i < palca; i++) {
  55. leds[index(X_pos, i + player_1)].setRGB(0, 0, 0);
  56. }
  57. for (int i = 0; i < palca; i++) {
  58. leds[index(X_pos_2, i + player_2)].setRGB(0, 0, 0);
  59. }
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement