Rainbow Fade To Red

Nihayet yapabildim gibi:

İkinci bir POT ekledim ve bunları Smoothing de gösterildiği gibi güzenledim:

https://www.arduino.cc/en/Tutorial/Smoothing

 

//TGAN SIFIRLAMA DUGMESI
#DEFINE USE_GET_MILLISECOND_TIMER 1
//TGAN SIFIRLAMA DUGMESI

#INCLUDE "FASTLED.H"

// PALETTEBEAT
// SHOWS HOW TO PULSE BACK AND FORTH BETWEEN TWO COLOR PALETTES
// AT A GIVEN NUMBER OF BEATS PER MINUTE.
//
// THE TWO COLOR PALETTES IN THE PULSE CYCLE EACH CAN
// ALSO INDEPENDENTLY MORPH AND SHIFT -- ALTHOUGH CHOOSING
// NEW TARGET PALETTES IS NOT SHOWN HERE.
//
// MARK KRIEGSMAN, AUGUST 2015

#IF FASTLED_VERSION < 3001000
#ERROR "REQUIRES FASTLED 3.1 OR LATER; CHECK GITHUB FOR LATEST CODE."
#ENDIF

#DEFINE DATA_PIN 2
//#DEFINE CLK_PIN 4
#DEFINE LED_TYPE WS2812B
#DEFINE COLOR_ORDER GRB
#DEFINE NUM_LEDS 300
#DEFINE BRIGHTNESS 255

CRGB LEDS[NUM_LEDS];

// TGAN_POTENTIOMETER_1
CONST INT NUMREADINGS1 = 10;
INT READINGS1[NUMREADINGS1]; // THE READINGS FROM THE ANALOG INPUT
INT INDEX1 = 0; // THE INDEX OF THE CURRENT READING
INT TOTAL1 = 0; // THE RUNNING TOTAL
INT AVERAGE1 = 0; // THE AVERAGE

INT POTPIN = A0;
INT POTVALUE = 0;
INT POTMAPPEDOUTPUTVALUE = 30;
// TGAN_POTENTIOMETER_1

// TGAN_POTENTIOMETER_2
CONST INT NUMREADINGS2 = 10;
INT READINGS2[NUMREADINGS2]; // THE READINGS FROM THE ANALOG INPUT
INT INDEX2 = 0; // THE INDEX OF THE CURRENT READING
INT TOTAL2 = 0; // THE RUNNING TOTAL
INT AVERAGE2 = 0; // THE AVERAGE

INT POT2PIN = A7;
INT POT2VALUE = 0;
INT POT2MAPPEDOUTPUTVALUE = 0;
// TGAN_POTENTIOMETER_2/
//TGAN SIFIRLAMA DUGMESI
CONST INT BUTTONPIN = 50;
INT BUTTONSTATE = 0;
//TGAN SIFIRLAMA DUGMESI
//TGAN SIFIRLAMA DUGMESI
UINT32_T RESETTIME;
//TGAN SIFIRLAMA DUGMESI

VOID SETUP() { // SETUPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
PINMODE(BUTTONPIN, INPUT);
//TGAN SIFIRLAMA DUGMESI
DELAY(3000); // 3 SECOND DELAY FOR RECOVERY
SERIAL.BEGIN(57600); // INITIALIZE SERIAL PORT FOR DEBUGGING.

// TGAN_POTENTIOMETER_1
FOR (INT THISREADING1 = 0; THISREADING1 < NUMREADINGS1; THISREADING1++)
READINGS1[THISREADING1] = 0;
// TGAN_POTENTIOMETER_1
// TGAN_POTENTIOMETER_2
FOR (INT THISREADING2 = 0; THISREADING2 < NUMREADINGS2; THISREADING2++)
READINGS2[THISREADING2] = 0;
// TGAN_POTENTIOMETER_2
FASTLED.ADDLEDS<LED_TYPE, DATA_PIN, COLOR_ORDER>(LEDS, NUM_LEDS)
.SETCORRECTION(TYPICALLEDSTRIP)
.SETDITHER(BRIGHTNESS < 255);

FASTLED.SETBRIGHTNESS(BRIGHTNESS);
} // SETUPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
//TGAN_SIFIRLAMA_DUGMESI
UINT32_T GET_MILLISECOND_TIMER()
{
RETURN MILLIS() - RESETTIME ;
}
//TGAN_SIFIRLAMA_DUGMESI/

