Go Down

Topic: Need some help With coding a ws2812b project (Read 1 time) previous topic - next topic

moJoeRedRog

Bonjour amigo's

I am working on a new project that I need help with, I am prototyping a new setup for a big wheel Lotto game.  It features a wheel of RGB's 24 of them, and 8 RGB's in a wheel inside the large wheel of 24.  The Purpose of the game is to make a selection from the 8 RGB Wheel and then press spin to make the RGB's in the outer larger wheel go around in a circle more than 5 times and then coming to a stop at a random spot in the wheel that is compared to the 1 in 8 selected.  If the number reduced to 8ths match then you win. 

Here is my wiring schematic.



and here is my code so far.
Code: [Select]


/* This Project is a big Led light wheel with a smaller led light wheel in the center.
 *  the big wheel has 24 RGB's and the inner "selection" wheel has 8 RGB's
 *  the point is to select a RGB with a Pot in the inner smaller ring
 *  and have it match or try to match the end of the loop of LED's
 *  when they stop at a random place.  So if user selects place number 5 for example
 *  then they need the wheel to stop at place 12 trough 15 in the outer ring.
 *  I will be adding a third strand of RGB's to add some flare to getting a match
 *  or not getting a match.  I would like the outer RGB Ring to go around at least
 *  5 times before having a random number from 1 to 24 multiply lets say another
 *  3 times around so it will reach a random spot on every spin. THen a button resets the
 *  action.  So the pot selects from 1 to 8 and the first button begins the leds in the outer ring
 *  going round and then they are brought to a stop at a random location that is compared
 *  to the user selected number in the first ring of 1 to 8.  Each number from 1 to 8 in the
 *  inner ring has 3 spots on the outer ring that would be a match, so it looks a little like a dart board  A simple game of
 *  guess the number with ws2812b's
 */



#include <JC_Button.h>
const byte Pin_button2 = 6;//The reset Button
const byte Pin_button3 = 5;//The spin Button
Button RESETGAME (Pin_button2);
Button SPIN (Pin_button3);
#include <pRNG.h> //randomizing library gives a random result of 0 to 255
pRNG prng;
#include <FastLED.h> //My led data pins and each Strip LED count
#define NUM_LEDS 8
#define DATA_PIN 2
#define DATA_PIN2 3
#define DATA_PIN3 4
#define NUM_LEDS2 24
#define NUM_LEDS3 5
CRGB leds[NUM_LEDS];
CRGB leds2[NUM_LEDS2];
CRGB leds3[NUM_LEDS3];
//Declare some Gloabal Variables
int pick; //the number selected by gambler
int analogPin = 1; //the pin the analog selector is on 10k pot used
int spinIt;
int outerLEDS[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23};



void setup() {
  // put your setup code here, to run once:
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);  //initalize the first strand
  FastLED.addLeds<NEOPIXEL, DATA_PIN2>(leds2, NUM_LEDS2); //initialie the second strand
  FastLED.addLeds<NEOPIXEL, DATA_PIN3>(leds3, NUM_LEDS3); //initialie the Third strand
  RESETGAME.begin();
  SPIN.begin();
  Serial.begin(2400);

}

void loop() {
  // put your main code here, to run repeatedly:
  pick = analogRead(analogPin);//the user selects a int from 1 to 1023
  pick = map(pick, 0, 1023, 1, 8);//the dial is maped to 1 to 8
  Serial.print("Bet Selected:");
  Serial.println(pick);
  selectNumber();
  checkbuttons();
 

}

void checkbuttons() {
  SPIN.read();  //read the spin button
  if (SPIN.wasReleased()) outerSpin(); //initiate the spinning of the big wheel of LED's
  RESETGAME.read();
  if (RESETGAME.wasReleased()) resetGame();//reset the game when the button is pressed
}



int outerSpin() { //spins the outer ring of LED's would like it to do 4 circles plus a rondom 2 to 5 aditional circles and stop at a random spot
    int dot = 0;
    byte spinIt = prng.getRndByte(); //gets a random number to multiply the number of more Led's that cycle
    spinIt = map (spinIt, 0, 255, 1, 24); //maping the random number
    Serial.print("Random Number:");
    Serial.print(spinIt);
    for (int dot = 0; dot < NUM_LEDS2; dot++) { //makes the leds go around once, need to repeat
    leds2[dot] = CRGB::Purple;
    FastLED.show();
    // clear this led for the next time around the loop
    leds2[dot] = CRGB::Black;
    delay(65);
       
  }

}

