TechKiwiGadgets
Published © CC BY-ND

LED Gyro Sphere

A unique, cool interactive LED sphere using a gyro and sound sensors create a colorful fun interactive gadget.

IntermediateFull instructions provided1,587
LED Gyro Sphere

Things used in this project

Hardware components

Teensy 3.5
Teensy 3.5
×1

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Thingiverse

https://www.thingiverse.com/thing:2776550

Schematics

LED Gyro Sphere Circuit

A unique, cool interactive LED Sphere using a Gyro and Sound sensors create a colorful fun interactive gadget.

Code

LED Gyro Sphere

C/C++
A unique, cool interactive LED Sphere using a Gyro and Sound sensors create a colorful fun interactive gadget.
/* LED Gyro Sphere Teesy - TechKiwiGadgets Feb 2018
 *  
 *  V5 - Major Update of Hardware and Capability
 *      Addition of Teensy 3.6 
 *      Upgrade Power Pack to 4400mha
 *      Reposition Gyro to ensure aligned to horizontal access when stationary
 */

/* ============================================
I2Cdev device library code is placed under the MIT license
Copyright (c) 2012 Jeff Rowberg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
===============================================
*/


#include <Audio.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioInputAnalog         adc1;           //xy=164,95
AudioAnalyzePeak         peak1;          //xy=317,123
AudioConnection          patchCord1(adc1, peak1);




//**********************************************************
 // MPU-6050 Short Example Sketch
// By Arduino User JohnChi
// August 17, 2014
// Public Domain
#include<Wire.h>


const int MPU_addr=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;

// WS2182 LED Driver Library Setup *************************************************************************
#include "FastLED.h"
// How many leds in your strip?
#define NUM_LEDS 130 // Note: First LED is address 0
#define DATA_PIN 33 // Note: Teensy D33 used to control LED chain
#define FASTLED_ALLOW_INTERRUPTS 0 

int t1 = 20; // Delay in Milliseconds for startup routine

// Define the array of leds
CRGB leds[NUM_LEDS];

// Smoothing Variables for LPF
const float alpha = 0.98; 
int smoothedX = 17000;
int smoothedY = 1000;
int smoothedZ = 10;
int gX = 57; // Pointer for Menu 5 option first LED on Xaxis in centre
int gY = 0; // Pointer for Menu 5 option

int i = 0; // Spiral variable

int xb;
int yb;
int zb;

int mic = 0; // Mic value read from A12
int soundthreshold = 20; // Minimum level threshold for fisr LED
int monoPeak = 0; // Measure of Peak input Audio
int td = 120; // Sound delay variable
int tsr = 224; // Sound delay variable
int sr1 = 300; // Delay in SoundRing
int srctr = 0; // Soundring counter
int srs = 200; // Sound Ring Delay
int nctr = 9; // Count down digits to zero

int Znum; // color digits

int clr4;
int clr5;
int clr6;

#define DC_OFFSET  0  // DC offset in mic signal 


int Xdiff = 0; // Used to track the difference between baselib=ne Gyro and current readings
int Ydiff = 0;
int Zdiff = 0;

int osX = 18000; // This is Gyro Offset
int osY = 18000; // This is Gyro Offset
int osZ = 18000; // This is Gyro Offset range of -17700 to 15200 therefore normalised to 32900 range by adding 17700


float josX = 0.014; // Used to convert Gyro outputs to number below 255 
float josY = 0.014; // Used to convert Gyro outputs to number below 255 
float josZ = 0.014; // Used to convert Gyro outputs to number below 255 

int Xcol = 0; // Final Gyro Color value
int Ycol = 0; // Final Gyro Color value
int Zcol = 0; // Final Gyro Color value

int Xvar = 0; // Variation from baseline
int Yvar = 0; // Variation from baseline
int Zvar = 0; // Variation from baseline

/*
8. X Plane unit of change    1093.75
8. Y Plane unit of change   1750
8. Z Plane unit of change   1750
*/
int Xinc = 1094; // Incremental value for each LED transition
int Yinc = 1750; // Incremental value for each LED transition
int Zinc = 1750; // Incremental value for each LED transition

int Xnormalise;
int Ynormalise;
int Znormalise;

// Menu Selection
int menu = 1; // Random Dot Pattern

int direct; // Temp direction variable

int g = 0; // Scratch variable
int d1 = 50; // Delay for LED effects
int d2 = 2000; // Delay for LED effects
int d4 = 500; // Delay for LED effects
int d5 = 200; // Delay for LED effects
int d6 = 2000; // Delay for LED effects
boolean cal = false; // Callibrate delay

/* Dot Snakes Array int dot[4][5] = { // Setup Location for 4 Dot Snakes 4 dots long
 *  Dot Arrays track location of a item
    Dot number identifier for each Dot
    0. LED Position  = 0-129
    1. Current Direction  = 0-7
    2. Prev Position = 0-129
    3. Prev Prev Position= 1-129
0 = Up
1 = Up Right  
2 = Right 
3 =  Down Right 
4 = Down
5 = Down Left
6 = Left
7 = Up Left
*/
int dot[4][5] = { // Setup Location for 4 Dot Snakes 4 dots long
      {5 , 5, 18, 34, 50},
      {1 , 5, 10, 26, 42},
      {126 , 0, 117, 101, 85},
      {122 , 0, 108, 92, 76}
      
};


int dt = 0;  // Setup Location for dot on top 


// Setup array for Sound bar graph

/* Dot Arrays track location of a item
    Dot number identifier for each Dot
    0. LED Position  = 0-129
    1. Current Direction  = 0-7
    2. Prev Position = 0-129
    3. Prev Prev Position= 1-129
0 = Up
1 = Up Right  
2 = Right 
3 =  Down Right 
4 = Down
5 = Down Left
6 = Left
7 = Up Left
*/

int sb[10] = {0, 1, 9, 25, 41, 57, 73, 89}; // Used for Sound Effect
int scntr = 0; // Counts the incremetal change around the sound effect (16 locations)

/* ************************************************************************
 *  The pixel Array carries the Coordinates of each LED in sequential order
LED Position
0 = Up
1 = Up Right  
2 = Right 
3 =  Down Right 
4 = Down
5 = Down Left
6 = Left
7 = Up Left
8 = LED Row Number
9 = LED Row Position Number
10 - X Axis Gyro Ref
11 - Y Axis Gyro Ref
12 - Z Axis Gyro Ref
****************************************************************************
*/
  
const int pixel[130][13]  = {
{  5 , 6 , 7 , 8 , 1 , 2 , 3 , 4 , 1 , 1 , 17668 , 18042 , 26  },
{ 0 , 7 , 8 , 9 , 10  , 11  , 2 , 3 , 2 , 1 , 13593 , 19330 , 945 },
{ 0 , 8 , 1 , 11  , 12  , 13  , 3 , 4 , 2 , 2 , 12765 , 14870 , 1500  },
{ 0 , 1 , 2 , 13  , 14  , 15  , 4 , 5 , 2 , 3 , 16290 , 12859 , 1015  },
{ 0 , 2 , 3 , 15  , 16  , 17  , 5 , 6 , 2 , 4 , 19352 , 12049 , 1121  },
{ 0 , 3 , 4 , 17  , 18  , 19  , 6 , 7 , 2 , 5 , 21402 , 15641 , 303 },
{ 0 , 4 , 5 , 19  , 20  , 21  , 7 , 8 , 2 , 6 , 22739 , 17763 , 390 },
{ 0 , 5 , 6 , 21  , 22  , 23  , 8 , 1 , 2 , 7 , 20164 , 20767 , 218 },
{ 0 , 6 , 7 , 23  , 24  , 9 , 1 , 2 , 2 , 8 , 16480 , 21065 , 399 },
{ 1 , 8 , 24  , 40  , 25  , 26  , 10  , 1 , 3 , 1 , 11649 , 22517 , 2345  },
{ 1 , 8 , 9 , 25  , 26  , 27  , 11  , 2 , 3 , 2 , 9928  , 18712 , 2667  },
{ 2 , 1 , 10  , 26  , 27  , 28  , 12  , 2 , 3 , 3 , 8984  , 15608 , 3558  },
{ 2 , 1 , 11  , 27  , 28  , 29  , 13  , 3 , 3 , 4 , 10660 , 11850 , 3618  },
{ 3 , 2 , 12  , 28  , 29  , 30  , 14  , 3 , 3 , 5 , 13153 , 9570  , 3496  },
{ 3 , 2 , 13  , 29  , 30  , 31  , 15  , 4 , 3 , 6 , 15628 , 7918  , 3836  },
{ 4 , 3 , 14  , 30  , 31  , 32  , 16  , 4 , 3 , 7 , 19982 , 7107  , 4119  },
{ 4 , 3 , 15  , 31  , 32  , 33  , 17  , 5 , 3 , 8 , 23846 , 8620  , 3852  },
{ 5 , 4 , 16  , 32  , 33  , 34  , 18  , 5 , 3 , 9 , 25987 , 10631 , 3521  },
{ 5 , 4 , 17  , 33  , 34  , 35  , 19  , 6 , 3 , 10  , 28716 , 13866 , 3929  },
{ 6 , 5 , 18  , 34  , 35  , 36  , 20  , 6 , 3 , 11  , 29138 , 18636 , 3572  },
{ 6 , 5 , 19  , 35  , 36  , 37  , 21  , 7 , 3 , 12  , 27845 , 22257 , 3311  },
{ 7 , 6 , 20  , 36  , 37  , 38  , 22  , 7 , 3 , 13  , 25448 , 24727 , 2888  },
{ 7 , 6 , 21  , 37  , 38  , 39  , 23  , 8 , 3 , 14  , 22405 , 27379 , 3368  },
{ 8 , 7 , 22  , 38  , 39  , 40  , 24  , 8 , 3 , 15  , 17686 , 27918 , 3383  },
{ 8 , 7 , 23  , 39  , 40  , 25  , 25  , 1 , 3 , 16  , 14693 , 26495 , 2947  },
{ 9 , 24  , 40  , 56  , 41  , 42  , 26  , 10  , 4 , 1 , 7984  , 26491 , 7655  },
{ 10  , 9 , 25  , 41  , 42  , 43  , 27  , 11  , 4 , 2 , 5486  , 21616 , 8131  },
{ 11  , 10  , 26  , 42  , 43  , 44  , 28  , 12  , 4 , 3 , 4951  , 16152 , 8431  },
{ 12  , 11  , 27  , 43  , 44  , 45  , 29  , 13  , 4 , 4 , 6181  , 10996 , 9020  },
{ 13  , 12  , 28  , 44  , 45  , 46  , 30  , 14  , 4 , 5 , 10314 , 6130  , 9348  },
{ 14  , 13  , 29  , 45  , 46  , 47  , 31  , 15  , 4 , 6 , 15265 , 3892  , 9042  },
{ 15  , 14  , 30  , 46  , 47  , 48  , 32  , 16  , 4 , 7 , 20306 , 3185  , 9537  },
{ 16  , 15  , 31  , 47  , 48  , 49  , 33  , 17  , 4 , 8 , 24925 , 5285  , 8163  },
{ 17  , 16  , 32  , 48  , 49  , 50  , 34  , 18  , 4 , 9 , 29639 , 9193  , 7858  },
{ 18  , 17  , 33  , 49  , 50  , 51  , 35  , 19  , 4 , 10  , 30917 , 14042 , 6045  },
{ 19  , 18  , 34  , 50  , 51  , 52  , 36  , 20  , 4 , 11  , 32324 , 18572 , 7309  },
{ 20  , 19  , 35  , 51  , 52  , 53  , 37  , 21  , 4 , 12  , 30890 , 23910 , 6993  },
{ 21  , 20  , 36  , 52  , 53  , 54  , 38  , 22  , 4 , 13  , 27434 , 28469 , 7035  },
{ 22  , 21  , 37  , 53  , 54  , 55  , 39  , 23  , 4 , 14  , 22328 , 30706 , 6511  },
{ 23  , 22  , 38  , 54  , 55  , 56  , 40  , 24  , 4 , 15  , 16781 , 30311 , 5820  },
{ 24  , 23  , 39  , 55  , 56  , 41  , 25  , 9 , 4 , 16  , 12755 , 28610 , 5479  },
{ 25  , 40  , 56  , 72  , 57  , 58  , 42  , 26  , 5 , 1 , 7799  , 28586 , 10753 },
{ 26  , 25  , 41  , 57  , 58  , 59  , 43  , 27  , 5 , 2 , 4003  , 21932 , 11245 },
{ 27  , 26  , 42  , 58  , 59  , 60  , 44  , 28  , 5 , 3 , 3408  , 17574 , 11295 },
{ 28  , 27  , 43  , 59  , 60  , 61  , 45  , 29  , 5 , 4 , 5198  , 11321 , 10979 },
{ 29  , 28  , 44  , 60  , 61  , 62  , 46  , 30  , 5 , 5 , 8799  , 5897  , 12116 },
{ 30  , 29  , 45  , 61  , 62  , 63  , 47  , 31  , 5 , 6 , 12895 , 3152  , 13187 },
{ 31  , 30  , 46  , 62  , 63  , 64  , 48  , 32  , 5 , 7 , 20472 , 2534  , 11456 },
{ 32  , 31  , 47  , 63  , 64  , 65  , 49  , 33  , 5 , 8 , 26325 , 4099  , 11774 },
{ 33  , 32  , 48  , 64  , 65  , 66  , 50  , 34  , 5 , 9 , 30549 , 8117  , 10717 },
{ 34  , 33  , 49  , 65  , 66  , 67  , 51  , 35  , 5 , 10  , 33015 , 12909 , 9971  },
{ 35  , 34  , 50  , 66  , 67  , 68  , 52  , 36  , 5 , 11  , 34328 , 19320 , 11192 },
{ 36  , 35  , 51  , 67  , 68  , 69  , 53  , 37  , 5 , 12  , 32750 , 24373 , 10762 },
{ 37  , 36  , 52  , 68  , 69  , 70  , 54  , 38  , 5 , 13  , 29723 , 28479 , 10794 },
{ 38  , 37  , 53  , 69  , 70  , 71  , 55  , 39  , 5 , 14  , 24231 , 32195 , 10756 },
{ 39  , 38  , 54  , 70  , 71  , 72  , 56  , 40  , 5 , 15  , 17745 , 33361 , 11558 },
{ 40  , 39  , 55  , 71  , 72  , 57  , 41  , 25  , 5 , 16  , 12228 , 31904 , 12098 },
{ 41  , 56  , 72  , 88  , 73  , 74  , 58  , 42  , 6 , 1 , 6691  , 28206 , 14789 },
{ 42  , 41  , 57  , 73  , 74  , 75  , 59  , 43  , 6 , 2 , 3615  , 23581 , 15638 },
{ 43  , 42  , 58  , 74  , 75  , 76  , 60  , 44  , 6 , 3 , 3043  , 17960 , 16378 },
{ 44  , 43  , 59  , 75  , 76  , 77  , 61  , 45  , 6 , 4 , 4318  , 12204 , 15523 },
{ 45  , 44  , 60  , 76  , 77  , 78  , 62  , 46  , 6 , 5 , 6727  , 7996  , 15721 },
{ 46  , 45  , 61  , 77  , 78  , 79  , 63  , 47  , 6 , 6 , 11867 , 3456  , 15325 },
{ 47  , 46  , 62  , 78  , 79  , 80  , 64  , 48  , 6 , 7 , 17541 , 2218  , 15737 },
{ 48  , 47  , 63  , 79  , 80  , 81  , 65  , 49  , 6 , 8 , 24905 , 3359  , 16112 },
{ 49  , 48  , 64  , 80  , 81  , 82  , 66  , 50  , 6 , 9 , 30165 , 6733  , 14977 },
{ 50  , 49  , 65  , 81  , 82  , 83  , 67  , 51  , 6 , 10  , 34142 , 13037 , 15350 },
{ 51  , 50  , 66  , 82  , 83  , 84  , 68  , 52  , 6 , 11  , 34749 , 18118 , 14834 },
{ 52  , 51  , 67  , 83  , 84  , 85  , 69  , 53  , 6 , 12  , 33417 , 24448 , 14899 },
{ 53  , 52  , 68  , 84  , 85  , 86  , 70  , 54  , 6 , 13  , 29458 , 30060 , 14355 },
{ 54  , 53  , 69  , 85  , 86  , 87  , 71  , 55  , 6 , 14  , 25152 , 32749 , 14340 },
{ 55  , 54  , 70  , 86  , 87  , 88  , 72  , 56  , 6 , 15  , 17874 , 33799 , 14465 },
{ 56  , 55  , 71  , 87  , 88  , 73  , 57  , 41  , 6 , 16  , 12293 , 32446 , 14952 },
{ 57  , 72  , 88  , 104 , 89  , 90  , 74  , 58  , 7 , 1 , 5086  , 25927 , 19638 },
{ 58  , 57  , 73  , 89  , 90  , 91  , 75  , 59  , 7 , 2 , 3880  , 22322 , 19960 },
{ 59  , 58  , 74  , 90  , 91  , 92  , 76  , 60  , 7 , 3 , 3236  , 15215 , 19354 },
{ 60  , 59  , 75  , 91  , 92  , 93  , 77  , 61  , 7 , 4 , 6407  , 8345  , 19193 },
{ 61  , 60  , 76  , 92  , 93  , 94  , 78  , 62  , 7 , 5 , 12490 , 4134  , 21831 },
{ 62  , 61  , 77  , 93  , 94  , 95  , 79  , 63  , 7 , 6 , 21073 , 2166  , 19120 },
{ 63  , 62  , 78  , 94  , 95  , 96  , 80  , 64  , 7 , 7 , 26857 , 4681  , 20849 },
{ 64  , 63  , 79  , 95  , 96  , 97  , 81  , 65  , 7 , 8 , 30594 , 7112  , 19188 },
{ 65  , 64  , 80  , 96  , 97  , 98  , 82  , 66  , 7 , 9 , 34260 , 13248 , 19078 },
{ 66  , 65  , 81  , 97  , 98  , 99  , 83  , 67  , 7 , 10  , 34359 , 22135 , 19412 },
{ 67  , 66  , 82  , 98  , 99  , 100 , 84  , 68  , 7 , 11  , 31790 , 27246 , 20214 },
{ 68  , 67  , 83  , 99  , 100 , 101 , 85  , 69  , 7 , 12  , 30688 , 27752 , 21846 },
{ 69  , 68  , 84  , 100 , 101 , 102 , 86  , 70  , 7 , 13  , 23430 , 33203 , 20115 },
{ 70  , 69  , 85  , 101 , 102 , 103 , 87  , 71  , 7 , 14  , 16897 , 34111 , 18241 },
{ 71  , 70  , 86  , 102 , 103 , 104 , 88  , 72  , 7 , 15  , 10035 , 31373 , 18584 },
{ 72  , 71  , 87  , 103 , 104 , 89  , 73  , 57  , 7 , 16  , 7134  , 28538 , 20044 },
{ 73  , 88  , 104 , 120 , 105 , 106 , 90  , 74  , 8 , 1 , 7873  , 26821 , 24225 },
{ 74  , 73  , 89  , 105 , 106 , 107 , 91  , 75  , 8 , 2 , 5306  , 22175 , 23077 },
{ 75  , 74  , 90  , 106 , 107 , 108 , 92  , 76  , 8 , 3 , 6201  , 16463 , 25588 },
{ 76  , 75  , 91  , 107 , 108 , 109 , 93  , 77  , 8 , 4 , 8490  , 13819 , 27891 },
{ 77  , 76  , 92  , 108 , 109 , 110 , 94  , 78  , 8 , 5 , 14794 , 5323  , 25643 },
{ 78  , 77  , 93  , 109 , 110 , 111 , 95  , 79  , 8 , 6 , 18490 , 5394  , 26483 },
{ 79  , 78  , 94  , 110 , 111 , 112 , 96  , 80  , 8 , 7 , 23016 , 6832  , 27352 },
{ 80  , 79  , 95  , 111 , 112 , 113 , 97  , 81  , 8 , 8 , 29410 , 9423  , 25387 },
{ 81  , 80  , 96  , 112 , 113 , 114 , 98  , 82  , 8 , 9 , 31652 , 13833 , 25081 },
{ 82  , 81  , 97  , 113 , 114 , 115 , 99  , 83  , 8 , 10  , 32588 , 19987 , 24888 },
{ 83  , 82  , 98  , 114 , 115 , 116 , 100 , 84  , 8 , 11  , 30446 , 26981 , 23327 },
{ 84  , 83  , 99  , 115 , 116 , 117 , 101 , 85  , 8 , 12  , 23286 , 31892 , 23080 },
{ 85  , 84  , 100 , 116 , 117 , 118 , 102 , 86  , 8 , 13  , 15759 , 31983 , 23686 },
{ 86  , 85  , 101 , 117 , 118 , 119 , 103 , 87  , 8 , 14  , 11992 , 30739 , 23612 },
{ 87  , 86  , 102 , 118 , 119 , 120 , 104 , 88  , 8 , 15  , 7613  , 28001 , 22028 },
{ 88  , 87  , 103 , 119 , 120 , 105 , 89  , 73  , 8 , 16  , 5508  , 18301 , 25441 },
{ 89  , 104 , 120 , 128 , 128 , 121 , 106 , 90  , 9 , 1 , 10407 , 17869 , 30098 },
{ 90  , 89  , 105 , 128 , 121 , 122 , 107 , 91  , 9 , 2 , 11177 , 16045 , 30448 },
{ 91  , 90  , 106 , 121 , 121 , 122 , 108 , 92  , 9 , 3 , 12933 , 12240 , 30229 },
{ 92  , 91  , 107 , 121 , 122 , 123 , 109 , 93  , 9 , 4 , 15426 , 10243 , 29959 },
{ 93  , 92  , 108 , 122 , 122 , 123 , 110 , 94  , 9 , 5 , 18541 , 9647  , 29972 },
{ 94  , 93  , 109 , 122 , 123 , 124 , 111 , 95  , 9 , 6 , 21995 , 11101 , 30517 },
{ 95  , 94  , 110 , 123 , 123 , 124 , 112 , 96  , 9 , 7 , 24772 , 13965 , 30775 },
{ 96  , 95  , 111 , 123 , 124 , 125 , 113 , 97  , 9 , 8 , 26122 , 17802 , 30895 },
{ 97  , 96  , 112 , 124 , 124 , 125 , 114 , 98  , 9 , 9 , 27284 , 20536 , 30144 },
{ 98  , 97  , 113 , 124 , 125 , 126 , 115 , 99  , 9 , 10  , 25751 , 23164 , 30278 },
{ 99  , 98  , 114 , 125 , 125 , 126 , 116 , 100 , 9 , 11  , 24160 , 23624 , 30835 },
{ 100 , 99  , 115 , 125 , 126 , 127 , 117 , 101 , 9 , 12  , 22398 , 25482 , 30374 },
{ 101 , 100 , 116 , 126 , 126 , 127 , 118 , 102 , 9 , 13  , 18869 , 26657 , 29832 },
{ 102 , 101 , 117 , 126 , 127 , 128 , 119 , 103 , 9 , 14  , 16163 , 26034 , 29940 },
{ 103 , 102 , 118 , 127 , 127 , 128 , 120 , 104 , 9 , 15  , 12348 , 23941 , 29748 },
{ 104 , 103 , 119 , 127 , 128 , 121 , 105 , 89  , 9 , 16  , 10088 , 24052 , 28396 },
{ 106 , 105 , 128 , 127 , 129 , 123 , 122 , 107 , 10  , 1 , 14631 , 20420 , 31622 },
{ 108 , 107 , 121 , 128 , 129 , 124 , 123 , 109 , 10  , 2 , 17492 , 18135 , 32370 },
{ 110 , 109 , 122 , 121 , 129 , 125 , 124 , 111 , 10  , 3 , 23254 , 15567 , 31552 },
{ 112 , 111 , 123 , 122 , 129 , 126 , 125 , 113 , 10  , 4 , 25852 , 18745 , 30702 },
{ 114 , 113 , 124 , 123 , 129 , 127 , 126 , 115 , 10  , 5 , 24787 , 21138 , 30845 },
{ 116 , 115 , 125 , 124 , 129 , 128 , 127 , 117 , 10  , 6 , 23662 , 24538 , 30109 },
{ 118 , 117 , 126 , 125 , 129 , 121 , 128 , 119 , 10  , 7 , 21269 , 25859 , 30134 },
{ 120 , 119 , 127 , 126 , 129 , 122 , 121 , 105 , 10  , 8 , 17778 , 25113 , 30673 },
{ 121 , 128 , 127 , 126 , 125 , 124 , 123 , 122 , 11  , 1 , 20604 , 19047 , 32659 }

  };

elapsedMillis fps;

void setup(){
  AudioMemory(4);  
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
  Serial.begin(115200);

  // WS2182 LED Driver Setup
  LEDS.addLeds<WS2812,DATA_PIN,GRB>(leds,NUM_LEDS).setCorrection( TypicalLEDStrip ); // Default if RGB for this however may vary dependent on LED manufacturer
  LEDS.setBrightness(5); //Set brightness of LEDs here
  // limit my draw to 1A at 5v of power draw
  FastLED.setMaxPowerInVoltsAndMilliamps(5,100);

  FastLED.setDither(0); // Turns of Auto Dithering function to remove flicker
  
    // Setup Input Mode and Select Push Buttons
    pinMode(34,INPUT_PULLUP); // Mode Button
    pinMode(35,INPUT_PULLUP); // Mode Button  

  // Clear LEDs
  for (int g = 0; g < 10; g++) {
     leds[g] = CRGB::Black;
    FastLED.show();
  }


clearsphere(); // Clear any LEDs left over from reset

}

void loop(){
  
buttoncheck(); // Check for user input
  
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);  // starting with register 0x3B (GYRO_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr,6,true);  // request a total of 6 registers

 /* 
  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)     
  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
  GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
  GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
  GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
*/

  GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
  GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
  GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)

  
// Apply Low Pass Filter to signal to smooth output from MPU 6050
    smoothedX = (alpha * smoothedX) + ( (1 - alpha) * GyX);
    smoothedY = (alpha * smoothedY) + ( (1 - alpha) * GyY);
    smoothedZ = (alpha * smoothedZ) + ( (1 - alpha) * GyZ);

// Apply filter to MIC output
    mic = abs(analogRead(A12)-DC_OFFSET); 


// Calculate final Gyro Colors for XYZ to RGB

if (abs(smoothedX)*josX < 256) {
    Xcol = abs(smoothedX)*josX;
} else {
  Xcol = 20;
}

if (abs(smoothedY)*josY < 256) {
    Ycol = abs(smoothedY)*josY;
} else {
  Ycol = 20;
}

if (abs(smoothedZ)*josZ < 256) {
    Zcol = abs(smoothedZ)*josZ;
} else {
  Zcol = 20;
}


//    Znum = abs(GyX)*josX; // color for digits
Znum = 160; // Number for Blue

/* At last a stable Audio input circuit !! A2 connected to 0.1uf and SP1 on freetronics Mic

  if (fps > 24) {
    if (peak1.available()) {
      fps = 0;
      int monoPeak = peak1.read() * 10.0;
      Serial.print("|");
      for (int cnt=0; cnt<monoPeak; cnt++) {
        Serial.print(">");
      }
      Serial.println();
    }
  }
*/

