/*
can any one fix this code or explain completly how to make classes and using them or at least a complete source to learn also third button should be for brightness of leds and game control also im using arduino nano with around 35 .h files so private class is needed preferly also arduino site forced me to put all .h files in one tab couse im new user but still so sorry about it (first button is gonna have 5 modes and when i got into one of them second button changes modes inside the mode also third button is for brightness and game control) thanks for any h
*/
// FIRST BUTTON /////////////////
#include <FastLED.h>
#include "Pacifica.h"
#include "AAnimations.h"
#include "Gamefun.h"
#include "Gameone.h"
#include "goodgoodmicthree.h"
#include "Gametwo.h"
//#include "Arduino.h"
int opop = 1;
int opopo = 1;
int one = 1;
int two = 1;
int three = 1;
float pressLength_milliSeconds = 0;
// Define the minimum length of time, in milli-seconds, that the button must be pressed for a particular option to occur
int optionOne_milliSeconds = 100;
int optionTwo_milliSeconds = 700;
int buttonPin = 5;
int n = 0;
// SECOND BUTTON ////////////////////
float pressLength_milliSeconds2 = 0;
// Define the minimum length of time, in milli-seconds, that the button must be pressed for a particular option to occur
int optionOne_milliSeconds2 = 100;
int optionTwo_milliSeconds2 = 700;
int buttonPin2 = 6;
int n2 = 9;
// THIRD BUTTON /////////////////
float pressLength_milliSeconds3 = 0;
// Define the minimum length of time, in milli-seconds, that the button must be pressed for a particular option to occur
int optionOne_milliSeconds3 = 100;
int optionTwo_milliSeconds3 = 700;
int buttonPin3 = 7;
int n3 = 19;
bool isRunning = false;
int abcd = 1;
void runBeatwave();
void runAAnimations();
void runPacifica();
void runBlendwave();
void runBlack();
void light();
//Gametwo gametwo;
void mictwo();
void gamegame();
void setup(){
pinMode(buttonPin, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
buttonone();
button2();
button3();
light();
if(n == 1){
if( n2 > 9 && n2 < 17) {
if(n2 == 10){
EVERY_N_MILLISECONDS(1000){
Serial.println("FIRST");}
micone();
// runPacifica();
}
if(n2 == 11){
EVERY_N_MILLISECONDS(1000){
Serial.println("SECOND");}
//while(n2 == 11){
//button2();
mictwo();
//}
}
if(n2 == 12){
EVERY_N_MILLISECONDS(1000){
Serial.println("THIRD");}
// runAAnimations();
runPacifica();
// micthree();
}
if(n2 == 13){
EVERY_N_MILLISECONDS(1000){
Serial.println("FOURTH");}
//runPacifica();
}
if(n2 == 14){
EVERY_N_MILLISECONDS(1000){
Serial.println("FIFTH");}
}
if(n2 == 15){
EVERY_N_MILLISECONDS(1000){
Serial.println("sixTH");}
//gamegame();
}
if(n2 == 16){
EVERY_N_MILLISECONDS(1000){
Serial.println("sevenTH");}
}
}
}
else { if ( n2 > 16 ){
n2 = 10;
}
else if ( n2 < 10 ) { n2 = 16; }
}
if(n == 2){
// micthree();
}
if(n == 3){
mictwo();
}
if(n == 4){
}
}
// BUTTON 1 /////////////////////////////////////////////////////////////////////////
void buttonone() {
//Record roughly the tenths of seconds the button in being held down
while (digitalRead(buttonPin) == LOW ){
isRunning = false;
delay(100); //if you want more resolution, lower this number
pressLength_milliSeconds = pressLength_milliSeconds + 100;
//Serial.print("ms = ");
//Serial.println(pressLength_milliSeconds);
}
if (pressLength_milliSeconds >= optionTwo_milliSeconds){
if( n <= 0) { n = 4;}
else{ n--; }
Serial.println(n);
}
else if(pressLength_milliSeconds >= optionOne_milliSeconds){
if( n >= 4) { n = 0;}
else{ n++; }
Serial.println(n);
}
pressLength_milliSeconds = 0;
}
// BUTTON 2 ///////////////////////////////////////////////////////////////////////////////
void button2() {
//Record roughly the tenths of seconds the button in being held down
while (digitalRead(buttonPin2) == LOW ){
delay(100); //if you want more resolution, lower this number
pressLength_milliSeconds2 = pressLength_milliSeconds2 + 100;
//Serial.print("ms = ");
//Serial.println(pressLength_milliSeconds);
}
if (pressLength_milliSeconds2 >= optionTwo_milliSeconds2){
if( n2 < 10) { n2 = 19;}
else{ n2--; }
}
else if(pressLength_milliSeconds2 >= optionOne_milliSeconds2){
if( n2 > 19) { n2 = 10;}
else{ n2++; }
}
pressLength_milliSeconds2 = 0;
}
// BUTTON 3 //////////////////////////////////////////////////////////////////////////////
void button3() {
if(n2 != 15){
//Record roughly the tenths of seconds the button in being held down
while (digitalRead(buttonPin3) == LOW ){
delay(100); //if you want more resolution, lower this number
pressLength_milliSeconds3 = pressLength_milliSeconds3 + 100;
//Serial.print("ms = ");
//Serial.println(pressLength_milliSeconds);
}
}
if (pressLength_milliSeconds3 >= optionTwo_milliSeconds3){
if( n3 < 21) { n3 = 24;}
else{ n3--; }
Serial.println(n3);
}
else if(pressLength_milliSeconds3 >= optionOne_milliSeconds3){
if( n3 >= 24) { n3 = 20;}
else{ n3++; }
Serial.println(n3);
}
pressLength_milliSeconds3 = 0;
}
void runPacifica(){
Pacifica pacifica;
pacifica.runPattern();
// isRunning = true;
// if(isRunning = true){
//isRunning = true;
// Pacifica pacifica = Pacifica();
// if(isRunning = true){ pacifica.runPattern();}
}
void runAAnimations(){
isRunning = true;
AAnimations aAnimations = AAnimations();
if(isRunning = true){ aAnimations.runPattern();}
}
/*
void gamegame(){
if(opop == 1){
//void setup()
myGame = new Game();
myGame->setup();
opop = 2;
}
else{
// void loop()
myGame->loop();
}
}*/
void micone(){
if(one == 1){
//void setup()
myGameone = new Gameone();
myGameone->setup();
one = 2;
}
else{
// void loop()
myGameone->loop();
}
}
void mictwo(){
Gametwo gametwo;
// isRunning = true;
// if(isRunning = true){
if(two == 1){
//void setup()
//myGametwo = new Gametwo();
gametwo.setup();
two = 2;
}
else{
// void loop()
gametwo.loop();
}
}
//}
/*
void micthree(){
if(three == 1){
//void setup()
myGamethree = new Gamethree();
myGamethree->setup();
three = 2;
}
else{
// void loop()
myGamethree->loop();
}
}
*/
void light() {
if(n3 == 20){
int max_bright = 5 ;}
if(n3 == 21){
int max_bright = 170 ;}
if(n3 == 22){
int max_bright = 240 ;}
}
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// AAnimation tab
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
#include "Arduino.h"
class AAnimations {
public:
int n3;
int max_bright ;
AAnimations(){};
void runPattern();
void jjPattern(){
if(n3 = 21){
max_bright = 10;
}
if(n3 = 22){
max_bright = 158;
}
};
private:
#include "FastLED.h"
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif
#define LED_DT 4
#define COLOR_ORDER GRB
#define LED_TYPE WS2812B
#define NUM_LEDS 60
// Global variables can be changed on the fly.
//uint8_t max_bright ; // Overall brightness definition. It can be changed on the fly.
// have 3 independent CRGBs - 2 for the sources and one for the output
CRGB leds[NUM_LEDS];
CRGB leds2[NUM_LEDS];
CRGB leds3[NUM_LEDS];
void aanimations_loop();
void animationA();
void animationB();
};
void AAnimations::runPattern() {
/*
if(n3 = 21){
max_bright = 10;
}
if(n3 = 22){
max_bright = 158;
}
*/
// LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS); // Use this for WS2812
// FastLED.setBrightness(max_bright);
aanimations_loop();
}
void AAnimations::aanimations_loop() {
LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS); // Use this for WS2812
FastLED.setBrightness(max_bright);
max_bright++;
animationA(); // render the first animation into leds2
animationB(); // render the second animation into leds3
uint8_t ratio = beatsin8(2); // Alternate between 0 and 255 every minute
for (int i = 0; i < NUM_LEDS; i++) { // mix the 2 arrays together
leds[i] = blend( leds2[i], leds3[i], ratio );
}
FastLED.show();
} // loop()
void AAnimations::animationA() { // running red stripe.
for (int i = 0; i < NUM_LEDS; i++) {
uint8_t red = (millis() / 10) + (i * 12); // speed, length
if (red > 128) red = 0;
leds2[i] = CRGB(red, 0, 0);
}
} // animationA()
void AAnimations::animationB() { // running green stripe in opposite direction.
for (int i = 0; i < NUM_LEDS; i++) {
uint8_t green = (millis() / 5) - (i * 12); // speed, length
if (green > 128) green = 0;
leds3[i] = CRGB(0, green, 0);
}
} // animationB()
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// Gamefun.h tab
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
#include "Arduino.h"
// We need these libraries installed from library manager
#include <Adafruit_NeoPixel.h>
#include "OneButton.h"
// What GPIO is the strip connected to
#define PIXELPIN 4
// How many NeoPixels in the strip
#define NUMPIXELS 60
// What GPIO is the button connected to?
#define BUTTON_TAP 7
// Initialise the button, with a default low
OneButton buttonTAP(BUTTON_TAP, true);
// Initialise the pixel strip
class Game *myGame;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIXELPIN, NEO_GRB + NEO_KHZ800);
class Game
{
unsigned long countdown = 0;
int playerDirection = 1;
bool gameOver = false;
int enemyIndex = -1;
int coinIndex = -1;
int playerIndex = -1;
float currentPlayerSpeed = 190;
int score = 0;
// A bunch of variables
int playerIndexTrail = -2;
float nextMove = 0;
int bestScore = 0;
int lastScore = 0;
public:
void setup()
{
// make the button pin an input
pinMode( BUTTON_TAP, INPUT_PULLUP );
// Attatch click functions to the button
buttonTAP.attachClick(Game::singleClick);
buttonTAP.attachLongPressStart(Game::longClick);
// Initialise the strip and set it's brightness to 20%
pixels.begin();
pixels.setBrightness(250);
// set a 2 second countdown before the player appears and starts moving
countdown = millis() + 2000;
}
void loop()
{
// Every cycle we need to tick the button state
buttonTAP.tick();
// If the game is in game over state, exit loop early
if ( gameOver )
return;
// Set the pixel display state of the level
// This sets the enemy position and the coin position
SetLevel();
// wait for a second for the player to get ready
if ( countdown > millis() )
{
pixels.show();
return;
}
// All the player display, movement and game logic is in here
DisplayPlayer();
// This sends the updated pixel color to the hardware.
pixels.show();
}
// Clear the level, setting all pixels to black
static void ClearLevel()
{
for (int i = 0; i < NUMPIXELS; i++)
pixels.setPixelColor(i, pixels.Color(0, 0, 0)); // Moderately bright green color.
//rainbow
pixels.show();
}
//random(1, 150),random(1, 255),random(150, 255)
// Show the best score in yellow and if the last score was less than the best, show that on top in red
void BestScore()
{
// Best score in yellow
for (int i = 0; i < NUMPIXELS; i++)
{
if ( i < bestScore )
pixels.setPixelColor(i, pixels.Color(255, 0, 0 )); // Moderately bright green color.
else
pixels.setPixelColor(i, pixels.Color(0, 0, 0));
}
// last score is less than best is in red
if ( lastScore < bestScore )
{
for (int i = 0; i < lastScore; i++)
pixels.setPixelColor(i, pixels.Color(255, 0, 0)); // Moderately bright green color.
}
pixels.show();
}
// Game over animation
void GameOver()
{
// First pass we animate the strip going red from the enemy position
int a = enemyIndex;
int b = enemyIndex;
for (int i = 0; i < NUMPIXELS / 2; i++)
{
pixels.setPixelColor(a, pixels.Color(255, 0, 0)); // Moderately bright green color.
pixels.setPixelColor(b, pixels.Color(255, 0, 0)); // Moderately bright green color.
a = ( a + 1) % NUMPIXELS;
b--;
if ( b == -1 )
b = NUMPIXELS;
pixels.show();
delay(20);
}
delay(100);
// Second pass we animate the strip going back from the enemy position
a = enemyIndex;
b = enemyIndex;
for (int i = 0; i < NUMPIXELS / 2; i++)
{
pixels.setPixelColor(a, pixels.Color(0, 0, 0)); // Black
pixels.setPixelColor(b, pixels.Color(0, 0, 0)); // Black
a = ( a + 1) % NUMPIXELS;
b--;
if ( b == -1 )
b = NUMPIXELS;
pixels.show();
delay(20);
}
// Now we show the best score
delay(100);
BestScore();
}
// Setup the level including the postiion of the enemy and the coin
void SetLevel()
{
// If the enemy position is -1 (has been reset)
// Find a new position for the enemy
if ( enemyIndex < 0 )
{
// I fthe player not playing, always start the enemy at the half strip position
if ( playerIndex < 0 )
{
enemyIndex = NUMPIXELS / 2;
}
// The player is in the game, so make sure not to place the enemy on or too close to the player
else
{
enemyIndex = random(0, NUMPIXELS);
while ( abs(enemyIndex - playerIndex ) < ( NUMPIXELS / 4 ) )
enemyIndex = random(0, NUMPIXELS);
}
}
// If the coin position is -1 (has been reset)
// Find a new position for the coin
if ( coinIndex < 0 )
{
coinIndex = random(0, NUMPIXELS);
// pick a coin position somewhere between the player and enemy
while ( abs(coinIndex - playerIndex ) < 7 || ( abs(coinIndex - enemyIndex ) < 7 ) )
coinIndex = random(0, NUMPIXELS);
}
pixels.setPixelColor(enemyIndex, pixels.Color(255, 10, 0));
pixels.setPixelColor(coinIndex, pixels.Color(255, 255, 0));
}
// This is where all the magic happens
// Player movement happens here as well as game logic for collecting coins or hitting the enemy
void DisplayPlayer()
{
if ( nextMove < millis() )
{
nextMove = millis() + currentPlayerSpeed;
// The player has a visual trail, so these next 2 if statements shows or clears the trail
if ( playerIndexTrail >= 0 )
pixels.setPixelColor(playerIndexTrail, pixels.Color(random(1, 70), random(1, 160), random(200, 255)));
if ( playerIndex >= 0)
{
pixels.setPixelColor(playerIndex, pixels.Color(255, 0, 255));
// second dot player
playerIndexTrail = playerIndex;
}
// Move the player in their current direction
playerIndex += playerDirection;
// Wrap the player at the strip edges
if ( playerIndex < 0 )
playerIndex = NUMPIXELS - 1;
else if ( playerIndex == NUMPIXELS )
playerIndex = 0;
pixels.setPixelColor(playerIndex, pixels.Color(0, 255, 0));
//142, 255, 10 player dot
// Did the player hit the coin?
// If so, increase the score, reset coin and enemy positions and clear the level
// Next loop the SetLevel() will reset the enemy and coin
// Player speed is also increased for every coin hit
if ( playerIndex == coinIndex )
{
enemyIndex = -1;
coinIndex = -1;
score++;
currentPlayerSpeed = constrain( currentPlayerSpeed - 5, 15, 130 );
ClearLevel();
pixels.setPixelColor(playerIndex, pixels.Color(0, 0, 255));
}
// 142, 255, 10
// Did the player hit the enemy?
// Set the last/best score and call game over
else if ( playerIndex == enemyIndex )
{
lastScore = score;
if ( score >= bestScore )
bestScore = score;
GameOver();
gameOver = true;
enemyIndex = -1;
coinIndex = -1;
playerIndex = -1;
}
}
}
// Single button click
static void singleClick()
{
// No input until player is visible
if ( myGame->countdown > millis() )
return;
// switch the player direction
myGame->playerDirection = -myGame->playerDirection;
}
// Long button click
static void longClick()
{
// Switch game over state
// If it was game over, start the game, otherwise cancel a game in progress
myGame->gameOver = !myGame->gameOver;
if ( myGame->gameOver )
{
myGame->enemyIndex = -1;
myGame->coinIndex = -1;
myGame->playerIndex = -1;
myGame->currentPlayerSpeed = 190;
myGame->ClearLevel();
}
else
{
myGame->ClearLevel();
myGame->score = 0;
myGame->currentPlayerSpeed = 190;
myGame->countdown = millis() + 2000;
}
}
};
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// Gameone.h tab
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
#include "Arduino.h"
class Gameone *myGameone;
class Gameone
{
#include <FastLED.h> //FastLED library
#define NUM_LED 150 //number of LEDs in the strip
#define LED_PIN 4 //data pin on the arduino
#define BRIGHTNESS 100 //default brightness
#define updateLEDS 5 //number of LEDs to update
CRGB led[NUM_LED]; //array of LEDs
const int brightnessPot = A1; //pin for the brightness pot
const int audioSignal = A0; //pin for the audio signal
int volumeLevel; //iniger for volume level
public:
void setup() {
pinMode(audioSignal, INPUT); //input pin for the audio signal
Serial.begin(9600); //serial for debugging
FastLED.addLeds<WS2812B, LED_PIN, GRB>(led, NUM_LED); //fastLED initalization
FastLED.setBrightness(BRIGHTNESS); //set the default brightness
delay(1000); //wait 1 sec
resetLedState(); //turn off all the leds
}
void setLedBrightness() { //function to set the brigthess set on the pot
LEDS.setBrightness(map(analogRead(brightnessPot),0,1023,0,255));
}
void loop() {
setLedBrightness(); //set the new brightness, you can comment this line at the beginning to disable it
audioRead(); //reap the audio level and map it
Serial.println(volumeLevel); //Send volume level to the serial monitor, you can also use serial plotter to better see the values and adjust the ampplification of the audio signal
//for loop to move all the LEDs down the strip
for (int i = NUM_LED - 1; i >= updateLEDS; i--) {
led[i] = led[i - updateLEDS];
}
//for loop to set the first LED corresponding to the audio level
for (int i = 0; i < updateLEDS; i++) {
displayFilter(volumeLevel, i); //set the right colour magic
}
FastLED.show(); //updates the LED strip
delay(50); //delay
}
void resetLedState() { //function to turn off all the LEDs
for (int turnMeOff = 0; turnMeOff < 61; turnMeOff++) {
led[turnMeOff] = CRGB(0, 0, 0);
}
FastLED.show();
}
void audioRead() { //function to read the audio
int rawValue = analogRead(audioSignal) * 2; //double the audio level
volumeLevel = map(rawValue, 0, 1023, 0, 900); //map it to 900 values
if (volumeLevel > 900) { //if it's higher than 900 it lowers it back to 900
volumeLevel = 900;
}
}
/*
- a lot of IF statements to set the right color.
- colors go from red to blue, then green and orange at the end(red is already used), at 0 volume leds are off/black, at 900/max they're white
*/
void displayFilter(int volume, int lucka) {
if (volume < 1) {
led[lucka] = CRGB(0, 0, 0); //0, black
}
if (volume > 1 && volume < 51) {
led[lucka] = CRGB(255, 0, 0); //1-50
}
if (volume > 50 && volume < 101) {
led[lucka] = CRGB(255, 0, 85); //51-100
}
if (volume > 100 && volume < 151) {
led[lucka] = CRGB(255, 0, 170); //101-150
}
if (volume > 150 && volume < 201) {
led[lucka] = CRGB(255, 0, 255); //151-200
}
if (volume > 200 && volume < 251) {
led[lucka] = CRGB(170, 0, 255); //201-250
}
if (volume > 250 && volume < 301) {
led[lucka] = CRGB(85, 0, 255); //251-300
}
if (volume > 300 && volume < 351) {
led[lucka] = CRGB(0, 0, 255); //301-350
}
if (volume > 350 && volume < 401) {
led[lucka] = CRGB(0, 85, 255); //351-400
}
if (volume > 400 && volume < 451) {
led[lucka] = CRGB(0, 170, 255); //401-450
}
if (volume > 450 && volume < 501) {
led[lucka] = CRGB(0, 255, 255); //451-500
}
if (volume > 500 && volume < 551) {
led[lucka] = CRGB(0, 255, 170); //501-550
}
if (volume > 550 && volume < 601) {
led[lucka] = CRGB(0, 255, 85); //551-600
}
if (volume > 600 && volume < 651) {
led[lucka] = CRGB(0, 255, 0); //601-650
}
if (volume > 650 && volume < 701) {
led[lucka] = CRGB(85, 255, 0); //651-700
}
if (volume > 700 && volume < 751) {
led[lucka] = CRGB(170, 255, 0); //701-750
}
if (volume > 750 && volume < 801) {
led[lucka] = CRGB(255, 255, 0); //751-800
}
if (volume > 800 && volume < 851) {
led[lucka] = CRGB(255, 170, 0); //801-850
}
if (volume > 850 && volume < 900) {
led[lucka] = CRGB(255, 85, 0); //851-899
}
if (volume > 899) {
led[lucka] = CRGB(255, 255, 255); //900, white
}
}
};
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// Gametwo.h tab
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
#include "Arduino.h"
//class Gametwo *myGametwo;
class Gametwo
{
#include <FastLED.h>
#define LED_PIN 4 //CONNECT DATA PIN OF PIXEL WITH 5 NUMBER PIN OF ARDUINO
#define NUM_LEDS 60 //CHANGE THE VALUE IF YOU WANT TO USE DIFFRENT NUMBER OF LED IN YOUR STRIP,HERE IN MY STRIP NUMBER OF LED IS 30 SO I SET IT 30.
CRGB leds[NUM_LEDS];
CRGB led[NUM_LEDS];
CRGB led_bucket[NUM_LEDS];
int r=152;
int g=0;
int b=10;
int s=0;
public:
//Gametwo(){
void Gametwo::setup() {
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
for (int i = NUM_LEDS; i >= 0; i--)
{
led_bucket[NUM_LEDS-i] = CRGB (r,g,b );
delay(40);
FastLED.show();
}
Serial.begin(9600);
pinMode(A0,INPUT);
}
void Gametwo::loop()
{
s=analogRead(A0);
s=s*2;
// Serial.println(s);
// delay(50);
if((s>=450)&&(s<=550))
{
led_bucket[0]=CRGB (0, 0, 255);
led_bucket[1]=CRGB (0, 0, 255);
}
else if((s>=400)&&(s<=450))
{
led_bucket[0]=CRGB (153, 153, 0);
led_bucket[1]=CRGB (153, 153, 0);
}
else if((s>=350)&&(s<=400))
{
led_bucket[0]=CRGB (255, 50, 255);
led_bucket[1]=CRGB (255, 50, 255);
}
else if((s>=300)&&(s<=350))
{
led_bucket[0]=CRGB (10, 25, 217);
led_bucket[1]=CRGB (10, 25, 217);
}
else if((s>=276)&&(s<=300))
{
led_bucket[0]=CRGB (50, 50, 150);
led_bucket[1]=CRGB (50, 50, 150);
}
else if((s>=250)&&(s<=275))
{
led_bucket[0]=CRGB (230, 0, 10);
led_bucket[1]=CRGB (230, 0, 10);
}
else if((s>=235)&&(s<=250))
{
led_bucket[0]=CRGB (0, 160, 0);
led_bucket[1]=CRGB (0, 160, 0);
}
else if((s>=200)&&(s<=230))
{
led_bucket[0]=CRGB (1, 0, 1);
led_bucket[1]=CRGB (1, 0, 1);
}
else
{
led_bucket[0] = CRGB ( r,s-100,b);
led_bucket[1] = CRGB ( r,s-100,b);
}
for (int i = 0; i <= (NUM_LEDS-2); i++)
{
led_bucket[NUM_LEDS-1-i] = led_bucket[(NUM_LEDS)-i-2];
leds[NUM_LEDS-1-i] = led_bucket[(NUM_LEDS)-i-2];
}
if(s>=450)
{
s=450;
}
if(s<=100)
{
s=100;
}
for (int i = (450-s)/15; i >=0; i--)
{
leds[NUM_LEDS-i] = CRGB (0, 0, 0);
}
FastLED.show();
delay(25);
}
// }
};
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// Pacifica.h tab
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
#include "Arduino.h"
class Pacifica {
#include <FastLED.h>
#define FASTLED_ALLOW_INTERRUPTS 0
FASTLED_USING_NAMESPACE
#define DATA_PIN 4
#define NUM_LEDS 60
#define MAX_POWER_MILLIAMPS 1200
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
public:
Pacifica(){};
void runPattern();
private:
CRGB leds[NUM_LEDS];
CRGBPalette16 pacifica_palette_1 =
{ 0x000507, 0x000409, 0x00030B, 0x00030D, 0x000210, 0x000212, 0x000114, 0x000117,
0x000019, 0x00001C, 0x000026, 0x000031, 0x00003B, 0x000046, 0x14554B, 0x28AA50 };
CRGBPalette16 pacifica_palette_2 =
{ 0x000507, 0x000409, 0x00030B, 0x00030D, 0x000210, 0x000212, 0x000114, 0x000117,
0x000019, 0x00001C, 0x000026, 0x000031, 0x00003B, 0x000046, 0x0C5F52, 0x19BE5F };
CRGBPalette16 pacifica_palette_3 =
{ 0x000208, 0x00030E, 0x000514, 0x00061A, 0x000820, 0x000927, 0x000B2D, 0x000C33,
0x000E39, 0x001040, 0x001450, 0x001860, 0x001C70, 0x002080, 0x1040BF, 0x2060FF };
void pacifica_loop();
void pacifica_one_layer( CRGBPalette16& p, uint16_t cistart, uint16_t wavescale, uint8_t bri, uint16_t ioff );
void pacifica_add_whitecaps();
void pacifica_deepen_colors();
};
void Pacifica::runPattern()
{
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); FastLED.setMaxPowerInVoltsAndMilliamps( 5, MAX_POWER_MILLIAMPS);
FastLED.setBrightness(200);
EVERY_N_MILLISECONDS( 20) {
pacifica_loop();
FastLED.show();
}
}
void Pacifica::pacifica_loop()
{
static uint16_t sCIStart1, sCIStart2, sCIStart3, sCIStart4;
static uint32_t sLastms = 0;
uint32_t ms = GET_MILLIS();
uint32_t deltams = ms - sLastms;
sLastms = ms;
uint16_t speedfactor1 = beatsin16(3, 179, 269);
uint16_t speedfactor2 = beatsin16(4, 179, 269);
uint32_t deltams1 = (deltams * speedfactor1) / 256;
uint32_t deltams2 = (deltams * speedfactor2) / 256;
uint32_t deltams21 = (deltams1 + deltams2) / 2;
sCIStart1 += (deltams1 * beatsin88(1011,10,13));
sCIStart2 -= (deltams21 * beatsin88(777,8,11));
sCIStart3 -= (deltams1 * beatsin88(501,5,7));
sCIStart4 -= (deltams2 * beatsin88(257,4,6));
fill_solid( leds, NUM_LEDS, CRGB( 2, 6, 10));
pacifica_one_layer( pacifica_palette_1, sCIStart1, beatsin16( 3, 11 * 256, 14 * 256), beatsin8( 10, 70, 130), 0-beat16( 301) );
pacifica_one_layer( pacifica_palette_2, sCIStart2, beatsin16( 4, 6 * 256, 9 * 256), beatsin8( 17, 40, 80), beat16( 401) );
pacifica_one_layer( pacifica_palette_3, sCIStart3, 6 * 256, beatsin8( 9, 10,38), 0-beat16(503));
pacifica_one_layer( pacifica_palette_3, sCIStart4, 5 * 256, beatsin8( 8, 10,28), beat16(601));
pacifica_add_whitecaps();
pacifica_deepen_colors();
}
void Pacifica::pacifica_one_layer( CRGBPalette16& p, uint16_t cistart, uint16_t wavescale, uint8_t bri, uint16_t ioff)
{
uint16_t ci = cistart;
uint16_t waveangle = ioff;
uint16_t wavescale_half = (wavescale / 2) + 20;
for( uint16_t i = 0; i < NUM_LEDS; i++) {
waveangle += 250;
uint16_t s16 = sin16( waveangle ) + 32768;
uint16_t cs = scale16( s16 , wavescale_half ) + wavescale_half;
ci += cs;
uint16_t sindex16 = sin16( ci) + 32768;
uint8_t sindex8 = scale16( sindex16, 240);
CRGB c = ColorFromPalette( p, sindex8, bri, LINEARBLEND);
leds[i] += c;
}
}
void Pacifica::pacifica_add_whitecaps()
{
uint8_t basethreshold = beatsin8( 9, 55, 65);
uint8_t wave = beat8( 7 );
for( uint16_t i = 0; i < NUM_LEDS; i++) {
uint8_t threshold = scale8( sin8( wave), 20) + basethreshold;
wave += 7;
uint8_t l = leds[i].getAverageLight();
if( l > threshold) {
uint8_t overage = l - threshold;
uint8_t overage2 = qadd8( overage, overage);
leds[i] += CRGB( overage, overage2, qadd8( overage2, overage2));
}
}
}
void Pacifica::pacifica_deepen_colors()
{
for( uint16_t i = 0; i < NUM_LEDS; i++) {
leds[i].blue = scale8( leds[i].blue, 145);
leds[i].green= scale8( leds[i].green, 200);
leds[i] |= CRGB( 2, 5, 7);
}
}
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// Rgb_reactive.h tab
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
#include "Arduino.h"
class Rgb_reactive {
public:
Rgb_reactive(){};
void runPattern();
private:
#include <FastLED.h>
int r=152;
int g=0;
int b=10;
#define LED_PIN 4 //CONNECT DATA PIN OF PIXEL WITH 5 NUMBER PIN OF ARDUINO
#define NUM_LEDS 60 //CHANGE THE VALUE IF YOU WANT TO USE DIFFRENT NUMBER OF LED IN YOUR STRIP,HERE IN MY STRIP NUMBER OF LED IS 60 SO I SET IT 60.
CRGB leds[NUM_LEDS];
CRGB led[NUM_LEDS];
int s=0;
void rgb_reactiveloop();
};
void Rgb_reactive::runPattern() {
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
for (int i = NUM_LEDS/2; i >= 0; i--)
{
leds[i] = CRGB ( r,g,b);
leds[NUM_LEDS-i] = CRGB (r,g,b );
delay(40);
FastLED.show();
}
Serial.begin(9600);
pinMode(A0,INPUT);
rgb_reactiveloop();
}
// 200 s<250 s>340 500
void Rgb_reactive::rgb_reactiveloop()
{
s=analogRead(A0);
// Serial.println(s);
// delay(50);
if((s>=469)&&(s<=520))
{
leds[(NUM_LEDS/2)-1]=CRGB (0, 0, 255);
leds[NUM_LEDS/2]=CRGB (0, 0, 255);
}
else if((s>=428)&&(s<=468))
{
leds[(NUM_LEDS/2)-1]=CRGB (153, 153, 0);
leds[NUM_LEDS/2]=CRGB (153, 153, 0);
}
else if((s>=386)&&(s<=427))
{
leds[(NUM_LEDS/2)-1]=CRGB (255, 50, 255);
leds[NUM_LEDS/2]=CRGB (255, 50, 255);
}
else if((s>=345)&&(s<=385))
{
leds[(NUM_LEDS/2)-1]=CRGB (10, 25, 217);
leds[NUM_LEDS/2]=CRGB (10, 25, 217);
}
else if((s>=228)&&(s<=238))
{
leds[(NUM_LEDS/2)-1]=CRGB (50, 50, 150);
leds[NUM_LEDS/2]=CRGB (50, 50, 150);
}
else if((s>=217)&&(s<=227))
{
leds[(NUM_LEDS/2)-1]=CRGB (230, 0, 10);
leds[NUM_LEDS/2]=CRGB (230, 0, 10);
}
else if((s>=205)&&(s<=216))
{
leds[(NUM_LEDS/2)-1]=CRGB (0, 160, 0);
leds[NUM_LEDS/2]=CRGB (0, 160, 0);
}
else if((s>=194)&&(s<=204))
{
leds[(NUM_LEDS/2)-1]=CRGB (1, 0, 1);
leds[NUM_LEDS/2]=CRGB (1, 0, 1);
}
else
{
leds[(NUM_LEDS/2)-1] = CRGB ( r,s-100,b);
leds[NUM_LEDS/2] = CRGB ( r,s-100,b);
}
for (int i = 0; i <= ((NUM_LEDS/2)-2); i++)
{
leds[i] = leds[i+1];
leds[NUM_LEDS-1-i] = leds[(NUM_LEDS)-i-2];
}
FastLED.show();
delay(25);
}
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// Vu_meter.h tab
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
#include "Arduino.h"
class Vu_meter {
public:
Vu_meter(){};
void runPattern();
private:
#include <FastLED.h>
int r=152;
int g=0;
int b=10;
#define LED_PIN 4 //CONNECT DATA PIN OF PIXEL WITH 5 NUMBER PIN OF ARDUINO
#define NUM_LEDS 60 //CHANGE THE VALUE IF YOU WANT TO USE DIFFRENT NUMBER OF LED IN YOUR STRIP,HERE IN MY STRIP NUMBER OF LED IS 30 SO I SET IT 30.
CRGB leds[NUM_LEDS];
CRGB led[NUM_LEDS];
CRGB led_bucket[NUM_LEDS];
int s=0;
void vu_meterloop();
};
void Vu_meter::runPattern() {
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
for (int i = NUM_LEDS; i >= 0; i--)
{
led_bucket[NUM_LEDS-i] = CRGB (r,g,b );
delay(40);
FastLED.show();
}
Serial.begin(9600);
pinMode(A0,INPUT);
vu_meterloop();
}
void Vu_meter::vu_meterloop()
{
s=analogRead(A0);
// Serial.println(s);
// delay(50);
if((s>=450)&&(s<=550))
{
led_bucket[0]=CRGB (0, 0, 255);
led_bucket[1]=CRGB (0, 0, 255);
}
else if((s>=400)&&(s<=450))
{
led_bucket[0]=CRGB (153, 153, 0);
led_bucket[1]=CRGB (153, 153, 0);
}
else if((s>=351)&&(s<=400))
{
led_bucket[0]=CRGB (255, 50, 255);
led_bucket[1]=CRGB (255, 50, 255);
}
else if((s>=340)&&(s<=350))
{
led_bucket[0]=CRGB (10, 25, 217);
led_bucket[1]=CRGB (10, 25, 217);
}
else if((s>=231)&&(s<=234))
{
led_bucket[0]=CRGB (50, 50, 150);
led_bucket[1]=CRGB (50, 50, 150);
}
else if((s>=225)&&(s<=230))
{
led_bucket[0]=CRGB (230, 0, 10);
led_bucket[1]=CRGB (230, 0, 10);
}
else if((s>=215)&&(s<=224))
{
led_bucket[0]=CRGB (0, 160, 0);
led_bucket[1]=CRGB (0, 160, 0);
}
else if((s>=200)&&(s<=210))
{
led_bucket[0]=CRGB (1, 0, 1);
led_bucket[1]=CRGB (1, 0, 1);
}
else
{
led_bucket[0] = CRGB ( r,s-100,b);
led_bucket[1] = CRGB ( r,s-100,b);
}
for (int i = 0; i <= (NUM_LEDS-2); i++)
{
led_bucket[NUM_LEDS-1-i] = led_bucket[(NUM_LEDS)-i-2];
leds[NUM_LEDS-1-i] = led_bucket[(NUM_LEDS)-i-2];
}
if(s>=450)
{
s=450;
}
if(s<=100)
{
s=100;
}
for (int i = (450-s)/20; i >=0; i--)
{
leds[NUM_LEDS-i] = CRGB (0, 0, 0);
}
FastLED.show();
delay(25);
}
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// goodgoodmicthree.h tab
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
#include "Arduino.h"
//Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
class Gamethree *myGamethree;
class Gamethree
{
#include <Adafruit_NeoPixel.h>
#ifdef AVR
#include <avr/power.h>
#endif
#define PIN 4
#define NUMPIXELS 60
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int outputValue=0;
int rememberOutputValue;
int randNumber;
int counter = 0;
int loopCounter = 0;
public:
void setup() {
// put your setup code here, to run once:
pixels.begin();
randomSeed(analogRead(0));
Serial.begin(9600);
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) { // uint32_t
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3,0);
}
if(WheelPos < 170) {
WheelPos -= 85;
return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3,0);
}
WheelPos -= 170;
return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0,0);
}
void loop() {
// put your main code here, to run repeatedly
// read the analog in value 100 times and count high levels
int sensorValue;
counter = 0;
for (int i=0; i < 100; i++){
sensorValue = analogRead(A0);
if( sensorValue > 340 || sensorValue < 235 ) counter++;
}
if(map(counter, 0, 60, 0, 29) > outputValue)outputValue = map(counter, 0, 40, 0, 29);
else if(loopCounter %2 == 0)outputValue-=1;
if(outputValue < 0) outputValue = 0;
if(outputValue > 60) outputValue = 60;
if(loopCounter % 60 == 0)randNumber = random(255);
loopCounter++;
// clear all LEDs
for(int i=0;i < NUMPIXELS;i++){
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(0,0,0, 255));
}
if(rememberOutputValue != outputValue){
for(int i=60;i > (60-outputValue) || (outputValue == 60 && i == 0);i--){
pixels.setPixelColor(i, Wheel((randNumber) & 255));
}
pixels.show(); // This sends the updated pixel color to the hardware
}
rememberOutputValue = outputValue;
}
};