void resetGame() { //looking to Reset all LED's and start from the begining
  FastLED.clear();
  FastLED.show();
}


void selectNumber() { //the code that selects the number and lights up the indicating LED
  if (pick == 1) {
    leds[1] = CRGB::Black;
    leds[0] = CRGB::Blue;
    FastLED.show();
  } else if (pick == 2) {
    leds[2] = CRGB::Black;
    leds[0] = CRGB::Black;
    leds[1] = CRGB::Blue;
    FastLED.show();
  } else if (pick == 3) {
    leds[3] = CRGB::Black;
    leds[1] = CRGB::Black;
    leds[2] = CRGB::Blue;
    FastLED.show();
  } else if (pick == 4) {
    leds[4] = CRGB::Black;
    leds[2] = CRGB::Black;
    leds[3] = CRGB::Blue;
    FastLED.show();
  } else if (pick == 5) {
    leds[5] = CRGB::Black;
    leds[3] = CRGB::Black;
    leds[4] = CRGB::Blue;
    FastLED.show();
  } else if (pick == 6) {
    leds[6] = CRGB::Black;
    leds[4] = CRGB::Black;
    leds[5] = CRGB::Blue;
    FastLED.show();
  } else if (pick == 7) {
    leds[7] = CRGB::Black;
    leds[5] = CRGB::Black;;
    leds[6] = CRGB::Blue;
    FastLED.show();
  } else if (pick == 8) {
    leds[6] = CRGB::Black;
    leds[7] = CRGB::Blue;
    FastLED.show();
  }


}





The code needs work.  I need to be able to spin through the 24 RGB strand more than 5 times and then stop randomly at any spot in the strip.  Then I need to compare the result to "pick" integer and have a third light strip light green on matches and red on wrongs.  When the reset button is push and its back to the start I want the third strip to Flicker on white.  any thoughts or help would be great.


lesept

Hi
Your code is well written but maybe it can be made simpler.
You need to write a loop that reads the reset button and executes some other functions until the reset button is pushed. The functions are mainly
1- read the pot and light the corresponding led in the inner strip until the start button is pushed. This enables to choose more easily the first bet.
2- take a random number, run the animation (do five rounds and stop on the chosen position). It would be great to make the speed change during this animation, faster at the beginning and slower at the end. This is done with delay having a variable argument.
3- depending on the result, do the thing you want with the third strip

See if you can write the first function which is the easiest one. Then try it and if you're satisfied write the second one...
I can help you if you need it.
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

Paul__B

Use an encoder instead of a pot.  This is the 21st century.

Note that in actual construction, those series resistors should be connected at the actual input to the WS2812Bs rather than at the Arduino.

moJoeRedRog

#3
Aug 10, 2018, 03:49 am Last Edit: Aug 10, 2018, 05:48 am by moJoeRedRog
Use an encoder instead of a pot.  This is the 21st century.

Note that in actual construction, those series resistors should be connected at the actual input to the WS2812Bs rather than at the Arduino.

Thank you for the tip but at twice the price I like the pots.  Only 3 wires and they got what i needed done before.  Could I ask what is there advantage(s) over cheap and common pots?

Paul__B

Thx for the tip but at twice the price I like the pots.  Only 3 wires and they got what I needed done before.  Could I ask what is there advantage(s) over cheap and common pots?
Easier to set the exact value, particularly over a wide range where you are able to spin them many revolutions; more durable.

moJoeRedRog

Easier to set the exact value, particularly over a wide range where you are able to spin them many revolutions; more durable.

Sound Superior is every way.  Next time I get supplies I will pick up a couple,  see them in action,

moJoeRedRog

Ok I have got the selector pot working fine.  The variable "pick" holds the value as a int and can be compared to later.  I am scratching my head with my outerSpin Function.  I can only get it to go around once.  I am trying to use a variable to add 1 to every time it goes around and to stop at 5 but it wont work.  here is the code for my function.

Code: [Select]