/*  
  Serial.print("AcX = "); Serial.print(AcX);
  Serial.print(" | AcY = "); Serial.print(AcY);
  Serial.print(" | AcZ = "); Serial.print(AcZ);
  Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53);  //equation for temperature in degrees C from datasheet
  Serial.print(" | GyX = "); Serial.print(GyX);
  Serial.print(" | GyY = "); Serial.print(GyY);
  Serial.print(" | GyZ = "); Serial.println(GyZ);



  Serial.print(" . Xcol  ");
 Serial.print(abs(smoothedX)*josX);
   Serial.print(" . Ycol  ");
    Serial.print(abs(smoothedY)*josY);
       Serial.print(" . Zcol.  ");
        Serial.println(abs(smoothedZ)*josZ);



  Serial.print(" . Xb  ");
 Serial.print(xb);
   Serial.print(" . sX  ");
    Serial.print(abs(smoothedX));
       Serial.print(" . gX.  ");
        Serial.print(dt);
   
  Serial.print(" . Yb.  ");
  Serial.print(yb);
    Serial.print(" . sY   ");
     Serial.print(abs(smoothedY));
            Serial.print(" . gY   ");
              Serial.print(dt);
    
  Serial.print(" . Zb . ");
   Serial.print(zb);
     Serial.print(" . sZ   ");
      Serial.print(abs(smoothedZ));
             Serial.print(" . gZ   ");
        Serial.println(dt);

  Serial.print(" . Mic . ");
Serial.print(mic);
  Serial.print(" . SMic . ");
        Serial.print(smoothmic);
  Serial.print(" .  . ");        
        Serial.print(soundot[0]);
   Serial.print(" .  . ");       
        Serial.print(soundot[1]);  
   Serial.print(" .  . ");            
        Serial.print(soundot[2]);  
  Serial.print(" .  . ");             
        Serial.println(soundot[3]);

*/



// delay(20);

       Serial.println(monoPeak);


  if (menu == 1) {
    GyroSpirallights(); // All LEDs change color with Gyro attitude
  }
  if (menu == 2 ) {
    Game1(); // Game 1 three bands of LEDs change color with Gyro attitude
  }
  if (menu == 3 ) {
    SoundRingStep(); // Sound activated Rings of Color
  } 
  if (menu == 4 ) {
  SoundEffect7(); // Sound Meter - LED VU Meter using 130 LEDs
  }    
  if (menu == 5 ) {
    DotSnakesSlow(); // Sound Slows LED Snakes down sphere
  } 
  if (menu == 6 ) {
    Colorwash(); // Cool display of all colors in spectrum for th sphere using LED rows
  }

  if (menu == 7 ) {
    GyroSnake(); // Sound Slows LED Snakes down sphere
  } 
  
  if (menu == 8 ) {
    DotSnakes(); // LED Snakes down sphere
  }
  if (menu == 9 ) {
    DotOnTop(); // Single Dot Circle on the top of the sphere that stays on top using Gyro
  }

  

  
 
 
 


}


void testLEDs130() { // For testing Display End to End
  for (int g = 0; g < 130; g++) {
     leds[g] = CRGB::Blue;
    FastLED.show();
    delay(t1);  
 if (g>2) { leds[g-2] = CRGB::Black;} 
    delay(t1);  
    FastLED.show();
  }
  leds[128] = CRGB::Black;
  leds[129] = CRGB::Black;
  FastLED.show();
  
  for (int g = 0; g < 130; g++) {
     leds[g] = CRGB::Red;
    FastLED.show();
    delay(t1);  
 if (g>2) {      leds[g-2] = CRGB::Black;}
    delay(t1);  
    FastLED.show();
  }
  leds[128] = CRGB::Black;
  leds[129] = CRGB::Black;  
  FastLED.show();
  
  for (int g = 0; g < 130; g++) {
     leds[g] = CRGB::Green;
    FastLED.show();
    delay(t1);  
 if (g>2) {      leds[g-2] = CRGB::Black;}
    delay(t1);  
    FastLED.show();
  }
  leds[128] = CRGB::Black;
  leds[129] = CRGB::Black;
  FastLED.show();
  

  for (int g = 0; g < 130; g++) {
     leds[g] = CRGB::HotPink;
    FastLED.show();
    delay(t1);  
 if (g>2) {      leds[g-2] = CRGB::Black;}
    delay(t1);  
    FastLED.show();
  }
  leds[128] = CRGB::Black;
  leds[129] = CRGB::Black;
  FastLED.show();
  
}

//********************************************
// GyroSpirallights 
// *******************************************
void GyroSpirallights() { // GyroLED Snakes down sphere


if (cal == false) { // Display the menu Item
  one();
  cal = true;
}



//fill_solid( &(leds[0]), 130 /*number of leds*/, CHSV( Xcol, 255, 255) );
// fill_rainbow( &(leds[0]), 130 /*led count*/, 5 /*starting hue*/);

fill_solid( &(leds[0]), 1, CHSV( Xcol, 255, 255) );
fill_solid( &(leds[1]), 8 , CHSV( Xcol, 255, 255) );
fill_solid( &(leds[9]), 16 , CHSV( Xcol, 255, 255) );
fill_solid( &(leds[25]), 16, CHSV( Xcol, 255, 255) );
fill_solid( &(leds[41]), 16 , CHSV( Xcol, 255, 255) );
fill_solid( &(leds[57]), 16 , CHSV( Xcol, 255, 255) );
fill_solid( &(leds[73]), 16, CHSV( Xcol, 255, 255) );
fill_solid( &(leds[89]), 16 , CHSV( Xcol, 255, 255) );
fill_solid( &(leds[105]), 16 , CHSV( Xcol, 255, 255) );
fill_solid( &(leds[121]), 8, CHSV( Xcol, 255, 255) );
fill_solid( &(leds[129]), 1 , CHSV( Xcol, 255, 255) );



FastLED.show();

//     Serial.println(Xcol);
}



//********************************************
// Game1  
// *******************************************
void Game1() { // GyroLED Snakes down sphere

if (cal == false) { // Display the menu Item
  two();
  cal = true;
}

// Three Bands
fill_solid( &(leds[0]), 41, CHSV( Xcol, 255, 255) );
fill_solid( &(leds[41]), 48 , CHSV( Ycol, 255, 255) );
fill_solid( &(leds[89]), 41 , CHSV( Zcol, 255, 255) );


FastLED.show();

//     Serial.println(Xcol);
}

//********************************************
// Game2  
// *******************************************
void Game2() { // GyroLED Snakes down sphere

/* Three Bands
fill_solid( &(leds[0]), 41, CHSV( Xcol, 255, 255) );
fill_solid( &(leds[41]), 48 , CHSV( Ycol, 255, 255) );
fill_solid( &(leds[89]), 41 , CHSV( Zcol, 255, 255) );
*/

// 11 Bands of color

fill_solid( &(leds[0]), 1, CHSV( Xcol, 255, 255) );
fill_solid( &(leds[1]), 8 , CHSV( Ycol, 255, 255) );
fill_solid( &(leds[9]), 16 , CHSV( Zcol, 255, 255) );
fill_solid( &(leds[25]), 16, CHSV( Xcol, 255, 255) );
fill_solid( &(leds[41]), 16 , CHSV( Ycol, 255, 255) );
fill_solid( &(leds[57]), 16 , CHSV( Zcol, 255, 255) );
fill_solid( &(leds[73]), 16, CHSV( Xcol, 255, 255) );
fill_solid( &(leds[89]), 16 , CHSV( Ycol, 255, 255) );
fill_solid( &(leds[105]), 16 , CHSV( Zcol, 255, 255) );
fill_solid( &(leds[121]), 8, CHSV( Xcol, 255, 255) );
fill_solid( &(leds[129]), 1 , CHSV( Ycol, 255, 255) );


FastLED.show();

//     Serial.println(Xcol);
}

//********************************************
// Spirallights
// *******************************************
void Spirallights() { // GyroLED Snakes down sphere


    
  if ( i < 10 ) {

//  leds[map(mic,10,250,0,9)].setRGB( (random(255)), (random(255)), (random(255))); 

    
    leds[map(mic,10,1023,0,9)] = CRGB::Blue;
    
    FastLED.show();


    delay(20);
    leds[i] = CRGB::Black;
    FastLED.show();

    
    i++; 
  } else {
  i = 0;
  }

}

//********************************************
// SoundVU 
// *******************************************
void SoundVU() { // At last a stable Audio input circuit !! A2 connected to 0.1uf and SP1 on freetronics Mic

// Blank all LEDs 

fill_solid( &(leds[0]), 130 /*number of leds*/, CHSV( 0, 0, 0) );

/*
 *   // initialize the pixel matrix by setting all LED Anodes and Cathodes to LOW:
  for (int x = 0; x < 13; x++) {
    for (int y = 0; y < 13; y++) {
      pixels[x][y] = LOW;
    }
  }
  
*/


// This works. Suggest writing in a circler around sphere then deleting each column

  if (fps > 24) {
    if (peak1.available()) {
      fps = 0;
      monoPeak = abs((peak1.read() * 180.0)-3);
      if (monoPeak >129) { monoPeak = 129;}      
      Serial.println(monoPeak);
      for (int cnt=0; cnt<monoPeak; cnt++) {

      if (cnt < 50) {    leds[cnt] = CRGB::Blue; } 
      else
      if (cnt < 80) {    leds[cnt] = CRGB::Green; } 
      else {
      leds[cnt] = CRGB::Red; }
    
//        leds[cnt].setRGB( (random(255)), (random(255)), (random(255)));
        FastLED.show();
        
      }
    }
  }
     
}

void buttoncheck() { // Debounce Button Check of Digital Pins 34 and 35 used to navigate menu of effects

        // Increment Menu
      if((digitalRead(34) == LOW ) && (digitalRead(35) == HIGH)){ // Check that one button pushed only
        delay(150); // Debounce by waiting then checking again
        if((digitalRead(34) == LOW) && (digitalRead(35) == HIGH)){
            // Now confirmed legitimate request increment menu variable
            if (menu < 10 ) {
                menu++;
                clearsphere(); // Clear the entire LED Array to Black
                cal = false;
                g = 0;
                i = 0;
             }
        }
      delay(150);
      }
      
      // Decrement Menu
      if((digitalRead(35) == LOW) && (digitalRead(34) == HIGH)){ // Check that one button pushed only
        delay(150); // Debounce by waiting then checking again
        if((digitalRead(35) == LOW) && (digitalRead(34) == HIGH)){
          // Now confirmed legitimate request increment menu variable
          if (menu > 1 ) {
            menu--;
            clearsphere(); // Clear the entire LED Array to Black  
                cal = false;
                g = 0;
                i = 0;      
          }
        }
      delay(150);
      }      
//  Serial.println(menu);     // Temporarily print menu output for testing


}



void clearsphere() { // Clear the entire LED array to black

//  for (int h = 0; h < 130; h++) {
//     leds[h] = CRGB::Black;

fill_solid( &(leds[0]), 130 /*number of leds*/, CHSV( 0, 0, 0) );
    FastLED.show();
//  }

     
}


//********************************************
// GyroSnakes
// *******************************************
void GyroSnake() { // GyroLED Snakes down sphere

if (cal == false) { // Display the menu Item
  seven();
  cal = true;
}

  if ( i < 140 ) {

    if ( i < 130 ) {
      
        leds[i].setRGB( (Xcol), (Ycol), (Zcol)); 
    }
    delay(d1);  
    if (i>9) {
        leds[i-10] = CRGB::Black;
    } 
    FastLED.show();
     
    i++; 
  } else {
  i = 0;
  }
     
}


void nine() {

    leds[33] = CHSV( Znum, 255, 255);
    leds[34] = CHSV( Znum, 255, 255);
    leds[35] = CHSV( Znum, 255, 255);
    leds[49] = CHSV( Znum, 255, 255);
    leds[51] = CHSV( Znum, 255, 255);
    leds[65] = CHSV( Znum, 255, 255);
    leds[66] = CHSV( Znum, 255, 255);
    leds[67] = CHSV( Znum, 255, 255);
//    leds[83] = CHSV( Znum, 255, 255);
    leds[81] = CHSV( Znum, 255, 255);
    leds[99] = CHSV( Znum, 255, 255);
    leds[98] = CHSV( Znum, 255, 255);
    leds[97] = CHSV( Znum, 255, 255);
        
    FastLED.show();

    delay(d6); 



    leds[33] = CRGB::Black;
    leds[34] = CRGB::Black;
    leds[35] = CRGB::Black;
    leds[49] = CRGB::Black;
    leds[51] = CRGB::Black;
    leds[65] = CRGB::Black;
    leds[66] = CRGB::Black;
    leds[67] = CRGB::Black;
    leds[83] = CRGB::Black;
    leds[81] = CRGB::Black;
    leds[99] = CRGB::Black;
    leds[98] = CRGB::Black;
    leds[97] = CRGB::Black;
    
    FastLED.show();
}

void eight() {

    leds[33] = CHSV( Znum, 255, 255);
    leds[34] = CHSV( Znum, 255, 255);
    leds[35] = CHSV( Znum, 255, 255);
    leds[49] = CHSV( Znum, 255, 255);
    leds[51] = CHSV( Znum, 255, 255);
    leds[65] = CHSV( Znum, 255, 255);
    leds[66] = CHSV( Znum, 255, 255);
    leds[67] = CHSV( Znum, 255, 255);
    leds[83] = CHSV( Znum, 255, 255);
    leds[81] = CHSV( Znum, 255, 255);
    leds[99] = CHSV( Znum, 255, 255);
    leds[98] = CHSV( Znum, 255, 255);
    leds[97] = CHSV( Znum, 255, 255);
        
    FastLED.show();

    delay(d6); 



    leds[33] = CRGB::Black;
    leds[34] = CRGB::Black;
    leds[35] = CRGB::Black;
    leds[49] = CRGB::Black;
    leds[51] = CRGB::Black;
    leds[65] = CRGB::Black;
    leds[66] = CRGB::Black;
    leds[67] = CRGB::Black;
    leds[83] = CRGB::Black;
    leds[81] = CRGB::Black;
    leds[99] = CRGB::Black;
    leds[98] = CRGB::Black;
    leds[97] = CRGB::Black;
    
    FastLED.show();
}

