Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #define LED_PIN 6
- #define WIDTH 16
- #define HEIGHT 16
- #define NUM_LEDS (WIDTH * HEIGHT)
- CRGB leds[NUM_LEDS];
- // https://pastebin.com/r7e28UuM
- int index(int x, int y) {
- if (y % 2 == 0)
- return y * WIDTH + WIDTH - x - 1;
- else
- return y * WIDTH + x;
- }
- float bail_x = 0;
- float bail_y = 0;
- float bail_vx = 0;
- float bail_vy = 0;
- int player_1 = 0;
- int player_2 = 0;
- int MAX_BR = 255;
- int X_pos = 1;
- int X_pos_2 = WIDTH - 2;
- int palca = 3;
- #define rezistor_1 A0
- #define rezistor_2 A1
- void setup() {
- Serial.begin(115200);
- FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS);
- FastLED.setBrightness(50);
- pinMode(rezistor_1, INPUT);
- pinMode(rezistor_2, INPUT);
- bail_x = WIDTH / 2;
- bail_y = HEIGHT / 2;
- bail_vx = 0.01;
- bail_vy = 0.05;
- }
- void loop() {
- player_1 = map(analogRead(rezistor_1), 0, 1023, 0, HEIGHT - palca + 1);
- player_2 = map(analogRead(rezistor_2), 0, 1023, 0, HEIGHT - palca + 1);
- float bail_x_new = bail_x + bail_vx;
- float bail_y_new = bail_y + bail_vy;
- if (bail_y_new < 0 || bail_y_new >= HEIGHT) {
- bail_vy = -bail_vy;
- bail_y_new = bail_y + bail_vy;
- }
- bail_x = bail_x_new;
- bail_y = bail_y_new;
- for (int i = 0; i < palca; i++) {
- leds[index(X_pos, i + player_1)].setRGB(0, 0, MAX_BR);
- leds[index(X_pos_2, i + player_2)].setRGB(MAX_BR, 0, 0);
- }
- leds[index(bail_x, bail_y)].setRGB(MAX_BR, MAX_BR, MAX_BR);
- FastLED.show();
- for (int i = 0; i < palca; i++) {
- leds[index(X_pos, i + player_1)].setRGB(0, 0, 0);
- leds[index(X_pos_2, i + player_2)].setRGB(0, 0, 0);
- }
- leds[index(bail_x, bail_y)].setRGB(0, 0, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement