I made a version of this Cyclone game (link below to code and circuit)

I made a version of this Cyclone game (link below to code and circuit) that uses fastLED pattern cylon when you win. I want it to trigger the fire2012 pattern instead but I can’t figure out how. Can someone help me modify the code to call a different fastLED pattern? https://www.instructables.com/id/Cyclone-LED-Arcade-Game/#discuss

I want it to trigger the fire2012 pattern, but I can’t figure out how. Can you help?

In the example you shared, there’s two things going on that allow you to see the cylon pattern animate.

  1. when it’s called, it’s called inside a loop (either i < 2 or i < 8 depending on the difficulty level), and then
  2. inside the cylon function there are two for loops that run forward and backward through NUM_LEDS And .show() calls to display those updates.

If you add the void Fire2012() function to the code and simply replace the call to run cylon() with Fire2012() you won’t really see much because
a) it’s only calling it two times (two VERY fast times around the main loop) and
b) there isn’t a show() inside the Fire2012 function to even display those two very fast updates.

So you need to do something like (and this is just one possible solution) put all the stuff inside the Fire2012 function inside a loop in the function so it will run a number of times (maybe 50) so you can actually create some animation, AND you also need to call show() after each update inside that loop to be able to see the pixels updates. You will probably want a tiny bit of a delay as well (similar to how it runs in the Fire2012 example where the function is called, then show() is called, and then there is a short delay [lines 26-29 in Fire2012 example].

See if the above makes sense to you. If not come back with more questions! :slight_smile:

@marmil Thank you for you reply. I am so close now. I can see the fires start up for a fraction of a second, and then it returns to the main loop. I followed your directions as best as I could figure, but my inexperience made it unclear how to exactly do each task. So guessed and guessed, trial and error and over came some issues, but not all.

  1. I copied and pasted all the stuff inside the Fire2012 inside a loop, but I don’t know how to make it so it will run a number of times (maybe 50).
    2.I tried delay [like in lines 26-29] in various places but it doesn’t seem to improve.

I attached a video clip so you can see what’s happening. I’m not sure if it will post. Thanks for any help or other suggestions you may have.

Sincere thanks,
Lou

Here’s the code so far:
//FIRE_and_ICE Game

#include “FastLED.h”

#define NUM_LEDS 84
#define FIRSTLED_HOTZONE 0
#define LASTLED_HOTZONE 41
#define FIRSTLED_COLDZONE 42
#define LASTLED_COLDZONE 83

#define LED_PIN 6

#define LED_TYPE WS2811

#define CHIPSET WS2811

#define COLOR_ORDER GRB

//range 0-64
#define BRIGHTNESS 200
#define FRAMES_PER_SECOND 60
bool gReverseDirection = false;

//Definition of difficulty levels
#define EASY 1
#define MEDIUM 2
#define HARD 3
#define ON_SPEED 4
#define SONIC_SPEED 5
#define ROCKET_SPEED 6
#define LIGHT_SPEED 7
#define MISSION_IMPOSSIBLE 8

//Starting difficulty
int difficulty = 1;

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

// Did player win this round? This tag is used for difficulty parameters.
bool wonThisRound = false;

// Starting location of the cycling light
int LEDaddress = 0;

// Is game running?
bool Playing = true;

// Is this the first win?
bool CycleEnded = true;

// Confirmation Sensor details
const int confirmPin = A0;
int confirmState = 0;
// Primer Sensor details
const int primerPin = A5;
int primerState = 0;

// Initialize the led library and arduino functions

void setup()
{
delay(3000); // sanity delay
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);

//Set up Confirmation Sensor
pinMode(A0, INPUT); //Recieves signal from Confirmation Sensor
pinMode(A1, OUTPUT); //Gnd pin for Confirmation Sensor
pinMode(A2, OUTPUT); //VCC pin for Confirmation Sensor
digitalWrite(A2, HIGH);//supply Confirmation Sensor with 5V
digitalWrite(A1,LOW);//Connect Confirmation Sensor to ground

//Set up Primer Sensor
pinMode(A3, OUTPUT); //VCC pin for Primer Sensor
pinMode(A4, OUTPUT); //Gnd pin for Primer Sensor
pinMode(A5, INPUT); //Recieves signal from Primer Sensor
digitalWrite(A3, HIGH);//supply Primer Sensor with 5V
digitalWrite(A4,LOW);//Connect Primer Sensor to ground

Serial.begin(9600);
}