void seven() {

    leds[33] = CHSV( Znum, 255, 255);
    leds[34] = CHSV( Znum, 255, 255);
    leds[35] = CHSV( Znum, 255, 255);
    leds[49] = CHSV( Znum, 255, 255);
//    leds[51] = CHSV( Znum, 255, 255);
    leds[65] = CHSV( Znum, 255, 255);
//    leds[66] = CHSV( Znum, 255, 255);
//    leds[67] = CHSV( Znum, 255, 255);
//    leds[83] = CHSV( Znum, 255, 255);
    leds[81] = CHSV( Znum, 255, 255);
//    leds[99] = CHSV( Znum, 255, 255);
//    leds[98] = CHSV( Znum, 255, 255);
    leds[97] = CHSV( Znum, 255, 255);
        
    FastLED.show();

    delay(d6); 



    leds[33] = CRGB::Black;
    leds[34] = CRGB::Black;
    leds[35] = CRGB::Black;
    leds[49] = CRGB::Black;
    leds[51] = CRGB::Black;
    leds[65] = CRGB::Black;
    leds[66] = CRGB::Black;
    leds[67] = CRGB::Black;
    leds[83] = CRGB::Black;
    leds[81] = CRGB::Black;
    leds[99] = CRGB::Black;
    leds[98] = CRGB::Black;
    leds[97] = CRGB::Black;
    
    FastLED.show();
}

void six() {

    leds[33] = CHSV( Znum, 255, 255);
    leds[34] = CHSV( Znum, 255, 255);
    leds[35] = CHSV( Znum, 255, 255);
//    leds[49] = CHSV( Znum, 255, 255);
    leds[51] = CHSV( Znum, 255, 255);
    leds[65] = CHSV( Znum, 255, 255);
    leds[66] = CHSV( Znum, 255, 255);
    leds[67] = CHSV( Znum, 255, 255);
    leds[83] = CHSV( Znum, 255, 255);
    leds[81] = CHSV( Znum, 255, 255);
    leds[99] = CHSV( Znum, 255, 255);
    leds[98] = CHSV( Znum, 255, 255);
    leds[97] = CHSV( Znum, 255, 255);
        
    FastLED.show();

    delay(d6); 



    leds[33] = CRGB::Black;
    leds[34] = CRGB::Black;
    leds[35] = CRGB::Black;
    leds[49] = CRGB::Black;
    leds[51] = CRGB::Black;
    leds[65] = CRGB::Black;
    leds[66] = CRGB::Black;
    leds[67] = CRGB::Black;
    leds[83] = CRGB::Black;
    leds[81] = CRGB::Black;
    leds[99] = CRGB::Black;
    leds[98] = CRGB::Black;
    leds[97] = CRGB::Black;
    
    FastLED.show();
}

void five() {

    leds[33] = CHSV( Znum, 255, 255);
    leds[34] = CHSV( Znum, 255, 255);
    leds[35] = CHSV( Znum, 255, 255);
//    leds[49] = CHSV( Znum, 255, 255);
    leds[51] = CHSV( Znum, 255, 255);
    leds[65] = CHSV( Znum, 255, 255);
    leds[66] = CHSV( Znum, 255, 255);
    leds[67] = CHSV( Znum, 255, 255);
//    leds[83] = CHSV( Znum, 255, 255);
    leds[81] = CHSV( Znum, 255, 255);
    leds[99] = CHSV( Znum, 255, 255);
    leds[98] = CHSV( Znum, 255, 255);
    leds[97] = CHSV( Znum, 255, 255);
        
    FastLED.show();

    delay(d6); 



    leds[33] = CRGB::Black;
    leds[34] = CRGB::Black;
    leds[35] = CRGB::Black;
    leds[49] = CRGB::Black;
    leds[51] = CRGB::Black;
    leds[65] = CRGB::Black;
    leds[66] = CRGB::Black;
    leds[67] = CRGB::Black;
    leds[83] = CRGB::Black;
    leds[81] = CRGB::Black;
    leds[99] = CRGB::Black;
    leds[98] = CRGB::Black;
    leds[97] = CRGB::Black;
    
    FastLED.show();
}

void four() {

    leds[33] = CHSV( Znum, 255, 255);
//    leds[34] = CHSV( Znum, 255, 255);
    leds[35] = CHSV( Znum, 255, 255);
    leds[49] = CHSV( Znum, 255, 255);
    leds[51] = CHSV( Znum, 255, 255);
    leds[65] = CHSV( Znum, 255, 255);
    leds[66] = CHSV( Znum, 255, 255);
    leds[67] = CHSV( Znum, 255, 255);
//    leds[83] = CHSV( Znum, 255, 255);
    leds[81] = CHSV( Znum, 255, 255);
//    leds[99] = CHSV( Znum, 255, 255);
//    leds[98] = CHSV( Znum, 255, 255);
    leds[97] = CHSV( Znum, 255, 255);
        
    FastLED.show();

    delay(d6); 



    leds[33] = CRGB::Black;
    leds[34] = CRGB::Black;
    leds[35] = CRGB::Black;
    leds[49] = CRGB::Black;
    leds[51] = CRGB::Black;
    leds[65] = CRGB::Black;
    leds[66] = CRGB::Black;
    leds[67] = CRGB::Black;
    leds[83] = CRGB::Black;
    leds[81] = CRGB::Black;
    leds[99] = CRGB::Black;
    leds[98] = CRGB::Black;
    leds[97] = CRGB::Black;
    
    FastLED.show();
}

void three() {

    leds[33] = CHSV( Znum, 255, 255);
    leds[34] = CHSV( Znum, 255, 255);
    leds[35] = CHSV( Znum, 255, 255);
    leds[49] = CHSV( Znum, 255, 255);
//    leds[51] = CHSV( Znum, 255, 255);
    leds[65] = CHSV( Znum, 255, 255);
    leds[66] = CHSV( Znum, 255, 255);
    leds[67] = CHSV( Znum, 255, 255);
//    leds[83] = CHSV( Znum, 255, 255);
    leds[81] = CHSV( Znum, 255, 255);
    leds[99] = CHSV( Znum, 255, 255);
    leds[98] = CHSV( Znum, 255, 255);
    leds[97] = CHSV( Znum, 255, 255);
        
    FastLED.show();

    delay(d6); 



    leds[33] = CRGB::Black;
    leds[34] = CRGB::Black;
    leds[35] = CRGB::Black;
    leds[49] = CRGB::Black;
    leds[51] = CRGB::Black;
    leds[65] = CRGB::Black;
    leds[66] = CRGB::Black;
    leds[67] = CRGB::Black;
    leds[83] = CRGB::Black;
    leds[81] = CRGB::Black;
    leds[99] = CRGB::Black;
    leds[98] = CRGB::Black;
    leds[97] = CRGB::Black;
    
    FastLED.show();
}

void two() {

    leds[33] = CHSV( Znum, 255, 255);
    leds[34] = CHSV( Znum, 255, 255);
    leds[35] = CHSV( Znum, 255, 255);
    leds[49] = CHSV( Znum, 255, 255);
//    leds[51] = CHSV( Znum, 255, 255);
    leds[65] = CHSV( Znum, 255, 255);
    leds[66] = CHSV( Znum, 255, 255);
    leds[67] = CHSV( Znum, 255, 255);
    leds[83] = CHSV( Znum, 255, 255);
//    leds[81] = CHSV( Znum, 255, 255);
    leds[99] = CHSV( Znum, 255, 255);
    leds[98] = CHSV( Znum, 255, 255);
    leds[97] = CHSV( Znum, 255, 255);
        
    FastLED.show();

    delay(d6); 


    leds[33] = CRGB::Black;
    leds[34] = CRGB::Black;
    leds[35] = CRGB::Black;
    leds[49] = CRGB::Black;
    leds[51] = CRGB::Black;
    leds[65] = CRGB::Black;
    leds[66] = CRGB::Black;
    leds[67] = CRGB::Black;
    leds[83] = CRGB::Black;
    leds[81] = CRGB::Black;
    leds[99] = CRGB::Black;
    leds[98] = CRGB::Black;
    leds[97] = CRGB::Black;

        FastLED.show();

}

void one() {

    leds[33] = CHSV( Znum, 255, 255);
//    leds[34] = CHSV( Znum, 255, 255);
//    leds[35] = CHSV( Znum, 255, 255);
    leds[49] = CHSV( Znum, 255, 255);
//    leds[51] = CHSV( Znum, 255, 255);
    leds[65] = CHSV( Znum, 255, 255);
//    leds[66] = CHSV( Znum, 255, 255);
//    leds[67] = CHSV( Znum, 255, 255);
//    leds[83] = CHSV( Znum, 255, 255);
    leds[81] = CHSV( Znum, 255, 255);
//    leds[99] = CHSV( Znum, 255, 255);
//    leds[98] = CHSV( Znum, 255, 255);
    leds[97] = CHSV( Znum, 255, 255);
        
    FastLED.show();

    delay(d6); 



    leds[33] = CRGB::Black;
    leds[34] = CRGB::Black;
    leds[35] = CRGB::Black;
    leds[49] = CRGB::Black;
    leds[51] = CRGB::Black;
    leds[65] = CRGB::Black;
    leds[66] = CRGB::Black;
    leds[67] = CRGB::Black;
    leds[83] = CRGB::Black;
    leds[81] = CRGB::Black;
    leds[99] = CRGB::Black;
    leds[98] = CRGB::Black;
    leds[97] = CRGB::Black;
    
    FastLED.show();
}

void zero() {

    leds[33] = CHSV( Znum, 255, 255);
    leds[34] = CHSV( Znum, 255, 255);
    leds[35] = CHSV( Znum, 255, 255);
    leds[49] = CHSV( Znum, 255, 255);
    leds[51] = CHSV( Znum, 255, 255);
    leds[65] = CHSV( Znum, 255, 255);
//    leds[66] = CHSV( Znum, 255, 255);
    leds[67] = CHSV( Znum, 255, 255);
    leds[83] = CHSV( Znum, 255, 255);
    leds[81] = CHSV( Znum, 255, 255);
    leds[99] = CHSV( Znum, 255, 255);
    leds[98] = CHSV( Znum, 255, 255);
    leds[97] = CHSV( Znum, 255, 255);
        
    FastLED.show();

    delay(d6); 



    leds[33] = CRGB::Black;
    leds[34] = CRGB::Black;
    leds[35] = CRGB::Black;
    leds[49] = CRGB::Black;
    leds[51] = CRGB::Black;
    leds[65] = CRGB::Black;
    leds[66] = CRGB::Black;
    leds[67] = CRGB::Black;
    leds[83] = CRGB::Black;
    leds[81] = CRGB::Black;
    leds[99] = CRGB::Black;
    leds[98] = CRGB::Black;
    leds[97] = CRGB::Black;

    FastLED.show();    

}




//********************************************
// Dotsnakes 
// *******************************************

void DotSnakes() {

if (cal == false) { // Display the menu Item
  eight();
  cal = true;
}
 
 //Clear all current LEDs


     leds[dot[0][0]] = CRGB::Black;  // Turn off current LED position
     leds[dot[0][2]] = CRGB::Black;  // Turn off current LED position
     leds[dot[0][3]] = CRGB::Black;  // Turn off current LED position    
     leds[dot[0][4]] = CRGB::Black;  // Turn off current LED position        

     leds[dot[1][0]] = CRGB::Black;  // Turn off current LED position
     leds[dot[1][2]] = CRGB::Black;  // Turn off current LED position
     leds[dot[1][3]] = CRGB::Black;  // Turn off current LED position    
     leds[dot[1][4]] = CRGB::Black;  // Turn off current LED position        

     leds[dot[2][0]] = CRGB::Black;  // Turn off current LED position
     leds[dot[2][2]] = CRGB::Black;  // Turn off current LED position
     leds[dot[2][3]] = CRGB::Black;  // Turn off current LED position    
     leds[dot[2][4]] = CRGB::Black;  // Turn off current LED position        

     leds[dot[3][0]] = CRGB::Black;  // Turn off current LED position
     leds[dot[3][2]] = CRGB::Black;  // Turn off current LED position
     leds[dot[3][3]] = CRGB::Black;  // Turn off current LED position    
     leds[dot[3][4]] = CRGB::Black;  // Turn off current LED position        
     FastLED.show(); 
     
     // Dot 0 **********************************************************

    
     // Randomly change direction of Dot
  
     direct = random8(8); // Randomly determine new direction

     // Check not going backwards    
     while ((abs(dot[0][1] - direct)) == 4){
        direct = random8(8); // Randomly determine new direction
     }
     
     dot[0][1] = direct; // Store value in array
    


    // Update position of data based on new direction before displaying
     dot[0][4] = dot[0][3]; // Store prevprev into prevprevprev location
     dot[0][3] = dot[0][2]; // Store prev into prevprev location
     dot[0][2] = dot[0][0]; // Store current into prev location   
      
     dot[0][0]= pixel[dot[0][0]][dot[0][1]]; // Use  function to read data back from array in Progam Memory




    // Dot 1**********************************************************


     // Randomly change direction of Dot
     direct = random8(8); // Randomly determine new direction
     // Check not going backwards    
     while ((abs(dot[1][1] - direct)) == 4){
        direct = random8(8); // Randomly determine new direction
     }
    
     dot[1][1] = direct; // Modify lead dot position and store value in array

     


    // Update position of data based on new direction before displaying
     dot[1][4] = dot[1][3]; // Store prevprev into prevprevprev location
     dot[1][3] = dot[1][2]; // Store prev into prevprev location
     dot[1][2] = dot[1][0]; // Store current into prev location   

     dot[1][0]= pixel[dot[1][0]][dot[1][1]];  // Use  function to read data back from array in Progam Memory



    
    // Dot 2 *****************************************  


     // Randomly change direction of Dot
     direct = random8(8); // Randomly determine new direction
     // Check not going backwards    
     while ((abs(dot[2][1] - direct)) == 4){
        direct = random8(8); // Randomly determine new direction
     }
     
     dot[2][1] = direct; // Store value in array

     
 

      // Update position of data based on new direction before displaying
       dot[2][4] = dot[2][3]; // Store prevprev into prevprevprev location
       dot[2][3] = dot[2][2]; // Store prev into prevprev location
       dot[2][2] = dot[2][0]; // Store current into prev location       
     
     dot[2][0]= pixel[dot[2][0]][dot[2][1]];   // Use pgm_read_byte function to read data back from array in Progam Memory




  
    // Dot 3 *****************************************  


     // Randomly change direction of Dot  
     direct = random8(8); // Randomly determine new direction
     // Check not going backwards    
     while ((abs(dot[3][1] - direct)) == 4){
        direct = random8(8); // Randomly determine new direction
     }     
     dot[3][1] = direct; // Store value in array


          


      // Update position of data based on new direction before displaying
       dot[3][4] = dot[3][3]; // Store prevprev into prevprevprev location
       dot[3][3] = dot[3][2]; // Store prev into prevprev location
       dot[3][2] = dot[3][0]; // Store current into prev location     
       
     dot[3][0]= pixel[dot[3][0]][dot[3][1]];   // Use pgm_read_byte function to read data back from array in Progam Memory


 // delay(100);

     leds[dot[0][0]] = CRGB::Blue; 
     leds[dot[0][2]] = CRGB::Blue; 
     leds[dot[0][3]] = CRGB::Blue;     
     leds[dot[0][4]] = CRGB::Blue;    
    
     leds[dot[1][0]] = CRGB::Red;
     leds[dot[1][2]] = CRGB::Red;
     leds[dot[1][3]] = CRGB::Red;     
     leds[dot[1][4]] = CRGB::Red;   

     leds[dot[2][0]] = CRGB::Green;
     leds[dot[2][2]] = CRGB::Green;
     leds[dot[2][3]] = CRGB::Green;     
     leds[dot[2][4]] = CRGB::Green;     

     leds[dot[3][0]] = CRGB::Purple;
     leds[dot[3][2]] = CRGB::Purple;
     leds[dot[3][3]] = CRGB::Purple;
     leds[dot[3][4]] = CRGB::Purple;        

     FastLED.show(); 

     delay(10);
}