int outerSpin() { //spins the outer ring of LED's would like it to do 4 circles plus a rondom 2 to 5 aditional circles and stop at a random spot
  int spin; // a integer to store the number of times around its gone and to stop the wheel of LEDs
  byte spinIt = prng.getRndByte(); //gets a random number to multiply the number of more Led's that cycle
  spinIt = map (spinIt, 0, 255, 1, 24); //maping the random number
  Serial.print("Random Number:");
  Serial.println(spinIt);
  Serial.println("spin number:");
  Serial.println(spin);
  if (spin <= 5) {
    for (int dot = 0; dot < NUM_LEDS2; dot++) { //makes the leds go around once, need to repeat
      leds2[dot] = CRGB::Purple;
      FastLED.show();
      // clear this led for the next time around the loop
      leds2[dot] = CRGB::Black;
      delay(varDelay);
      if (dot == 23, spin++); //when the circle is complete this adds 1 to spin and the circle goes again ^not working

    }
  }

  spin = spin + 1; // trying to add one to the spin variable which allows the for loop to run until spin hits 5

}


Not sure I am barking up the right tree. 

lesept

Just do a for loop of 24 inside a for loop of 5 and finally do the leds until the one you choose randomly
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

moJoeRedRog

#8
Aug 11, 2018, 04:54 pm Last Edit: Aug 11, 2018, 06:24 pm by moJoeRedRog
I am finally understanding the for Loop better.  I did that and it worked, I am trying to have the function return to the loop the final result of the random spin result but it just returns 0;  Here is the code.

Code: [Select]


#include <JC_Button.h>
const byte Pin_button2 = 6;//The reset Button
const byte Pin_button3 = 5;//The spin Button
Button RESETGAME (Pin_button2);
Button SPIN (Pin_button3);
#include <pRNG.h> //randomizing library gives a random result of 0 to 255
pRNG prng;
#include <FastLED.h> //My led data pins and each Strip LED count
#define NUM_LEDS 8
#define DATA_PIN 2
#define DATA_PIN2 3
#define DATA_PIN3 4
#define NUM_LEDS2 24
#define NUM_LEDS3 5
CRGB leds[NUM_LEDS];
CRGB leds2[NUM_LEDS2];
CRGB leds3[NUM_LEDS3];
//Declare some Gloabal Variables
int pick; //the number selected by gambler
int analogPin = 1; //the pin the analog selector is on 10k pot used
int spinIt;
int outerLEDS[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23};//not needed array
int varDelay = 50;


void setup() {
  // put your setup code here, to run once:
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);  //initalize the first strand
  FastLED.addLeds<NEOPIXEL, DATA_PIN2>(leds2, NUM_LEDS2); //initialie the second strand
  FastLED.addLeds<NEOPIXEL, DATA_PIN3>(leds3, NUM_LEDS3); //initialie the Third strand
  RESETGAME.begin();
  SPIN.begin();
  Serial.begin(2400);

}

void loop() {
  // put your main code here, to run repeatedly:
  pick = analogRead(analogPin);//the user selects a int from 1 to 1023
  pick = map(pick, 0, 1020, 1, 8);//the dial is maped to 1 to 8
  Serial.print("Bet Selected:");
  Serial.println(pick);
  //Serial.print ("result:");
  //Serial.println(spinIt);
  selectNumber();
  checkbuttons();


}

void checkbuttons() {
  int finalResult;
  SPIN.read();  //read the spin button
  if (SPIN.wasReleased()) outerSpin(); { //spins LED wheel and compares pick to spinIt
    Serial.print ("final result:");
    Serial.println(finalResult);
  }
  RESETGAME.read();
  if (RESETGAME.wasReleased()) resetGame();//reset the game when the button is pressed
}



int outerSpin() { //spins the outer ring of LED's would like it to do 4 circles plus a rondom 2 to 5 aditional circles and stop at a random spot
  int spin; // a integer to store the number of times around its gone and to stop the wheel of LEDs
  int spinIt = prng.getRndByte(); //gets a random number to multiply the number of more Led's that cycle
  spinIt = map (spinIt, 0, 255, 1, 24); //maping the random number
  Serial.print("Random Number:");
  Serial.println(spinIt);
  for (int spin = 0; spin < 7; spin++) { //makes leds go around for 7 loops
    for (int dot = 0; dot < NUM_LEDS2; dot++) { //leds go around once per loop
      leds2[dot] = CRGB::Purple;
      FastLED.show();
      leds2[dot] = CRGB::Black;
      delay(varDelay);
    }
  } for (int dot = 0; dot < spinIt; dot++) {  // the final loop with random selection of final spot
    leds2[dot] = CRGB::Cyan;
    FastLED.show();
    leds2[dot] = CRGB::Black;
    delay(varDelay);
  }
  leds2[spinIt] = CRGB::Cyan; //keeps the last led on
  FastLED.show();
  int finalResult = spinIt;  //trying to return the int spinIt
  return finalResult;

}