VOID LOOP() // LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOP
{
//TGAN_SIFIRLAMA_DUGMESI
BUTTONSTATE = DIGITALREAD(BUTTONPIN);
IF (BUTTONSTATE == HIGH) {
RESETTIME = MILLIS() ;
} ;
//TGAN_SIFIRLAMA_DUGMESI/

PERIODICALLYCHOOSENEWCOLORPALETTES(); // CURRENTLY DOES NOTHING
MIXBEATPALETTE(); // MIX UP THE NEW 'BEAT PALETTE' TO DRAW WITH
DRAWONEFRAMEUSINGBEATPALETTE(); // DRAW A SIMPLE ANIMATION USING THE 'BEAT PALETTE'

FASTLED.SHOW();
FASTLED.DELAY(30);

// TGAN_POTENTIOMETER_1
TOTAL1 = TOTAL1 - READINGS1[INDEX1];
READINGS1[INDEX1] = ANALOGREAD(POTPIN);
TOTAL1 = TOTAL1 + READINGS1[INDEX1];
INDEX1 = INDEX1 + 1;
IF (INDEX1 >= NUMREADINGS1)
INDEX1 = 0;
AVERAGE1 = TOTAL1 / NUMREADINGS1;
POTVALUE = ANALOGREAD(POTPIN);
POTMAPPEDOUTPUTVALUE = MAP(AVERAGE1, 0, 1023, 40, 145);
// TGAN_POTENTIOMETER_1

// TGAN_POTENTIOMETER_2
TOTAL2 = TOTAL2 - READINGS2[INDEX2];
READINGS2[INDEX2] = ANALOGREAD(POT2PIN);
TOTAL2 = TOTAL2 + READINGS2[INDEX2];
INDEX2 = INDEX2 + 1;
IF (INDEX2 >= NUMREADINGS2)
INDEX2 = 0;
AVERAGE2 = TOTAL2 / NUMREADINGS2;

POT2VALUE = ANALOGREAD(POT2PIN);
POT2MAPPEDOUTPUTVALUE = MAP(AVERAGE2, 0, 1023, 0, 256);
// TGAN_POTENTIOMETER_2/

SERIAL.PRINT("POTMAPPEDOUTPUTVALUE: PALETTEBEATSPERMINUTE:"); //
SERIAL.PRINTLN(POTMAPPEDOUTPUTVALUE);
SERIAL.PRINT("POT2MAPPEDOUTPUTVALUE: INCINDEX: "); // INCINDEX , POT2MAPPEDOUTPUTVALUE, MIXER = SIN8( BEAT);
SERIAL.PRINTLN(POT2MAPPEDOUTPUTVALUE);

} // LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOP

CRGBPALETTE16 GCURRENTPALETTEA( CRGB::GREEN);
CRGBPALETTE16 GCURRENTPALETTEB( CRGB::GREEN);

CRGBPALETTE16 GTARGETPALETTEA( RAINBOWCOLORS_P);
CRGBPALETTE16 GTARGETPALETTEB( CRGB::RED );

CRGBPALETTE16 GBEATPALETTE;