//********************************************
// SoundEffect1 
// *******************************************
void SoundEffect1() { // At last a stable Audio input circuit !! Teensy A2 connected to 4.7uf and SP1 on freetronics Mic. Also Analog Ground used with Mic


// Use the Ampliyude of the Mic input to set the Delay to slow down dotsnakes effect

  if (fps > 24) {
    if (peak1.available()) {
      fps = 0;
      monoPeak = abs((peak1.read() * 100.0));        
      }
    }



 //Clear all current LEDs


     leds[dot[0][0]] = CRGB::Black;  // Turn off current LED position
     leds[dot[0][2]] = CRGB::Black;  // Turn off current LED position
     leds[dot[0][3]] = CRGB::Black;  // Turn off current LED position    
     leds[dot[0][4]] = CRGB::Black;  // Turn off current LED position        

     leds[dot[1][0]] = CRGB::Black;  // Turn off current LED position
     leds[dot[1][2]] = CRGB::Black;  // Turn off current LED position
     leds[dot[1][3]] = CRGB::Black;  // Turn off current LED position    
     leds[dot[1][4]] = CRGB::Black;  // Turn off current LED position        

     leds[dot[2][0]] = CRGB::Black;  // Turn off current LED position
     leds[dot[2][2]] = CRGB::Black;  // Turn off current LED position
     leds[dot[2][3]] = CRGB::Black;  // Turn off current LED position    
     leds[dot[2][4]] = CRGB::Black;  // Turn off current LED position        

     leds[dot[3][0]] = CRGB::Black;  // Turn off current LED position
     leds[dot[3][2]] = CRGB::Black;  // Turn off current LED position
     leds[dot[3][3]] = CRGB::Black;  // Turn off current LED position    
     leds[dot[3][4]] = CRGB::Black;  // Turn off current LED position        
     FastLED.show(); 
     
     // Dot 0 **********************************************************

    
     // Randomly change direction of Dot
  
     direct = random8(8); // Randomly determine new direction

     // Check not going backwards    
     while ((abs(dot[0][1] - direct)) == 4){
        direct = random8(8); // Randomly determine new direction
     }
     
     dot[0][1] = direct; // Store value in array
    


    // Update position of data based on new direction before displaying
     dot[0][4] = dot[0][3]; // Store prevprev into prevprevprev location
     dot[0][3] = dot[0][2]; // Store prev into prevprev location
     dot[0][2] = dot[0][0]; // Store current into prev location   
      
     dot[0][0]= pixel[dot[0][0]][dot[0][1]]; // Use  function to read data back from array in Progam Memory




    // Dot 1**********************************************************


     // Randomly change direction of Dot
     direct = random8(8); // Randomly determine new direction
     // Check not going backwards    
     while ((abs(dot[1][1] - direct)) == 4){
        direct = random8(8); // Randomly determine new direction
     }
    
     dot[1][1] = direct; // Modify lead dot position and store value in array

     


    // Update position of data based on new direction before displaying
     dot[1][4] = dot[1][3]; // Store prevprev into prevprevprev location
     dot[1][3] = dot[1][2]; // Store prev into prevprev location
     dot[1][2] = dot[1][0]; // Store current into prev location   

     dot[1][0]= pixel[dot[1][0]][dot[1][1]];  // Use  function to read data back from array in Progam Memory



    
    // Dot 2 *****************************************  


     // Randomly change direction of Dot
     direct = random8(8); // Randomly determine new direction
     // Check not going backwards    
     while ((abs(dot[2][1] - direct)) == 4){
        direct = random8(8); // Randomly determine new direction
     }
     
     dot[2][1] = direct; // Store value in array

     
 

      // Update position of data based on new direction before displaying
       dot[2][4] = dot[2][3]; // Store prevprev into prevprevprev location
       dot[2][3] = dot[2][2]; // Store prev into prevprev location
       dot[2][2] = dot[2][0]; // Store current into prev location       
     
     dot[2][0]= pixel[dot[2][0]][dot[2][1]];   // Use pgm_read_byte function to read data back from array in Progam Memory




  
    // Dot 3 *****************************************  


     // Randomly change direction of Dot  
     direct = random8(8); // Randomly determine new direction
     // Check not going backwards    
     while ((abs(dot[3][1] - direct)) == 4){
        direct = random8(8); // Randomly determine new direction
     }     
     dot[3][1] = direct; // Store value in array


          


      // Update position of data based on new direction before displaying
       dot[3][4] = dot[3][3]; // Store prevprev into prevprevprev location
       dot[3][3] = dot[3][2]; // Store prev into prevprev location
       dot[3][2] = dot[3][0]; // Store current into prev location     
       
     dot[3][0]= pixel[dot[3][0]][dot[3][1]];   // Use pgm_read_byte function to read data back from array in Progam Memory


 // delay(100);

     leds[dot[0][0]] = CRGB::Blue; 
     leds[dot[0][2]] = CRGB::Blue; 
     leds[dot[0][3]] = CRGB::Blue;     
     leds[dot[0][4]] = CRGB::Blue;    
    
     leds[dot[1][0]] = CRGB::Red;
     leds[dot[1][2]] = CRGB::Red;
     leds[dot[1][3]] = CRGB::Red;     
     leds[dot[1][4]] = CRGB::Red;   

     leds[dot[2][0]] = CRGB::Green;
     leds[dot[2][2]] = CRGB::Green;
     leds[dot[2][3]] = CRGB::Green;     
     leds[dot[2][4]] = CRGB::Green;     

     leds[dot[3][0]] = CRGB::Purple;
     leds[dot[3][2]] = CRGB::Purple;
     leds[dot[3][3]] = CRGB::Purple;
     leds[dot[3][4]] = CRGB::Purple;        

     FastLED.show(); 

     delay(monoPeak);


      
}




//********************************************
// SoundEffect 3 
// *******************************************
void SoundEffect3() { // At last a stable Audio input circuit !! Teensy A2 connected to 4.7uf and SP1 on freetronics Mic. Also Analog Ground used with Mic


// Use the Ampliyude of the Mic input to set the VU Display which is a Bar graph cicling the Shpere

  if (fps > 24) {
    if (peak1.available()) {
      fps = 0;
      monoPeak = abs((peak1.read() * 10000.0)); 
      if (monoPeak >10000 ) {
        monoPeak = 10000;
        }      
      }
    }


// *********

/*
0 = Up
1 = Up Right  
2 = Right 
3 =  Down Right 
4 = Down
5 = Down Left
6 = Left
7 = Up Left
                  led, peakv
int soundot[5] = { 73 , 73, 88, 87, 86};
*/
    
     // Determine the Location of the new dot position based on the Analogue input value and the 5 rings of LEDs where 1st is baseline
     // smoothmic is the smooothed Mic output from A2 which has a range of 0 - 1025 in value
     // Suggested ranges are 0 < 10, 1 < 30, etc

     if (monoPeak >= 10000) { // Highest level of sound (read adjacent dot 4x)

// 11 Bands of color

fill_solid( &(leds[0]), 1, CRGB( 255, 0, 0) );
fill_solid( &(leds[1]), 8 , CRGB( 255, 0, 0) );
fill_solid( &(leds[9]), 16 , CRGB::Red);
fill_solid( &(leds[25]), 16, CRGB::Green);
fill_solid( &(leds[41]), 16 , CRGB( 0, 255, 0) );
fill_solid( &(leds[57]), 16 , CRGB( 0, 255, 0) );
fill_solid( &(leds[73]), 16, CRGB( 0, 0, 255) );
fill_solid( &(leds[89]), 16 , CRGB( 0, 0, 255) );
//fill_solid( &(leds[105]), 16 , CRGB( 0, 0, 255) );

                
     } else

  if (monoPeak >= 8000 ) { // 2nd Highest level of sound

fill_solid( &(leds[1]), 8 , CRGB( 255, 0, 0) );
fill_solid( &(leds[9]), 16 , CRGB::Red);
fill_solid( &(leds[25]), 16, CRGB::Green);
fill_solid( &(leds[41]), 16 , CRGB( 0, 255, 0) );
fill_solid( &(leds[57]), 16 , CRGB( 0, 255, 0) );
fill_solid( &(leds[73]), 16, CRGB( 0, 0, 255) );
fill_solid( &(leds[89]), 16 , CRGB( 0, 0, 255) );
//fill_solid( &(leds[105]), 16 , CRGB( 0, 0, 255) );

           
     } else

     
     if (monoPeak >= 6000 ) { // 2nd Highest level of sound


fill_solid( &(leds[9]), 16 , CRGB::Red);
fill_solid( &(leds[25]), 16, CRGB::Green);
fill_solid( &(leds[41]), 16 , CRGB( 0, 255, 0) );
fill_solid( &(leds[57]), 16 , CRGB( 0, 255, 0) );
fill_solid( &(leds[73]), 16, CRGB( 0, 0, 255) );
fill_solid( &(leds[89]), 16 , CRGB( 0, 0, 255) );
//fill_solid( &(leds[105]), 16 , CRGB( 0, 0, 255) );
           
     } else

  if (monoPeak >= 5000 ) { // 2nd Highest level of sound



fill_solid( &(leds[25]), 16, CRGB::Green);
fill_solid( &(leds[41]), 16 , CRGB( 0, 255, 0) );
fill_solid( &(leds[57]), 16 , CRGB( 0, 255, 0) );
fill_solid( &(leds[73]), 16, CRGB( 0, 0, 255) );
fill_solid( &(leds[89]), 16 , CRGB( 0, 0, 255) );
//fill_solid( &(leds[105]), 16 , CRGB( 0, 0, 255) );

          
     } else

     
     if (monoPeak >= 4000 ) { // 2nd Highest level of sound

fill_solid( &(leds[41]), 16 , CRGB( 0, 255, 0) );
fill_solid( &(leds[57]), 16 , CRGB( 0, 255, 0) );
fill_solid( &(leds[73]), 16, CRGB( 0, 0, 255) );
fill_solid( &(leds[89]), 16 , CRGB( 0, 0, 255) );
//fill_solid( &(leds[105]), 16 , CRGB( 0, 0, 255) );
           
     } else

     if (monoPeak >= 3000 ) { // 3rd Highest level of sound

fill_solid( &(leds[57]), 16 , CRGB( 0, 255, 0) );
fill_solid( &(leds[73]), 16, CRGB( 0, 0, 255) );
fill_solid( &(leds[89]), 16 , CRGB( 0, 0, 255) );
//fill_solid( &(leds[105]), 16 , CRGB( 0, 0, 255) );


      } else   
      
     if (monoPeak >= 2000 ) { // 3rd Highest level of sound

fill_solid( &(leds[73]), 16, CRGB( 0, 0, 255) );
fill_solid( &(leds[89]), 16 , CRGB( 0, 0, 255) );
           
     } else   
      
     if (monoPeak >= 1000 ) { // 3rd Highest level of sound

fill_solid( &(leds[89]), 16 , CRGB( 0, 0, 255) );

           
     } 
     
     FastLED.show(); 

     delay(1); 


       // Clear Sphere

fadeToBlackBy( leds, 25, 15);
fadeToBlackBy( leds, 41, 15);
fadeToBlackBy( leds, 57, 15);
fadeToBlackBy( leds, 73, 15);
fadeToBlackBy( leds, 89, 15);
//  FastLED.show();

      
}


