#include <FastLED.h>
// How many leds in your strip?
#define NUM_LEDS 48
// For led chips like WS2812, which have a data line, ground, and power, you just
// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
// Clock pin only needed for SPI based chipsets when not using hardware SPI
#define DATA_PIN 5
#define button1 13
#define plyr_1_BTN 12
#define plyr_2_BTN 14
#define CLOCK_PIN 13
// Define the array of leds
CRGB leds[NUM_LEDS];
void setup() {
// Uncomment/edit one of the following lines for your leds arrangement.
// ## Clockless types ##
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // GRB ordering is assumed
// FastLED.addLeds<SM16703, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<TM1829, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<TM1812, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<UCS1903B, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<UCS1904, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<UCS2903, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS); // GRB ordering is typical
// FastLED.addLeds<WS2852, DATA_PIN, RGB>(leds, NUM_LEDS); // GRB ordering is typical
// FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS); // GRB ordering is typical
// FastLED.addLeds<GS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<SK6812, DATA_PIN, RGB>(leds, NUM_LEDS); // GRB ordering is typical
// FastLED.addLeds<SK6822, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<APA106, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<PL9823, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<SK6822, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2813, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<APA104, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2811_400, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<GE8822, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<GW6205_400, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<LPD1886, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<LPD1886_8BIT, DATA_PIN, RGB>(leds, NUM_LEDS);
// ## Clocked (SPI) types ##
// FastLED.addLeds<LPD6803, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); // GRB ordering is typical
// FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); // GRB ordering is typical
// FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2803, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); // BGR ordering is typical
// FastLED.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); // BGR ordering is typical
// FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); // BGR ordering is typical
// FastLED.addLeds<SK9822, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); // BGR ordering is typical
pinMode(button1, INPUT);
pinMode(plyr_1_BTN, INPUT);
pinMode(plyr_2_BTN, INPUT);
}
int bight = 230;
int millisDelay = 10000;
unsigned long myTime = 0;
bool StartGame = false;
void loop() {
/*if (myTime < millis()) {
myTime = millis() + millisDelay;
mainLED();
}
*/
paddel();
}
void Start_Animation () {
for (int i = 0; i < random(700,12000); i++) {
uint8_t thisSpeed = 50; // Change this to control the speed of the rainbow
uint8_t deltaHue = 10; // Change this to control the spacing between the colors
uint8_t thisHue = beat8(thisSpeed, 255); // Get a new hue value based on the speed
fill_rainbow(leds, NUM_LEDS, thisHue, deltaHue); // Fill the leds with the rainbow colors
FastLED.show(); // Show the leds
}
}
void ClearStrip () {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::Black;
}
}
// =======================================================
// ============ GAME 1 ==============
// =======================================================
void paddel () {
/*
STATE:
0 - Waiting for starting to COMPLETE
1 - Game running
2 - Game paused
3 - Start new round
10 - Player 1 Losser
20 - Player 2 Looser
69 = Exit Game
*/
byte state = 0;
byte PlayerToGoTo = 0;
int ball_position = 0;
int SpEeD = 50;
unsigned long daTime = 0;
while (!(state == 69)) {
// START!!
if (digitalRead(button1) == HIGH) {
StartGame = true;
}
switch (state) {
case 0: // =====[ Waiting for starting to COMPLETE ]======
// WHAT TO DO WHEN STARTING
if (StartGame) {
PlayerToGoTo = random(1, 2);
if (PlayerToGoTo == 1) {
ball_position = (NUM_LEDS - 1);
}
Start_Animation();
ClearStrip();
StartGame = false;
state = 1;
}
case 1: // =====[ Game running ]======
if (digitalRead(plyr_1_BTN) == HIGH){
PlayerToGoTo = 2;
}
if (digitalRead(plyr_2_BTN) == HIGH){
PlayerToGoTo = 1;
}
// ===== LED SpEeEeEeEd ======
if (daTime < millis()) {
daTime = millis() + SpEeD;
switch (PlayerToGoTo) {
case 1: // Player 1
GoToPlayer_1(ball_position);
break;
case 2: // Player 2
GoToPlayer_2(ball_position);
break;
default:
// if nothing else matches, do the default
// default is optional
break;
}
}
break;
case 2:
//do something when var equals 2
break;
default:
// if nothing else matches, do the default
// default is optional
break;
}
}
}
// =======================================================
// ============ GO TO PLAYER 1 ==============
// =======================================================
void GoToPlayer_1 (int &ballPos) {
ballPos--;
// Check if limit is reached
if (ballPos < 0) {
leds[(ballPos + 1)] = CRGB::Red;
FastLED.show();
return;
}
leds[ballPos] = CRGB::Blue;
for (int j = 1; j <= 6; j++) {
if (!((((NUM_LEDS - 1) - ballPos) + j) > (NUM_LEDS - 1))) {
if (j == 6) {
leds[(((NUM_LEDS - 1) - ballPos) + j)] = CRGB::Black;
} else {
leds[(((NUM_LEDS - 1) - ballPos) + j)].fadeLightBy(43);
}
}
}
FastLED.show();
/*
for (i = 0; i < NUM_LEDS; i++) {
leds[(NUM_LEDS - 1) - i] = CRGB::Blue;
int j;
for (j = 1; j < 11; j++) {
if (!((((NUM_LEDS - 1) - i) + j) > (NUM_LEDS - 1))) {
if (j == 10) {
leds[(((NUM_LEDS - 1) - i) + j)] = CRGB::Black;
} else {
leds[(((NUM_LEDS - 1) - i) + j)].fadeLightBy(35);
}
}
}
FastLED.show();
delay(20);
}
*/
}
// =======================================================
// ============ GO TO PLAYER 2 ==============
// =======================================================
void GoToPlayer_2 (int &ballPos) {
ballPos++;
// Check if limit is reached
if (ballPos >= NUM_LEDS) {
leds[(ballPos - 1)] = CRGB::Red;
FastLED.show();
return;
}
leds[ballPos] = CRGB::Blue;
for (int j = 1; j <= 6; j++) {
if (!((ballPos - j) < 0)) {
if (j == 6) {
leds[ballPos - j] = CRGB::Black;
} else {
leds[ballPos - j].fadeLightBy(43);
}
}
}
FastLED.show();
/*
for (i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::Blue;
int j;
for (j = 1; j < 11; j++) {
if (!((i - j) < 0)) {
if (j == 10) {
leds[i - j] = CRGB::Black;
} else {
leds[i - j].fadeLightBy(35);
}
}
}
FastLED.show();
delay(20);
}
*/
}
void mainLED() {
// Turn the LED on, then pause
int i;
for (i = 0; i < NUM_LEDS; i++) {
// Declare a variable to store the RGB value
int* rgbValue;
// Call the function and assign the result to the variable
rgbValue = randomRGB();
leds[i] = CRGB(rgbValue[0], rgbValue[1], rgbValue[2]);
// Free the memory allocated by the function
free(rgbValue);
}
FastLED.show();
}
// =======================================================
// ============ RANDON GENERATED RGB VALUES ==============
// =======================================================
// This function returns a random RGB value as an array of three integers
int* randomRGB() {
// Create an array to store the RGB value
int* rgb = (int*) malloc(3 * sizeof(int));
// Generate a random number between 0 and 255 for each color component
rgb[0] = random(0, 256); // Red
rgb[1] = random(0, 256); // Green
rgb[2] = random(0, 256); // Blue
// Return the RGB value
return rgb;
}
// =======================================================
// ============ BLUR FUNCTION ==============
// =======================================================
void Test_BLUR() {
// Turn the LED on, then pause
int i;
for (i = 0; i < NUM_LEDS; i++) {
// Declare a variable to store the RGB value
int* rgbValue;
// Call the function and assign the result to the variable
rgbValue = randomRGB();
leds[i] = CRGB(rgbValue[0], rgbValue[1], rgbValue[2]);
// Free the memory allocated by the function
free(rgbValue);
}
FastLED.show();
delay(10000);
// Now turn the LED off, then pause
//for (i=0;i<NUM_LEDS;i++){
// leds[i] = CRGB::Black;
//}
blur1d (leds, NUM_LEDS, 172);
FastLED.show();
delay(20000);
}
// =======================================================
// ============ LOOP COPY TO GO BACK TO ==============
// =======================================================
/*
void loop() {
// Turn the LED on, then pause
int i;
for (i=0;i<NUM_LEDS;i++){
// Declare a variable to store the RGB value
int* rgbValue;
// Call the function and assign the result to the variable
rgbValue = randomRGB();
leds[i] = CRGB(rgbValue[0], rgbValue[1], rgbValue[2]);
// Free the memory allocated by the function
free(rgbValue);
}
FastLED.show();
delay(2000);
fade_video (leds, NUM_LEDS, 150);
FastLED.show();
delay(2000);
}
*/