// HERE'S WHERE THE MAGIC HAPPENS. SINCE INTERNALLY PALETTES ARE
// NOTHING MORE THAN AN ARRAY OF CRGB, WE CAN USE THE FASTLED "BLEND"
// FUNCTION TO MIX UP A NEW PALETTE, WHICH IS A BLEND OF OUR TWO CURRENT
// PALETTES, WITH THE AMOUNT OF BLENDING CONTROLLED BY A 'MIXER' THAT
// PULSES BACK AND FORTH SMOOTHLY BETWEEN THE TWO, AT A GIVEN BPM.
//
VOID MIXBEATPALETTE()
{
UINT8_T PALETTEBEATSPERMINUTE = POTMAPPEDOUTPUTVALUE;

UINT8_T BEAT = BEAT8( PALETTEBEATSPERMINUTE); // REPEATS FROM 0..255

// 'CUBICWAVE8' SPENDS MORE TIME AT EACH END THAN SIN8, AND LESS TIME
// IN THE MIDDLE. TRY OTHERS: TRIWAVE8, QUADWAVE8, SIN8, CUBICWAVE8
UINT8_T MIXER = SIN8( BEAT);

// MIX A NEW PALETTE, GBEATPALETTE, WITH A VARYING AMOUNT OF CONTRIBUTION
// FROM GCURRENTPALETTEA AND GCURRENTPALETTEB, DEPENDING ON 'MIXER'.
// THE 'BEAT PALETTE' IS THEN USED TO DRAW ONTO THE LEDS.

UINT8_T PALETTESIZE = SIZEOF( GBEATPALETTE) / SIZEOF(GBEATPALETTE[0]); // = 16
BLEND( GCURRENTPALETTEA, GCURRENTPALETTEB, GBEATPALETTE, PALETTESIZE, MIXER );

}
// SAMPLE DRAW FUNCTION TO DRAW SOME PIXELS USING THE COLORS IN GBEATPALETTE
VOID DRAWONEFRAMEUSINGBEATPALETTE()
{
UINT8_T STARTINDEX = MILLIS() / 2;
UINT8_T INCINDEX = 12 ;
// FILL_PALETTE(LEDS, NUM_LEDS, STARTINDEX, INCINDEX, GBEATPALETTE, 255, LINEARBLEND);
// FILL_PALETTE(LEDS, NUM_LEDS, POT2MAPPEDOUTPUTVALUE, INCINDEX, GBEATPALETTE, 255, LINEARBLEND);
FILL_PALETTE(LEDS, NUM_LEDS, 0, POT2MAPPEDOUTPUTVALUE, GBEATPALETTE, 255, LINEARBLEND);

}
// IF YOU WANTED TO CHANGE THE TWO PALETTES FROM 'RAINBOW' AND 'RED'
// TO SOMETHING ELSE, HERE'S WHERE YOU'D DO IT.
VOID PERIODICALLYCHOOSENEWCOLORPALETTES()
{
EVERY_N_MILLISECONDS(20) {
NBLENDPALETTETOWARDPALETTE( GCURRENTPALETTEA, GTARGETPALETTEA);
NBLENDPALETTETOWARDPALETTE( GCURRENTPALETTEB, GTARGETPALETTEB);
}
}

 

Smoothing Kodu

 

// TGAN_POTENTIOMETER_1

CONST INT NUMREADINGS1 = 10;
INT READINGS1[NUMREADINGS1]; // THE READINGS FROM THE ANALOG INPUT
INT INDEX1 = 0; // THE INDEX OF THE CURRENT READING
INT TOTAL1 = 0; // THE RUNNING TOTAL
INT AVERAGE1 = 0; // THE AVERAGE

INT POTPIN = A0;
INT POTVALUE = 0;
INT POTMAPPEDOUTPUTVALUE = 30;

// TGAN_POTENTIOMETER_1

VOID SETUP() { // SETUPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP

// TGAN_POTENTIOMETER_1
FOR (INT THISREADING1 = 0; THISREADING1 < NUMREADINGS1; THISREADING1++)
READINGS1[THISREADING1] = 0;
// TGAN_POTENTIOMETER_1

} // SETUPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP

VOID LOOP() // LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOP

// TGAN_POTENTIOMETER_1
TOTAL1 = TOTAL1 - READINGS1[INDEX1];
READINGS1[INDEX1] = ANALOGREAD(POTPIN);
TOTAL1 = TOTAL1 + READINGS1[INDEX1];
INDEX1 = INDEX1 + 1;
IF (INDEX1 >= NUMREADINGS1)
INDEX1 = 0;
AVERAGE1 = TOTAL1 / NUMREADINGS1;

POTVALUE = ANALOGREAD(POTPIN);
POTMAPPEDOUTPUTVALUE = MAP(AVERAGE1, 0, 1023, 40, 145);
// TGAN_POTENTIOMETER_1

} // LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOP

 

Leave a Reply