//********************************************
// Color Wash  
// *******************************************
void Colorwash() { // GyroLED Snakes down sphere


if (cal == false) { // Display the menu Item
  six();
  cal = true;
}

/* Three Bands
fill_solid( &(leds[0]), 41, CHSV( Xcol, 255, 255) );
fill_solid( &(leds[41]), 48 , CHSV( Ycol, 255, 255) );
fill_solid( &(leds[89]), 41 , CHSV( Zcol, 255, 255) );
*/

int aw[11]; // 

 for (int uw = 0; uw < 256; uw++) {

  aw[0] = uw + 22;
  aw[1] = uw + 44;
  aw[2] = uw + 66;
  aw[3] = uw + 88;
  aw[4] = uw + 110;
  aw[5] = uw + 132;
  aw[6] = uw + 154;
  aw[7] = uw + 176;
  aw[8] = uw + 196;
  aw[9] = uw + 218;
  aw[10] = uw + 240;
  
  if (aw[1] > 256) { aw[1] = aw[1] - 255; }
  if (aw[2] > 256) { aw[2] = aw[2] - 255; }
  if (aw[3] > 256) { aw[3] = aw[3] - 255; }
  if (aw[4] > 256) { aw[4] = aw[4] - 255; }
  if (aw[5] > 256) { aw[5] = aw[5] - 255; }
  if (aw[6] > 256) { aw[6] = aw[6] - 255; }
  if (aw[7] > 256) { aw[7] = aw[7] - 255; }
  if (aw[8] > 256) { aw[8] = aw[8] - 255; }
  if (aw[9] > 256) { aw[9] = aw[9] - 255; }
  if (aw[10] > 256) { aw[10] = aw[10] - 255; }
  
  
  // 11 Bands of color
  
  fill_solid( &(leds[0]), 1, CHSV( aw[0], 255, 255) );
  fill_solid( &(leds[1]), 8 , CHSV( aw[1], 255, 255) );
  fill_solid( &(leds[9]), 16 , CHSV( aw[2], 255, 255) );
  fill_solid( &(leds[25]), 16, CHSV( aw[3], 255, 255) );
  fill_solid( &(leds[41]), 16 , CHSV( aw[4], 255, 255) );
  fill_solid( &(leds[57]), 16 , CHSV( aw[5], 255, 255) );
  fill_solid( &(leds[73]), 16, CHSV( aw[6], 255, 255) );
  fill_solid( &(leds[89]), 16 , CHSV( aw[7], 255, 255) );
  fill_solid( &(leds[105]), 16 , CHSV( aw[8], 255, 255) );
  fill_solid( &(leds[121]), 8, CHSV( aw[9], 255, 255) );
  fill_solid( &(leds[129]), 1 , CHSV( aw[10], 255, 255) );
  
  
  FastLED.show();

  delay(1);

  
  //     Serial.println(Xcol);
  }
      
}

//********************************************
// DotOnTop 
// *******************************************
void DotOnTop() { // LED stays in top of sphere

  // Callibrate with 5 second count down

if (cal == false) { // Delay count down timer to let MPU 6050 stabilize
      nine();
        

  cal = true;
// get a baseline of X,Y,Z coordinates from smoothing algorithm

  xb = smoothedX; // At rest baseline value
  yb = smoothedY; // At rest baseline value
  zb = smoothedZ; // At rest baseline value

  // Normalise Baseline

  xb = xb + 18100;
  yb = yb + 18100;  
  zb = zb + 18100;
  
}



// Normalise Smoothed Values
Xnormalise = smoothedX + 18100;
Ynormalise = smoothedY + 18100;
Znormalise = smoothedZ + 18100;

// Display dot on top of ball

//    leds[dt] = CRGB::Blue;
//    FastLED.show(); 

// Identify from Array new position of the Dot

int tolerance = 2000;// X,Y,Z must meet this criteria to turn on LED
int gc=0; // Points to LED to be tested
boolean gf = false; // Flag to indicate coordinate found no need to search further

// Temp calc variables
int tX = 0;
int tY = 0;
int tZ = 0;



while ( (gc<130) && (gf == false)) { // For LEDS on top of Sphere
  // Read in Data from Array and Test Against Gyro Coordinates

        tX = pixel[gc][10];
        tY = pixel[gc][11];
        tZ = pixel[gc][12];        
    
    
        if ( (Xnormalise < (tX+tolerance)) && (Xnormalise > (tX-tolerance))) {
    
             if ( (Ynormalise < (tY+tolerance)) && (Ynormalise > (tY-tolerance))) {

                  if ( (Znormalise < (tZ+tolerance)) && (Znormalise > (tZ-tolerance))) {              
 
                          // Set pointer to new LED and display it
                          dt = gc;
                          gf = true; // Set flag to exit While Loop
                          leds[dt] = CRGB::Red;
                          leds[pixel[dt][0]] = CRGB::Blue;
                          leds[pixel[dt][1]] = CRGB::Blue;
                          leds[pixel[dt][2]] = CRGB::Blue;
                          leds[pixel[dt][3]] = CRGB::Blue;
                          leds[pixel[dt][4]] = CRGB::Blue;
                          leds[pixel[dt][5]] = CRGB::Blue;                                        
                          leds[pixel[dt][6]] = CRGB::Blue;                   
                          leds[pixel[dt][7]] = CRGB::Blue;
                          
                          FastLED.show(); 
       
                          leds[dt] = CRGB::Black;
                          leds[pixel[dt][0]] = CRGB::Black;
                          leds[pixel[dt][1]] = CRGB::Black;
                          leds[pixel[dt][2]] = CRGB::Black;
                          leds[pixel[dt][3]] = CRGB::Black;
                          leds[pixel[dt][4]] = CRGB::Black;
                          leds[pixel[dt][5]] = CRGB::Black;                                        
                          leds[pixel[dt][6]] = CRGB::Black; 
                          leds[pixel[dt][7]] = CRGB::Black;                   
                          FastLED.show();     
                  }
            
              }      
          }
    
   //         leds[i].setRGB( (Xcol), (Ycol), (Zcol));          
       
    //Increment counter  
    gc++;  
  }     
   
}

//********************************************
// SoundEffect 4 
// *******************************************
void SoundEffect4() { // At last a stable Audio input circuit !! Teensy A2 connected to 4.7uf and SP1 on freetronics Mic. Also Analog Ground used with Mic


// Use the Ampliyude of the Mic input to set the VU Display which is a Bar graph circling the Shpere

  if (fps > 24) {
    if (peak1.available()) {
      fps = 0;
      monoPeak = abs((peak1.read() * 10000.0)); 
      if (monoPeak >10000 ) {
        monoPeak = 10000;
        }      
    }

  }


// *********

/*
0 = Up
1 = Up Right  
2 = Right 
3 =  Down Right 
4 = Down
5 = Down Left
6 = Left
7 = Up Left
                  led, peakv
int soundot[5] = { 73 , 73, 88, 87, 86};

int sb[10] = {0, 1, 9, 25, 41, 57, 73, 89}; // Used for Sound Effect
int scntr = 0; // Counts the incremetal change around the sound effect (16 locations)


*/
    


// 6 Bands of color

     if (monoPeak >= 10000) { // Highest level of sound (read adjacent dot 4x)

        leds[sb[2] + scntr] = CRGB::Red;
        leds[sb[3] + scntr] = CRGB::Red;
        leds[sb[4] + scntr] = CRGB::Green;
        leds[sb[5] + scntr] = CRGB::Green;
        leds[sb[6] + scntr] = CRGB::Blue;
        leds[sb[7] + scntr] = CRGB::Blue;
                                         
     } else

  if (monoPeak >= 8000 ) { // 2nd Highest level of sound

        // leds[sb[2] + scntr] = CRGB::Red;
        leds[sb[3] + scntr] = CRGB::Red;
        leds[sb[4] + scntr] = CRGB::Green;
        leds[sb[5] + scntr] = CRGB::Green;
        leds[sb[6] + scntr] = CRGB::Blue;
        leds[sb[7] + scntr] = CRGB::Blue;
           
     } else

     
     if (monoPeak >= 6500 ) { // 2nd Highest level of sound

        // leds[sb[2] + scntr] = CRGB::Red;
        // leds[sb[3] + scntr] = CRGB::Red;
        leds[sb[4] + scntr] = CRGB::Green;
        leds[sb[5] + scntr] = CRGB::Green;
        leds[sb[6] + scntr] = CRGB::Blue;
        leds[sb[7] + scntr] = CRGB::Blue;
           
     } else

  if (monoPeak >= 5000 ) { // 2nd Highest level of sound

        // leds[sb[2] + scntr] = CRGB::Red;
        // leds[sb[3] + scntr] = CRGB::Red;
        // leds[sb[4] + scntr] = CRGB::Green;
        leds[sb[5] + scntr] = CRGB::Green;
        leds[sb[6] + scntr] = CRGB::Blue;
        leds[sb[7] + scntr] = CRGB::Blue;
          
     } else

     
     if (monoPeak >= 2000 ) { // 2nd Highest level of sound

        // leds[sb[2] + scntr] = CRGB::Red;
        // leds[sb[3] + scntr] = CRGB::Red;
        // leds[sb[4] + scntr] = CRGB::Green;
        // leds[sb[5] + scntr] = CRGB::Green;
        leds[sb[6] + scntr] = CRGB::Blue;
        leds[sb[7] + scntr] = CRGB::Blue;
           
     } else

     if (monoPeak >= 1000 ) { // 3rd Highest level of sound

        // leds[sb[2] + scntr] = CRGB::Red;
        // leds[sb[3] + scntr] = CRGB::Red;
        // leds[sb[4] + scntr] = CRGB::Green;
        // leds[sb[5] + scntr] = CRGB::Green;
        // leds[sb[6] + scntr] = CRGB::Blue;
        leds[sb[7] + scntr] = CRGB::Blue;

      }  


     
     FastLED.show(); 

//     delay(100); 

 // Increment LED Counter 
  scntr++;

        if (scntr == 6 ) {
      // Fade all LEDs to Black
      fadeToBlackBy( leds, 25, 15);
      fadeToBlackBy( leds, 41, 15);
      fadeToBlackBy( leds, 57, 15);
      fadeToBlackBy( leds, 73, 15);
      fadeToBlackBy( leds, 89, 15);

      } else 
       
       if (scntr == 12 ) {
      // Fade all LEDs to Black
      fadeToBlackBy( leds, 25, 15);
      fadeToBlackBy( leds, 41, 15);
      fadeToBlackBy( leds, 57, 15);
      fadeToBlackBy( leds, 73, 15);
      fadeToBlackBy( leds, 89, 15);

      } else 
      
      if (scntr > 15 ) {
      scntr = 0; // Reset Counter
      // Fade all LEDs to Black
      fadeToBlackBy( leds, 25, 15);
      fadeToBlackBy( leds, 41, 15);
      fadeToBlackBy( leds, 57, 15);
      fadeToBlackBy( leds, 73, 15);
      fadeToBlackBy( leds, 89, 15);

      }




}


void BouncingBalls(byte red, byte green, byte blue, int BallCount) {
  float Gravity = -9.81;
  int StartHeight = 1;
  
  float Height[BallCount];
  float ImpactVelocityStart = sqrt( -2 * Gravity * StartHeight );
  float ImpactVelocity[BallCount];
  float TimeSinceLastBounce[BallCount];
  int   Position[BallCount];
  long  ClockTimeSinceLastBounce[BallCount];
  float Dampening[BallCount];
  
  for (int i = 0 ; i < BallCount ; i++) {   
    ClockTimeSinceLastBounce[i] = millis();
    Height[i] = StartHeight;
    Position[i] = 0; 
    ImpactVelocity[i] = ImpactVelocityStart;
    TimeSinceLastBounce[i] = 0;
    Dampening[i] = 0.90 - float(i)/pow(BallCount,2); 
  }

  while (menu == 8) {
    for (int i = 0 ; i < BallCount ; i++) {
      TimeSinceLastBounce[i] =  millis() - ClockTimeSinceLastBounce[i];
      Height[i] = 0.5 * Gravity * pow( TimeSinceLastBounce[i]/1000 , 2.0 ) + ImpactVelocity[i] * TimeSinceLastBounce[i]/1000;
  
      if ( Height[i] < 0 ) {                      
        Height[i] = 0;
        ImpactVelocity[i] = Dampening[i] * ImpactVelocity[i];
        ClockTimeSinceLastBounce[i] = millis();
  
        if ( ImpactVelocity[i] < 0.01 ) {
          ImpactVelocity[i] = ImpactVelocityStart;
        }
      }
      Position[i] = round( Height[i] * (NUM_LEDS - 1) / StartHeight);
    }
  
    for (int i = 0 ; i < BallCount ; i++) {
    leds[Position[i]].setRGB( random(255),random(255),random(255));    
   FastLED.show();
    }
    

fadeToBlackBy( leds, 130, 5);
       
  }


}

//********************************************
// SoundEffect 6 
// *******************************************
void SoundEffect6() { // At last a stable Audio input circuit !! Teensy A2 connected to 4.7uf and SP1 on freetronics Mic. Also Analog Ground used with Mic

clr4 = random(255);
clr5 = random(255);
clr6 = random(255);

// Use the Ampliyude of the Mic input to set the VU Display which is a Bar graph circling the Shpere


  if (fps > 24) {
    if (peak1.available()) {
      fps = 0;
      monoPeak = abs((peak1.read() * 139.0)) - 9; // Remove noise level of 9
      if (monoPeak >129 ) {
        monoPeak = 129;
        }      
    }

  }

      fill_solid( &(leds[0]), monoPeak, CRGB( clr4, clr5, clr6 ) );

     FastLED.show(); 

     delay(5); 

      fadeToBlackBy( leds, 130, 5);

     FastLED.show(); 

        Serial.println(monoPeak);
      
}

//********************************************
// SoundEffect 7 
// *******************************************
void SoundEffect7() { // At last a stable Audio input circuit !! Teensy A2 connected to 4.7uf and SP1 on freetronics Mic. Also Analog Ground used with Mic

if (cal == false) { // Display the menu Item
  four();
  cal = true;
}

clr6 = random(3);

// Use the Amplitude of the Mic input to set the VU Display which is a Bar graph circling the Shpere


  if (fps > 24) {
    if (peak1.available()) {
      fps = 0;
      monoPeak = abs((peak1.read() * 139.0)) - 9; // Remove noise level of 9
      if (monoPeak >129 ) {
        monoPeak = 129;
        }      
    }

  }


        
if (clr6 == 0 ) {        
        fill_solid( &(leds[0]), monoPeak , CRGB::Blue);
} else  

if (clr6 == 1 ) {        
        fill_solid( &(leds[0]), monoPeak , CRGB::Green);
}   else  

if (clr6 == 2 ) {        
        fill_solid( &(leds[0]), monoPeak , CRGB::Red);
}  
              
      
      // fill_solid( &(leds[0]), monoPeak, CRGB( clr4, clr5, clr6 ) );

     FastLED.show(); 

     delay(3); 

      fadeToBlackBy( leds, 130, 10);

     FastLED.show(); 


}

//********************************************
// DotSnakesSlow 
// *******************************************