void resetGame() { //looking to Reset all LED's and start from the begining
  FastLED.clear();
  FastLED.show();
}


void selectNumber() { //the code that selects the number and lights up the indicating LED
  if (pick == 1) {
    leds[1] = CRGB::Black;
    leds[0] = CRGB::Blue;
    FastLED.show();
  } else if (pick == 2) {
    leds[2] = CRGB::Black;
    leds[0] = CRGB::Black;
    leds[1] = CRGB::Blue;
    FastLED.show();
  } else if (pick == 3) {
    leds[3] = CRGB::Black;
    leds[1] = CRGB::Black;
    leds[2] = CRGB::Blue;
    FastLED.show();
  } else if (pick == 4) {
    leds[4] = CRGB::Black;
    leds[2] = CRGB::Black;
    leds[3] = CRGB::Blue;
    FastLED.show();
  } else if (pick == 5) {
    leds[5] = CRGB::Black;
    leds[3] = CRGB::Black;
    leds[4] = CRGB::Blue;
    FastLED.show();
  } else if (pick == 6) {
    leds[6] = CRGB::Black;
    leds[4] = CRGB::Black;
    leds[5] = CRGB::Blue;
    FastLED.show();
  } else if (pick == 7) {
    leds[7] = CRGB::Black;
    leds[5] = CRGB::Black;;
    leds[6] = CRGB::Blue;
    FastLED.show();
  } else if (pick == 8) {
    leds[6] = CRGB::Black;
    leds[7] = CRGB::Blue;
    FastLED.show();
  }


}

void guessRight() {  //if your selection was right 3rd strand lights up green
  leds3[0] = CRGB::Green;
  FastLED.show();
  leds3[1] = CRGB::Green;
  FastLED.show();
  leds3[2] = CRGB::Green;
  FastLED.show();
  leds3[3] = CRGB::Green;
  FastLED.show();
  leds3[4] = CRGB::Green;

}

void guessWrong() { //If your selection was wrong the 3rd strand lights up red
  leds3[0] = CRGB::Red;
  FastLED.show();
  leds3[1] = CRGB::Red;
  FastLED.show();
  leds3[2] = CRGB::Red;
  FastLED.show();
  leds3[3] = CRGB::Red;
  FastLED.show();
  leds3[4] = CRGB::Red;

}


Any tips or advice on how to return the value of the random number and compare it to the selected bet which is stored as the "int pick" would be great.  The guessRight() and guessWrong() functions are just my LED code that turns the 3rd strand all green for right or all red for wrong.  Once it is all working right I plan to add a buzzer and the song Yankee Doodle Dandy :) For correct matches

lesept

You should call the function outerspin as result = outerspin () ;

Also you should move the delay in the outerspin function before the leds2[dot] = CRGB::Black;
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

lesept

#10
Aug 11, 2018, 10:30 pm Last Edit: Aug 11, 2018, 10:51 pm by lesept
If you want to have a varying duration for the leds you just need to count every time you lit an led and map this number to a duration
Duration =map (count, 0,total number, longdelay, shortdelay) ;
Total number is 7*24+spinit
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

lesept

#11
Aug 11, 2018, 10:45 pm Last Edit: Aug 11, 2018, 10:52 pm by lesept
Also if you want to play again, you must have every part of the game in the loop. Then the loop must check for the button bring pressed to start again

This would look like this for the loop
1 take the bet
2 spin the wheel
3 do the third strip
4 wait for the button
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

lesept

#12
Aug 11, 2018, 10:49 pm Last Edit: Aug 11, 2018, 10:53 pm by lesept
For the bet, you should do the same :do read the pot + light the led, until the button is pressed
This enables to change the bet more easily.

Sorry for these short messages, I'm on a smartphone with very bad WiFi...
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

moJoeRedRog

For the bet, you should do the same :do read the pot + light the led, until the button is pressed
This enables to change the bet more easily.