//Two Modes - Playing, and End Game
void loop()
{
confirmState = digitalRead(confirmPin);
if (confirmState == LOW)
{
Playing = false; //User has a confirmed basket made, and the LED has stopped on the winning address.
for (int i = 0; i < NUM_LEDS; i++)
{
leds [i] = CRGB::Black;
}
for(int i = FIRSTLED_HOTZONE; i <= LASTLED_HOTZONE; i++) {
leds[i] = CRGB::Red;
}

leds[LEDaddress] = CRGB::White;  
FastLED.show();
if (CycleEnded)
{
  //int diff = abs(CENTER_LED2 - LEDaddress); //Finds distance between the lit led and the center led
  if (LEDaddress >= FIRSTLED_HOTZONE && LEDaddress <= LASTLED_HOTZONE)
  {
    wonThisRound = true; //Player sucessfully beat the level
    if (difficulty != MISSION_IMPOSSIBLE)
     {
      for (int i = 0; i < 2; i++)
       {
      Fire2012();
       }
     }
    if (difficulty == MISSION_IMPOSSIBLE)
     {                                 
      for (int i = 0; i < 8; i++)
       {
        Fire2012();
       }
      difficulty = 0; 
     }
    increaseDifficulty();      
    wonThisRound = false;
  }
  
   else
  {
  delay(1000);  
  for (int i = 0; i < 2; i++)
   {
    flash();
   }
  }
    CycleEnded = false;
  }
LEDaddress = 0; 
delay(100);
confirmState = digitalRead(confirmPin);
if (confirmState == HIGH)
{
 Playing = true;
}

}

//PLAYING
if(Playing)
{
for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB::Black; //Turns off all the leds
}
for(int i = FIRSTLED_HOTZONE; i <= LASTLED_HOTZONE; i++) {
leds[i] = CRGB::Red;
}

// Cold Side Name of Color
for(int i = FIRSTLED_COLDZONE; i <= LASTLED_COLDZONE; i++) {
  leds[i] = CRGB::DodgerBlue;
}
leds[LEDaddress] = CRGB::White; //Sets cycling led color to White
FastLED.show(); //Initializes light cycle
LEDaddress++; //Sets light cycle to one led at a time
if (LEDaddress == NUM_LEDS)
{
  LEDaddress = 0;
}
delay(getTime(difficulty));
confirmState = digitalRead(confirmPin);
if (confirmState == LOW)
{
 Playing = false;
 CycleEnded = true;
}

}
}

//Level Parameters
int getTime(int diff) // Returns time delay for led movement base on difficulty
{
int timeValue = 0;
switch (diff)
{
case EASY:
timeValue = 40;
break;
case MEDIUM:
timeValue = 35;
break;
case HARD:
timeValue = 30;
break;
case ON_SPEED:
timeValue = 25;
break;
case SONIC_SPEED:
timeValue = 20;
break;
case ROCKET_SPEED:
timeValue = 15;
break;
case LIGHT_SPEED:
timeValue = 10;
break;
case MISSION_IMPOSSIBLE:
timeValue = 5;
}
return timeValue;// Return the delay amount
}

//Winning difficulty increase parameters
void increaseDifficulty()
{
if (difficulty != MISSION_IMPOSSIBLE && wonThisRound)
{
difficulty++;
}
FastLED.show(); // display this frame
FastLED.delay(1000 / FRAMES_PER_SECOND);
}

// COOLING: How much does the air cool as it rises?
// Less cooling = taller flames. More cooling = shorter flames.
// Default 50, suggested range 20-100
#define COOLING 20

// SPARKING: What chance (out of 255) is there that a new spark will be lit?
// Higher chance = more roaring fire. Lower chance = more flickery fire.
// Default 120, suggested range 50-200.
#define SPARKING 200

//Lost LED Show
void flash()
{
fill_solid(leds, NUM_LEDS, CRGB::Red);
FastLED.show();
delay(200);
fill_solid(leds, NUM_LEDS, CRGB::Black);
FastLED.show();
delay(40);
}

//Won LED Show

void Fire2012()
{

static byte heat[NUM_LEDS];// Array of temperature readings at each simulation cell

// Step 1. Cool down every cell a little
for( int i = 0; i < NUM_LEDS; i++) {
heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
}

// Step 2.  Heat from each cell drifts 'up' and diffuses a little
for( int k= NUM_LEDS - 1; k >= 2; k--) {
  heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
}

// Step 3.  Randomly ignite new 'sparks' of heat near the bottom
if( random8() < SPARKING ) {
  int y = random8(7);
  heat[y] = qadd8( heat[y], random8(160,255) );
}

// Step 4.  Map from heat cells to LED colors
for( int j = 0; j < NUM_LEDS; j++) {
  CRGB color = HeatColor( heat[j]);
  int pixelnumber;
  if( gReverseDirection ) {
    pixelnumber = (NUM_LEDS-1) - j;
  } else {
    pixelnumber = j;
  }
  leds[pixelnumber] = color;
    FastLED.show(); // display this frame

}

}

Please post code to http://gist.github.com and share the link. Then it will always display properly on all devices and line numbers can be referenced for discussion.

@marmil I have been working on this all day. I was determined to better understand the code. I finally figured out some of the simple, but vital lines after reading and referencing more carefully.
For example: The number 2 in this section
for (int i = 0; i < 2; i++)
{
Fire2012();
}

is the variable for how many times it will repeat after the call, as well as a several other bits and pieces. Anyway, I got it working the way I envisioned and the rest of this particular game is coming together. I have about 17 others I have brainstormed and flow charted that I will be piecing together one by one. At least that’s the plan.

Thank you for your help. I have never posted code on github or did anything like that before. I read the instructions a couple time and I’m not sure I understand all the terminology. I will probably hold off for a bit and post when I am further along. Also, I am trying to develop a product and am a little reluctant to share at the moment. Reaching out to the fastLED community was something I initially wasn’t going to do, but I did, and I appreciate you helping me over this hurdle. Thank you

Great to hear you got it working @Louis_Celenza
Looking forward to seeing more of what you come up with.