void DotSnakesSlow() {

if (cal == false) { // Display the menu Item
  five();
  cal = true;
}

// Use the Amplitude of the Mic input to set the delay for the DotSnakes


  if (fps > 24) {
    if (peak1.available()) {
      fps = 0;
      monoPeak = abs((peak1.read() * td)); // Remove noise level 
      if (monoPeak >td ) {
        monoPeak = td;
        }      
    }

  }
 
 //Clear all current LEDs


     leds[dot[0][0]] = CRGB::Black;  // Turn off current LED position
     leds[dot[0][2]] = CRGB::Black;  // Turn off current LED position
     leds[dot[0][3]] = CRGB::Black;  // Turn off current LED position    
     leds[dot[0][4]] = CRGB::Black;  // Turn off current LED position        

     leds[dot[1][0]] = CRGB::Black;  // Turn off current LED position
     leds[dot[1][2]] = CRGB::Black;  // Turn off current LED position
     leds[dot[1][3]] = CRGB::Black;  // Turn off current LED position    
     leds[dot[1][4]] = CRGB::Black;  // Turn off current LED position        

     leds[dot[2][0]] = CRGB::Black;  // Turn off current LED position
     leds[dot[2][2]] = CRGB::Black;  // Turn off current LED position
     leds[dot[2][3]] = CRGB::Black;  // Turn off current LED position    
     leds[dot[2][4]] = CRGB::Black;  // Turn off current LED position        

     leds[dot[3][0]] = CRGB::Black;  // Turn off current LED position
     leds[dot[3][2]] = CRGB::Black;  // Turn off current LED position
     leds[dot[3][3]] = CRGB::Black;  // Turn off current LED position    
     leds[dot[3][4]] = CRGB::Black;  // Turn off current LED position        
     FastLED.show(); 
     
//if (monoPeak > 1) { // No sound blank ball
  

     // Dot 0 **********************************************************

    
     // Randomly change direction of Dot
  
     direct = random8(8); // Randomly determine new direction

     // Check not going backwards    
     while ((abs(dot[0][1] - direct)) == 4){
        direct = random8(8); // Randomly determine new direction
     }
     
     dot[0][1] = direct; // Store value in array
    


    // Update position of data based on new direction before displaying
     dot[0][4] = dot[0][3]; // Store prevprev into prevprevprev location
     dot[0][3] = dot[0][2]; // Store prev into prevprev location
     dot[0][2] = dot[0][0]; // Store current into prev location   
      
     dot[0][0]= pixel[dot[0][0]][dot[0][1]]; // Use  function to read data back from array in Progam Memory




    // Dot 1**********************************************************


     // Randomly change direction of Dot
     direct = random8(8); // Randomly determine new direction
     // Check not going backwards    
     while ((abs(dot[1][1] - direct)) == 4){
        direct = random8(8); // Randomly determine new direction
     }
    
     dot[1][1] = direct; // Modify lead dot position and store value in array

     


    // Update position of data based on new direction before displaying
     dot[1][4] = dot[1][3]; // Store prevprev into prevprevprev location
     dot[1][3] = dot[1][2]; // Store prev into prevprev location
     dot[1][2] = dot[1][0]; // Store current into prev location   

     dot[1][0]= pixel[dot[1][0]][dot[1][1]];  // Use  function to read data back from array in Progam Memory



    
    // Dot 2 *****************************************  


     // Randomly change direction of Dot
     direct = random8(8); // Randomly determine new direction
     // Check not going backwards    
     while ((abs(dot[2][1] - direct)) == 4){
        direct = random8(8); // Randomly determine new direction
     }
     
     dot[2][1] = direct; // Store value in array

     
 

      // Update position of data based on new direction before displaying
       dot[2][4] = dot[2][3]; // Store prevprev into prevprevprev location
       dot[2][3] = dot[2][2]; // Store prev into prevprev location
       dot[2][2] = dot[2][0]; // Store current into prev location       
     
     dot[2][0]= pixel[dot[2][0]][dot[2][1]];   // Use pgm_read_byte function to read data back from array in Progam Memory




  
    // Dot 3 *****************************************  


     // Randomly change direction of Dot  
     direct = random8(8); // Randomly determine new direction
     // Check not going backwards    
     while ((abs(dot[3][1] - direct)) == 4){
        direct = random8(8); // Randomly determine new direction
     }     
     dot[3][1] = direct; // Store value in array


          


      // Update position of data based on new direction before displaying
       dot[3][4] = dot[3][3]; // Store prevprev into prevprevprev location
       dot[3][3] = dot[3][2]; // Store prev into prevprev location
       dot[3][2] = dot[3][0]; // Store current into prev location     
       
     dot[3][0]= pixel[dot[3][0]][dot[3][1]];   // Use pgm_read_byte function to read data back from array in Progam Memory


 // delay(100);

     leds[dot[0][0]] = CRGB::Blue; 
     leds[dot[0][2]] = CRGB::Blue; 
     leds[dot[0][3]] = CRGB::Blue;     
     leds[dot[0][4]] = CRGB::Blue;    
    
     leds[dot[1][0]] = CRGB::Red;
     leds[dot[1][2]] = CRGB::Red;
     leds[dot[1][3]] = CRGB::Red;     
     leds[dot[1][4]] = CRGB::Red;   

     leds[dot[2][0]] = CRGB::Green;
     leds[dot[2][2]] = CRGB::Green;
     leds[dot[2][3]] = CRGB::Green;     
     leds[dot[2][4]] = CRGB::Green;     

     leds[dot[3][0]] = CRGB::Purple;
     leds[dot[3][2]] = CRGB::Purple;
     leds[dot[3][3]] = CRGB::Purple;
     leds[dot[3][4]] = CRGB::Purple;        

     FastLED.show(); 


//        Serial.println(monoPeak);

     delay(monoPeak*2);
//}
           
}

//********************************************
// SoundRing  
// *******************************************
void SoundRing() { // GyroLED Snakes down sphere

  if (fps > 24) {
    if (peak1.available()) {
      fps = 0;
      monoPeak = abs((peak1.read() * tsr)); // Remove noise level 
      if (monoPeak >tsr ) {
        monoPeak = tsr;
        }  
    }
  }


  

    //  Step Through Layers from top to bottom ring on ball and speed up with louder music
    
    srctr++; // Increment counter
    if ( srctr > 10 ) {
      srctr = 0; // Reset Counter to top ring on ball
    }
    

if (monoPeak > 10 ) {
          
        // 11 Bands of color
     //   fill_solid( &(leds[0]), 130, CHSV( monoPeak, 0, 0) );// First blank all LEDs
    
        
        if (srctr == 0) {
          fill_solid( &(leds[0]), 1, CHSV( 224-monoPeak, 255, 255) );
        } else 
        
        if (srctr == 1) {     
          fill_solid( &(leds[1]), 8 , CHSV( 224-monoPeak, 255, 255) );
        }else 
        
        if (srctr == 2) {  
          fill_solid( &(leds[9]), 16 , CHSV( 224-monoPeak, 255, 255) );
        
        }else 
        
        if (srctr == 3) {  
          fill_solid( &(leds[25]), 16, CHSV( 224-monoPeak, 255, 255) );
        }else 
        
        if (srctr == 4) {  
          fill_solid( &(leds[41]), 16 , CHSV( 224-monoPeak, 255, 255) );
        }else 
        
        if (srctr == 5) {  
          fill_solid( &(leds[57]), 16 , CHSV( 224-monoPeak, 255, 255) );
        }else 
        
        if (srctr == 6) {  
          fill_solid( &(leds[73]), 16, CHSV( 224-monoPeak, 255, 255) );
        }else 
        
        if (srctr == 7) {  
          fill_solid( &(leds[89]), 16 , CHSV( 224-monoPeak, 255, 255) );
        }else 
        
        if (srctr == 8) {  
          fill_solid( &(leds[105]), 16 , CHSV( 224-monoPeak, 255, 255) );
        }else 
        
        if (srctr == 9) {  
          fill_solid( &(leds[121]), 8, CHSV( 224-monoPeak, 255, 255) );
        }else 
        
        if (srctr == 10) {  
          fill_solid( &(leds[129]), 1 , CHSV( 224-monoPeak, 255, 255) );    
        }
         FastLED.show();  
} else { 

       fadeToBlackBy( leds, 130, 8);
         FastLED.show();  
}
//        Serial.println(monoPeak);

     
}

//********************************************
// SoundRingStep  
// *******************************************
void SoundRingStep() { // GyroLED Snakes down sphere

if (cal == false) { // Display the menu Item
  three();
  cal = true;
}

  if (fps > 24) {
    if (peak1.available()) {
      fps = 0;
      monoPeak = abs((peak1.read() * 160)); // Remove noise level 
      if (monoPeak >160 ) {
        monoPeak = 160;
        }  
    }
  }


  srs = 10;

    //  Step Through Layers from top to bottom ring on ball and speed up with louder music
    
    srctr++; // Increment counter
    if ( srctr > 10 ) {
      srctr = 0; // Reset Counter to top ring on ball
    }
    

if (monoPeak >10  ) {
          
        // 11 Bands of color
     //   fill_solid( &(leds[0]), 130, CHSV( monoPeak, 0, 0) );// First blank all LEDs
    
        
        if (srctr == 0) {
          fill_solid( &(leds[0]), 1, CHSV( 160-monoPeak, 255, 255) );
          FastLED.show(); 
          delay(srs);
 //         fill_solid( &(leds[0]), 1, CHSV( 0, 0, 0) );
          
        } else 
        
        if (srctr == 1) {     
          fill_solid( &(leds[1]), 8 , CHSV( 160-monoPeak, 255, 255) );
          FastLED.show(); 
          delay(srs);
  //        fill_solid( &(leds[1]), 8, CHSV( 0, 0, 0) );
          
        }else 
        
        if (srctr == 2) {  
          fill_solid( &(leds[9]), 16 , CHSV( 160-monoPeak, 255, 255) );
          FastLED.show(); 
           delay(srs);
 //         fill_solid( &(leds[9]), 16, CHSV( 0, 0, 0) );
                 
        }else 
        
        if (srctr == 3) {  
          fill_solid( &(leds[25]), 16, CHSV( 160-monoPeak, 255, 255) );
          FastLED.show(); 
          delay(srs);
//          fill_solid( &(leds[25]), 16, CHSV( 0, 0, 0) );
          
        }else 
        
        if (srctr == 4) {  
          fill_solid( &(leds[41]), 16 , CHSV( 160-monoPeak, 255, 255) );
          FastLED.show(); 
          delay(srs);
//          fill_solid( &(leds[41]), 16, CHSV( 0, 0, 0) );
          
        }else 
        
        if (srctr == 5) {  
          fill_solid( &(leds[57]), 16 , CHSV( 160-monoPeak, 255, 255) );
          FastLED.show(); 
          delay(srs);
 //         fill_solid( &(leds[57]), 16, CHSV( 0, 0, 0) );
          
        }else 
        
        if (srctr == 6) {  
          fill_solid( &(leds[73]), 16, CHSV( 160-monoPeak, 255, 255) );
          FastLED.show(); 
          delay(srs);
 //         fill_solid( &(leds[73]), 16, CHSV( 0, 0, 0) );
          
        }else 
        
        if (srctr == 7) {  
          fill_solid( &(leds[89]), 16 , CHSV( 160-monoPeak, 255, 255) );
          FastLED.show(); 
          delay(srs);
  //        fill_solid( &(leds[89]), 16, CHSV( 0, 0, 0) );
          
        }else 
        
        if (srctr == 8) {  
          fill_solid( &(leds[105]), 16 , CHSV( 160-monoPeak, 255, 255) );
          FastLED.show(); 
          delay(srs);
  //        fill_solid( &(leds[105]), 16, CHSV( 0, 0, 0) );
         
        }else 
        
        if (srctr == 9) {  
          fill_solid( &(leds[121]), 8, CHSV( 160-monoPeak, 255, 255) );
          FastLED.show(); 
          delay(srs);
 //         fill_solid( &(leds[121]), 8, CHSV( 0, 0, 0) );
          
        }else 
        
        if (srctr == 10) {  
          fill_solid( &(leds[129]), 1 , CHSV( 160-monoPeak, 255, 255) );
          FastLED.show();     
          delay(srs);


          
        } 
        }else {
          fadeToBlackBy( leds, 130, 2);
          FastLED.show(); 
      } 
//        Serial.println(monoPeak);

     
}

//********************************************
// SoundRingStepBar  
// *******************************************
void SoundRingStepBar() { // GyroLED Snakes down sphere

  if (fps > 24) {
    if (peak1.available()) {
      fps = 0;
      monoPeak = abs((peak1.read() * 160)); // TThis limits spectrum from Red to Blue which us reversed below for Bar effect
      if (monoPeak >160 ) {
        monoPeak = 160;
        }  
    }
  }


  srs = 0; // Sets minimum delay between each ring being left on

    //  Step Through Layers from top to bottom ring on ball and speed up with louder music
    
    

if (monoPeak >10  ) {
          
        // 11 Bands of color
     //   fill_solid( &(leds[0]), 130, CHSV( monoPeak, 0, 0) );// First blank all LEDs
    
        
        if (monoPeak > 10) {
          fill_solid( &(leds[0]), 1, CHSV( 160-monoPeak, 255, 255) );
          FastLED.show(); 
          delay(srs);
 //         fill_solid( &(leds[0]), 1, CHSV( 0, 0, 0) );
          
        }  else 
        
        if (monoPeak > 35) {     
          fill_solid( &(leds[1]), 8 , CHSV( 160-monoPeak, 255, 255) );
          FastLED.show(); 
          delay(srs);
  //        fill_solid( &(leds[1]), 8, CHSV( 0, 0, 0) );
          
        }  else  
        
        if (monoPeak > 55) {  
          fill_solid( &(leds[9]), 16 , CHSV( 160-monoPeak, 255, 255) );
          FastLED.show(); 
           delay(srs);
 //         fill_solid( &(leds[9]), 16, CHSV( 0, 0, 0) );
                 
        }  else  
        
        if (monoPeak > 75) {  
          fill_solid( &(leds[25]), 16, CHSV( 160-monoPeak, 255, 255) );
          FastLED.show(); 
          delay(srs);
//          fill_solid( &(leds[25]), 16, CHSV( 0, 0, 0) );
          
        }  else  
        
        if (monoPeak > 95) {  
          fill_solid( &(leds[41]), 16 , CHSV( 160-monoPeak, 255, 255) );
          FastLED.show(); 
          delay(srs);
//          fill_solid( &(leds[41]), 16, CHSV( 0, 0, 0) );
          
        }  else  
        
        if (monoPeak > 115) {  
          fill_solid( &(leds[57]), 16 , CHSV( 160-monoPeak, 255, 255) );
          FastLED.show(); 
          delay(srs);
 //         fill_solid( &(leds[57]), 16, CHSV( 0, 0, 0) );
          
        }  else  
        
        if (monoPeak > 125) {  
          fill_solid( &(leds[73]), 16, CHSV( 160-monoPeak, 255, 255) );
          FastLED.show(); 
          delay(srs);
 //         fill_solid( &(leds[73]), 16, CHSV( 0, 0, 0) );
          
        }  else  
        
        if (monoPeak > 135) {  
          fill_solid( &(leds[89]), 16 , CHSV( 160-monoPeak, 255, 255) );
          FastLED.show(); 
          delay(srs);
  //        fill_solid( &(leds[89]), 16, CHSV( 0, 0, 0) );
          
        }  else  
        
        if (monoPeak > 145) {  
          fill_solid( &(leds[105]), 16 , CHSV( 160-monoPeak, 255, 255) );
          FastLED.show(); 
          delay(srs);
  //        fill_solid( &(leds[105]), 16, CHSV( 0, 0, 0) );
         
        }  else  
        
        if (monoPeak > 150) {  
          fill_solid( &(leds[121]), 8, CHSV( 160-monoPeak, 255, 255) );
          FastLED.show(); 
          delay(srs);
 //         fill_solid( &(leds[121]), 8, CHSV( 0, 0, 0) );
          
        }  else  
        
        if (monoPeak > 155) {  
          fill_solid( &(leds[129]), 1 , CHSV( 160-monoPeak, 255, 255) );
          FastLED.show();     
          delay(srs);


          
        } 
        }else {
          fadeToBlackBy( leds, 130, 2);
          FastLED.show(); 
      } 
//        Serial.println(monoPeak);

     
}