Sorry for these short messages, I'm on a smartphone with very bad WiFi...
no need to apologize, I thank you for your help

I will work on what you have instructed and post the results.

moJoeRedRog

Ok lesept I did what you instructed and it all is somewhat working now.  The dial picks a number from 1 to 8 and lights up a led in the inner ring.  Then the spin Button starts it spinning and it stops at a random spot.  The result is compared and the third strip lights up accordingly. If a correct match is made it plays yankee doodle and lights up green.

I could not however get that duration = map stuff to work though.  Here is the code I came up with.

Code: [Select]

//yankee doodle
#define NB4 494
#define NC5 523
#define ND5 587
#define ND5S 622
#define NE5 660
#define NF5 698
#define NF5S 740
#define NG5 784
#define NA5 880
#define NB5 987
#define NC6 1046
#define NC6S 1108
#define ND6 1174
#define NE6 1318
#define NE6S 1244
#define NF6 1397
#define NG6 1568
#define NA6 1760 
#define NB6 1975
#define NC7 2093
#define Nrest 0

const int k_Speaker = 9;

#define yankee 75

const int notes[yankee] = {

NG5, NG5, NA5, NB5, NG5, NB5, NA5, ND5,
NG5, NG5, NA5, NB5, NG5, NF5S,
NG5, NG5, NA5, NB5, NC6, NB5, NA5, NG5,
NF5S, ND5, NE5, NF5S, NG5, NG5,
NG5, NG5, NA5, NB5, NG5, NB5, NA5, ND5,
NG5, NG5, NA5, NB5, NG5, NF5S,
NG5, NG5, NA5, NB5, NC6, NB5, NA5, NG5,
NF5S, ND5, NE5, NF5S, NG5, NG5,
 
};

const int beats[yankee] = {
4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 8, 8,
4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 8, 8,
4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 8, 8,
4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 8, 8,
};

const int tempo = 60;

#include <JC_Button.h>
const byte Pin_button2 = 6;//The reset Button
const byte Pin_button3 = 5;//The spin Button
Button RESETGAME (Pin_button2);
Button SPIN (Pin_button3);
#include <pRNG.h> //randomizing library gives a random result of 0 to 255
pRNG prng;
#include <FastLED.h> //My led data pins and each Strip LED count
#define NUM_LEDS 8
#define DATA_PIN 2
#define DATA_PIN2 3
#define DATA_PIN3 4
#define NUM_LEDS2 24
#define NUM_LEDS3 5
CRGB leds[NUM_LEDS];
CRGB leds2[NUM_LEDS2];
CRGB leds3[NUM_LEDS3];
//Declare some Gloabal Variables
int pick; //the number selected by gambler
int analogPin = 1; //the pin the analog selector is on 10k pot used
int spinIt;
int outerLEDS[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23};//not needed array
int varDelay = 50;
int result = 9;

void setup() {
  // put your setup code here, to run once:
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);  //initalize the first strand
  FastLED.addLeds<NEOPIXEL, DATA_PIN2>(leds2, NUM_LEDS2); //initialie the second strand
  FastLED.addLeds<NEOPIXEL, DATA_PIN3>(leds3, NUM_LEDS3); //initialie the Third strand
  RESETGAME.begin();
  SPIN.begin();
  Serial.begin(2400);
  pinMode(k_Speaker, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  pick = analogRead(analogPin);//the user selects a int from 1 to 1023
  pick = map(pick, 0, 1020, 1, 8);//the dial is maped to 1 to 8
  Serial.print("Bet Selected:");
  Serial.println(pick);
  selectNumber();
  SPIN.read();  //read the spin button
  if (SPIN.wasReleased()) result = outerSpin();
  Serial.print ("result:");
  Serial.println(result);
  RESETGAME.read();
  if (RESETGAME.wasReleased()) resetGame();//reset the game when the button is pressed

 
}

