how can I edit this library code for 20 LED diodes, can anyone help me? I am still new at this programming.
Instructables?
We can't see your code.
Try with this:
const int chipCount = 3;
Do you even have anything wired?
everything's wired as it should be.
Still can't see your code
#include "FastLED.h"
#define NUM_LEDS 20
#define DATA_PIN 2
#define SCORE_PIN 6
#define SCORE_LEDS 4
//AUTHOR == Neehaw.com
//Check out more work from Neehaw.com
CRGB leds[NUM_LEDS];
CRGB sleds[SCORE_LEDS];
bool reachedEnd = false;
byte gameState = 0;
//byte ledSpeed = 0;
int period = 1000;
unsigned long time_now = 0;
byte Position = 0;
byte level = 0;
const byte ledSpeed[4] = {50, 40, 35, 20};
const byte colorType[21] = {255, 0, 0, //red 0
0, 255, 0, //green 1
0, 0, 255, //blue 2
255, 255, 0,//yellow 3
0, 255, 255,//cyan 4
255, 0, 255,//pink 5
255, 175, 0 //orange 6
};
byte colorChoice = 0;
byte oldChoice = 0;
//Debounce
bool findRandom = false;
byte spot = 0;
/*Note there are two games in this version. To toggle between games, turn on the device. Watch as the right side led strip(scoreboard)
switches from a single red led to two blue leds. Whichever mode is displaying will determain what gametype the player will play. It will switch
between game modes ever couple of seconds
GAME 1(red led on): It will prompt the user to select a color and will cycle through colors. Once the button is pressed, whatever color that
was currently on will be the next color. Afterwards, the user has to press the button when the next color appears.
Game 2(two blue leds on): The normal cyclon game. The red dot will spin and the user has to press it between the givin margins.
*/
void setup() {
// put your setup code here, to run once:
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.addLeds<WS2812B, SCORE_PIN, GRB>(sleds, SCORE_LEDS);
pinMode(4, INPUT_PULLUP);
Serial.begin(9600);
Serial.println("Reset");
}
void loop() {
if (gameState == 0) {
fill_rainbow(leds, NUM_LEDS, 0, 7); //2 = longer gradient strip
if (millis() > time_now + period) {
time_now = millis();
switch (level) {
case 0:
sleds[0].setRGB(255, 0, 0);
sleds[1].setRGB(0, 0, 0);
level++;
FastLED.show();
break;
case 1:
sleds[0].setRGB(0, 0, 255);
sleds[1].setRGB(0, 0, 255);
level = 0;
FastLED.show();
break;
}
}
if (digitalRead(4) == LOW) { //if button was pressed
Position = 0;
findRandom = true;
delay(500);
for (byte i = 0; i < NUM_LEDS; i++) {
leds[i].setRGB(0, 0, 0);
delay(40);
FastLED.show();
}
for (byte i = 0; i < SCORE_LEDS; i++) {
sleds[i].setRGB(0, 0, 0);
delay(100);
FastLED.show();
}
if (level == 0) {
gameState = 1;
} else if (level == 1) {
gameState = 5;
}
}
FastLED.show();
}
//Game 1
if (gameState == 1) {
period = ledSpeed[0];
if (millis() > time_now + period) {
time_now = millis();
if (findRandom) {
spot = random(16) + 3;
findRandom = false;
}
leds[spot - 1].setRGB(255, 140, 0);
leds[spot].setRGB(0, 255, 0);
leds[spot + 1].setRGB(255, 110, 0);
sleds[0].setRGB(0, 255, 0);
PlayGame(spot - 1, spot + 1);
}
if (digitalRead(4) == LOW) {
delay(300);
findRandom = false;
if (Position > spot - 1 && Position < spot + 3) {
level = gameState;
gameState = 98;
} else {
gameState = 99;
}
}
}
if (gameState == 2) {
// period = 320;
period = ledSpeed[1];
if (millis() > time_now + period) {
time_now = millis();
if (findRandom) {
spot = random(16) + 3;
findRandom = false;
}
leds[spot - 1].setRGB(255, 190, 0);
leds[spot].setRGB(0, 255, 0);
leds[spot + 1].setRGB(255, 190, 0);
sleds[1].setRGB(255, 255, 0);
PlayGame(spot - 1, spot + 1);
}
if (digitalRead(4) == LOW) {
delay(300);
if (spot - 1 && Position < spot + 3) {
level = gameState;
gameState = 98;
} else {
gameState = 99;
}
}
}
if (gameState == 3) {
period = ledSpeed[2];
if (millis() > time_now + period) {
time_now = millis();
if (findRandom) {
spot = random(16) + 3;
findRandom = false;
}
leds[spot].setRGB(0, 255, 0);
sleds[2].setRGB(255, 50, 0);
PlayGame(spot, spot);
}
if (digitalRead(4) == LOW) {
delay(300);
if (Position == spot + 1) {
level = gameState;
gameState = 98;
} else {
gameState = 99;
}
}
}
if (gameState == 4) {
period = ledSpeed[3];
if (millis() > time_now + period) {
time_now = millis();
if (findRandom) {
spot = random(16) + 3;
findRandom = false;
}
leds[spot].setRGB(0, 255, 0);
sleds[3].setRGB(255, 0, 0);
PlayGame(spot, spot);
}
if (digitalRead(4) == LOW) {
delay(300);
if (Position == spot + 1) {
level = gameState;
gameState = 98;
} else {
gameState = 99;
}
}
}
if (gameState == 98) {
winner();
}
if (gameState == 99) {
loser();
}
if (gameState == 5) {
pickColor();
}
if (gameState == 6) {
PlayGame2();
}
}
void PlayGame(byte bound1, byte bound2) {
leds[Position].setRGB(255, 0, 0);
if (Position < bound1 + 1 || Position > bound2 + 1) {
leds[Position - 1].setRGB(0, 0, 0);
}
FastLED.show();
Position++;
if (Position >= NUM_LEDS) {
leds[Position - 1].setRGB(0, 0, 0);
Position = 0;
}
}
//End Game 1
//Start Game 2
void pickColor() {
if (gameState == 5) { //Pick a color
period = 1000;
if (millis() > time_now + period) {
time_now = millis();
byte oldChoice = 0;
oldChoice = colorChoice;
colorChoice = random(6);
while (colorChoice == oldChoice) {
colorChoice = random(6);
}
for (byte i = 0; i < SCORE_LEDS; i++) {
sleds[i].setRGB(colorType[colorChoice * 3], colorType[colorChoice * 3 + 1], colorType[colorChoice * 3 + 2]);
}
leds[0].setRGB(colorType[colorChoice * 3], colorType[colorChoice * 3 + 1], colorType[colorChoice * 3 + 2]);
leds[1].setRGB(colorType[colorChoice * 3], colorType[colorChoice * 3 + 1], colorType[colorChoice * 3 + 2]);
FastLED.show();
}
if (digitalRead(4) == LOW) {
Position = 2;
period = 500;
level = colorChoice;
delay(700);
gameState = 6;
}
}
}
void PlayGame2() {
if (millis() > time_now + period) {
time_now = millis();
colorChoice = random(6);
leds[Position].setRGB(colorType[colorChoice * 3], colorType[colorChoice * 3 + 1], colorType[colorChoice * 3 + 2]);
leds[Position + 1].setRGB(colorType[colorChoice * 3], colorType[colorChoice * 3 + 1], colorType[colorChoice * 3 + 2]);
FastLED.show();
}
if (digitalRead(4) == LOW) {
if (level == colorChoice) {
if (Position <= 18) {
delay(300);
Position += 2;
period -= 50;
} else {
delay(400);
winner();
}
}
else{
delay(400);
loser();
}
}
}
void winner() {
for (byte i = 0; i < 3; i++) {
for (byte j = 0; j < NUM_LEDS; j++) {
leds[j].setRGB(0, 255, 0);
}
FastLED.show();
delay(500);
clearLEDS();
FastLED.show();
delay(500);
}
findRandom = true;
Position = 0;
gameState = level + 1;
if (gameState > 4) {
gameState = 0;
}
}
void loser() {
for (byte i = 0; i < 3; i++) {
for (byte j = 0; j < NUM_LEDS; j++) {
leds[j].setRGB(255, 0, 0);
}
FastLED.show();
delay(500);
clearLEDS();
FastLED.show();
delay(500);
}
Position = 0;
level = 0;
gameState = 0;
}
void clearLEDS() {
for (byte i = 0; i < NUM_LEDS; i++) {
leds[i].setRGB(0, 0, 0);
}
for (byte i = 0; i < SCORE_LEDS; i++) {
sleds[i].setRGB(0, 0, 0);
}
level = 0;
period = 1000;
}
So, you link to some external code, ask for help, then post a totally different code?!
WTF, man?!
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.