@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.
- 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
}
}