int outerSpin() { //spins the outer ring of LED's would like it to do 4 circles plus a rondom 2 to 5 aditional circles and stop at a random spot
  int duration;
  int spin; // a integer to store the number of times around its gone and to stop the wheel of LEDs
  int spinIt = prng.getRndByte(); //gets a random number to multiply the number of more Led's that cycle
  spinIt = map (spinIt, 0, 255, 1, 24); //maping the random number
  Serial.print("Random Number:");
  Serial.println(spinIt);
  for (int spin = 0; spin < 5; spin++) { //makes leds go around for 7 loops
    for (int dot = 0; dot < NUM_LEDS2; dot++) { //leds go around once per loop
      leds2[dot] = CRGB::Purple;
      delay(varDelay);
      FastLED.show();
      leds2[dot] = CRGB::Black;
    }
  } for (int dot = 0; dot < spinIt; dot++) {  // the final loop with random selection of final spot
    leds2[dot] = CRGB::Cyan;
    delay(varDelay);
    FastLED.show();   
    leds2[dot] = CRGB::Black;
  }
  leds2[spinIt] = CRGB::Cyan; //keeps the last led on
  FastLED.show();
  int result = spinIt;   
  result = map(result, 1, 24, 1, 8); //maping the outerwheel to 1 in 8
  Serial.print("mapped amount:");
  Serial.println(result);
  if (result == pick) {  // compare the result to the pick
    guessRight();       
  } else {               
    guessWrong();
  }
  return result;
 
}

void resetGame() { //looking to Reset all LED's and start from the begining
  FastLED.clear();
  FastLED.show();
  leds3[0] = CRGB::Black;
  FastLED.show();
  leds3[1] = CRGB::Black;
  FastLED.show();
  leds3[2] = CRGB::Black;
  FastLED.show();
  leds3[3] = CRGB::Black;
  FastLED.show();
  leds3[4] = CRGB::Black;

}


void selectNumber() { //the code that selects the number and lights up the indicating LED
  if (pick == 1) {
    leds[1] = CRGB::Black;
    leds[0] = CRGB::Blue;
    FastLED.show();
  } else if (pick == 2) {
    leds[2] = CRGB::Black;
    leds[0] = CRGB::Black;
    leds[1] = CRGB::Blue;
    FastLED.show();
  } else if (pick == 3) {
    leds[3] = CRGB::Black;
    leds[1] = CRGB::Black;
    leds[2] = CRGB::Blue;
    FastLED.show();
  } else if (pick == 4) {
    leds[4] = CRGB::Black;
    leds[2] = CRGB::Black;
    leds[3] = CRGB::Blue;
    FastLED.show();
  } else if (pick == 5) {
    leds[5] = CRGB::Black;
    leds[3] = CRGB::Black;
    leds[4] = CRGB::Blue;
    FastLED.show();
  } else if (pick == 6) {
    leds[6] = CRGB::Black;
    leds[4] = CRGB::Black;
    leds[5] = CRGB::Blue;
    FastLED.show();
  } else if (pick == 7) {
    leds[7] = CRGB::Black;
    leds[5] = CRGB::Black;;
    leds[6] = CRGB::Blue;
    FastLED.show();
  } else if (pick == 8) {
    leds[6] = CRGB::Black;
    leds[7] = CRGB::Blue;
    FastLED.show();
  }


}

void guessRight() {  //if your selection was right 3rd strand lights up green
  leds3[0] = CRGB::Green;
  FastLED.show();
  leds3[1] = CRGB::Green;
  FastLED.show();
  leds3[2] = CRGB::Green;
  FastLED.show();
  leds3[3] = CRGB::Green;
  FastLED.show();
  leds3[4] = CRGB::Green;
  FastLED.show();
  doodle();

}

void guessWrong() { //If your selection was wrong the 3rd strand lights up red
  leds3[0] = CRGB::Red;
  FastLED.show();
  leds3[1] = CRGB::Red;
  FastLED.show();
  leds3[2] = CRGB::Red;
  FastLED.show();
  leds3[3] = CRGB::Red;
  FastLED.show();
  leds3[4] = CRGB::Red;
  FastLED.show();

}

void doodle(){
  for (int i = 0; i < yankee; i ++){
    if (notes[i] == 0){
      delay(beats[i] * 60);
    }
    else{
      ourTone(notes[i], beats[i] * 60);
    }
    delay(tempo /2);
  }

}
void ourTone(int freq, int duration){
  long timeDelay = (1000000 / (2 * freq));
  long endTime = millis() + duration;
  while (millis() < endTime){
    digitalWrite(k_Speaker, HIGH);
   
    delayMicroseconds(timeDelay);
    digitalWrite(k_Speaker, LOW);
   
    delayMicroseconds(timeDelay);
  }
}



Go Up