//********************************************
// DotOnTopSound 
// *******************************************
void DotOnTopSound() { // Sound Bubble stays in top of sphere



  if (fps > 24) {
    if (peak1.available()) {
      fps = 0;
      monoPeak = abs((peak1.read() * 160)); // TThis limits spectrum from Red to Blue which us reversed below for Bar effect
      if (monoPeak >160 ) {
        monoPeak = 160;
        }  
    }
  }

// Normalise Smoothed Values
Xnormalise = smoothedX + 18100;
Ynormalise = smoothedY + 18100;
Znormalise = smoothedZ + 18100;

// Display dot on top of ball

//    leds[dt] = CRGB::Blue;
//    FastLED.show(); 

// Identify from Array new position of the Dot

int tolerance = 2000;// X,Y,Z must meet this criteria to turn on LED
int gc=0; // Points to LED to be tested
boolean gf = false; // Flag to indicate coordinate found no need to search further

// Temp calc variables
int tX = 0;
int tY = 0;
int tZ = 0;



while ( (gc<130) && (gf == false)) { // For LEDS on top of Sphere
  // Read in Data from Array and Test Against Gyro Coordinates

        tX = pixel[gc][10];
        tY = pixel[gc][11];
        tZ = pixel[gc][12];        
    
    
        if ( (Xnormalise < (tX+tolerance)) && (Xnormalise > (tX-tolerance))) {
    
             if ( (Ynormalise < (tY+tolerance)) && (Ynormalise > (tY-tolerance))) {

                  if ( (Znormalise < (tZ+tolerance)) && (Znormalise > (tZ-tolerance))) {              
 
                          // Set pointer to new LED and display it
                          dt = gc;
                          gf = true; // Set flag to exit While Loop
                          leds[dt] = CRGB::Green;

                          /*
                           * LED Position
                          0 = Up
                          1 = Up Right  
                          2 = Right 
                          3 =  Down Right 
                          4 = Down
                          5 = Down Left
                          6 = Left
                          7 = Up Left
                           * 
                           */


 if (monoPeak > 50) {
                          leds[pixel[dt][0]] = CRGB::Red;
                          leds[pixel[dt][1]] = CRGB::Red;
                          leds[pixel[dt][2]] = CRGB::Red;
                          leds[pixel[dt][3]] = CRGB::Red;
                          leds[pixel[dt][4]] = CRGB::Red;
                          leds[pixel[dt][5]] = CRGB::Red;                                        
                          leds[pixel[dt][6]] = CRGB::Red;                   
                          leds[pixel[dt][7]] = CRGB::Red;

 }

 if (monoPeak > 140) {

                          leds[pixel[pixel[dt][0]][0]] = CRGB::Blue;

                          leds[pixel[pixel[dt][1]][0]] = CRGB::Blue; 
                          leds[pixel[pixel[dt][1]][2]] = CRGB::Blue;
                          
                          leds[pixel[pixel[dt][2]][2]] = CRGB::Blue;

                          
                          leds[pixel[pixel[dt][3]][2]] = CRGB::Blue;
                          leds[pixel[pixel[dt][3]][4]] = CRGB::Blue;

                          
                          leds[pixel[pixel[dt][4]][4]] = CRGB::Blue;
                          
                          leds[pixel[pixel[dt][5]][4]] = CRGB::Blue;    
                          leds[pixel[pixel[dt][5]][6]] = CRGB::Blue;    
                                                              
                          leds[pixel[pixel[dt][6]][6]] = CRGB::Blue; 
                                            
                          leds[pixel[pixel[dt][7]][0]] = CRGB::Blue;
                          leds[pixel[pixel[dt][7]][6]] = CRGB::Blue;

 }
    
                          
                          FastLED.show(); 
                          delay(10);

       
                          leds[dt] = CRGB::Black;
                          leds[pixel[dt][0]] = CRGB::Black;
                          
                          leds[pixel[dt][1]] = CRGB::Black;
                          leds[pixel[dt][2]] = CRGB::Black;
                          leds[pixel[dt][3]] = CRGB::Black;
                          leds[pixel[dt][4]] = CRGB::Black;
                          leds[pixel[dt][5]] = CRGB::Black;                                        
                          leds[pixel[dt][6]] = CRGB::Black; 
                          leds[pixel[dt][7]] = CRGB::Black;   


                          leds[pixel[pixel[dt][0]][0]] = CRGB::Black;

                          leds[pixel[pixel[dt][1]][0]] = CRGB::Black; 
                          leds[pixel[pixel[dt][1]][2]] = CRGB::Black;
                          
                          leds[pixel[pixel[dt][2]][2]] = CRGB::Black;

                          
                          leds[pixel[pixel[dt][3]][2]] = CRGB::Black;
                          leds[pixel[pixel[dt][3]][4]] = CRGB::Black;

                          
                          leds[pixel[pixel[dt][4]][4]] = CRGB::Black;
                          
                          leds[pixel[pixel[dt][5]][4]] = CRGB::Black;    
                          leds[pixel[pixel[dt][5]][6]] = CRGB::Black;    
                                                              
                          leds[pixel[pixel[dt][6]][6]] = CRGB::Black; 
                                            
                          leds[pixel[pixel[dt][7]][0]] = CRGB::Black;
                          leds[pixel[pixel[dt][7]][6]] = CRGB::Black;



                                          
                          FastLED.show();     
                  }
            
              }      
          }
    
   //         leds[i].setRGB( (Xcol), (Ycol), (Zcol));          
       
    //Increment counter  
    gc++;  
  }     
   
}

//********************************************
// Counter
// *******************************************
void Counter() { // LED stays in top of sphere


  
    if (nctr == 9) {
          nine();  
    } else
    
    if (nctr == 8) {
           eight(); 
    } else
    if (nctr == 7) {
          seven();  
    } else
    if (nctr == 6) {
          six();  
    } else
    
    if (nctr == 5) {
          five();  
    } else
    if (nctr == 4) {
          four();  
    } else
    if (nctr == 3) {
          three();  
    } else
    
    if (nctr == 2) {
          two();  
    } else
    if (nctr == 1) {
          one();  
    } else
    if (nctr == 0) {
          zero();  
    }

  nctr--;
  if (nctr < 0) {
    nctr = 9;
  }
 
   

}

//********************************************
// DotsnakesSpeed 
// *******************************************

void DotSnakesSpeed() {

// Use the Amplitude of the Mic input to set the delay for the DotSnakes


  if (fps > 24) {
    if (peak1.available()) {
      fps = 0;
      monoPeak = abs((peak1.read() * td)); // Remove noise level 
      if (monoPeak >td ) {
        monoPeak = td;
        }      
    }

  }
 
 //Clear all current LEDs


     leds[dot[0][0]] = CRGB::Black;  // Turn off current LED position
     leds[dot[0][2]] = CRGB::Black;  // Turn off current LED position
     leds[dot[0][3]] = CRGB::Black;  // Turn off current LED position    
     leds[dot[0][4]] = CRGB::Black;  // Turn off current LED position        

     leds[dot[1][0]] = CRGB::Black;  // Turn off current LED position
     leds[dot[1][2]] = CRGB::Black;  // Turn off current LED position
     leds[dot[1][3]] = CRGB::Black;  // Turn off current LED position    
     leds[dot[1][4]] = CRGB::Black;  // Turn off current LED position        

     leds[dot[2][0]] = CRGB::Black;  // Turn off current LED position
     leds[dot[2][2]] = CRGB::Black;  // Turn off current LED position
     leds[dot[2][3]] = CRGB::Black;  // Turn off current LED position    
     leds[dot[2][4]] = CRGB::Black;  // Turn off current LED position        

     leds[dot[3][0]] = CRGB::Black;  // Turn off current LED position
     leds[dot[3][2]] = CRGB::Black;  // Turn off current LED position
     leds[dot[3][3]] = CRGB::Black;  // Turn off current LED position    
     leds[dot[3][4]] = CRGB::Black;  // Turn off current LED position        
     FastLED.show(); 
     
//if (monoPeak > 1) { // No sound blank ball
  

     // Dot 0 **********************************************************

    
     // Randomly change direction of Dot
  
     direct = random8(8); // Randomly determine new direction

     // Check not going backwards    
     while ((abs(dot[0][1] - direct)) == 4){
        direct = random8(8); // Randomly determine new direction
     }
     
     dot[0][1] = direct; // Store value in array
    


    // Update position of data based on new direction before displaying
     dot[0][4] = dot[0][3]; // Store prevprev into prevprevprev location
     dot[0][3] = dot[0][2]; // Store prev into prevprev location
     dot[0][2] = dot[0][0]; // Store current into prev location   
      
     dot[0][0]= pixel[dot[0][0]][dot[0][1]]; // Use  function to read data back from array in Progam Memory




    // Dot 1**********************************************************


     // Randomly change direction of Dot
     direct = random8(8); // Randomly determine new direction
     // Check not going backwards    
     while ((abs(dot[1][1] - direct)) == 4){
        direct = random8(8); // Randomly determine new direction
     }
    
     dot[1][1] = direct; // Modify lead dot position and store value in array

     


    // Update position of data based on new direction before displaying
     dot[1][4] = dot[1][3]; // Store prevprev into prevprevprev location
     dot[1][3] = dot[1][2]; // Store prev into prevprev location
     dot[1][2] = dot[1][0]; // Store current into prev location   

     dot[1][0]= pixel[dot[1][0]][dot[1][1]];  // Use  function to read data back from array in Progam Memory



    
    // Dot 2 *****************************************  


     // Randomly change direction of Dot
     direct = random8(8); // Randomly determine new direction
     // Check not going backwards    
     while ((abs(dot[2][1] - direct)) == 4){
        direct = random8(8); // Randomly determine new direction
     }
     
     dot[2][1] = direct; // Store value in array

     
 

      // Update position of data based on new direction before displaying
       dot[2][4] = dot[2][3]; // Store prevprev into prevprevprev location
       dot[2][3] = dot[2][2]; // Store prev into prevprev location
       dot[2][2] = dot[2][0]; // Store current into prev location       
     
     dot[2][0]= pixel[dot[2][0]][dot[2][1]];   // Use pgm_read_byte function to read data back from array in Progam Memory




  
    // Dot 3 *****************************************  


     // Randomly change direction of Dot  
     direct = random8(8); // Randomly determine new direction
     // Check not going backwards    
     while ((abs(dot[3][1] - direct)) == 4){
        direct = random8(8); // Randomly determine new direction
     }     
     dot[3][1] = direct; // Store value in array


          


      // Update position of data based on new direction before displaying
       dot[3][4] = dot[3][3]; // Store prevprev into prevprevprev location
       dot[3][3] = dot[3][2]; // Store prev into prevprev location
       dot[3][2] = dot[3][0]; // Store current into prev location     
       
     dot[3][0]= pixel[dot[3][0]][dot[3][1]];   // Use pgm_read_byte function to read data back from array in Progam Memory


 // delay(100);

     leds[dot[0][0]] = CRGB::Blue; 
     leds[dot[0][2]] = CRGB::Blue; 
     leds[dot[0][3]] = CRGB::Blue;     
     leds[dot[0][4]] = CRGB::Blue;    
    
     leds[dot[1][0]] = CRGB::Red;
     leds[dot[1][2]] = CRGB::Red;
     leds[dot[1][3]] = CRGB::Red;     
     leds[dot[1][4]] = CRGB::Red;   

     leds[dot[2][0]] = CRGB::Green;
     leds[dot[2][2]] = CRGB::Green;
     leds[dot[2][3]] = CRGB::Green;     
     leds[dot[2][4]] = CRGB::Green;     

     leds[dot[3][0]] = CRGB::Purple;
     leds[dot[3][2]] = CRGB::Purple;
     leds[dot[3][3]] = CRGB::Purple;
     leds[dot[3][4]] = CRGB::Purple;        

     FastLED.show(); 


//        Serial.println(monoPeak);

     delay(240 - monoPeak*2);
//}
           
}

Credits

TechKiwiGadgets

TechKiwiGadgets

2 projects • 28 followers
I love the challenge of building unique things. My goal is to make technology fun. Passionate user of Design Thinking.

Comments