Hi, you wrote me this script. Can I use a 3 position switch on my Futaba transmitter?…
- User
Hi, you wrote me this script. Can I use a 3 position switch on my Futaba transmitter? #include <FastLED.h>
#define LED_PIN 6 #define COLOR_ORDER GRB #define CHIPSET WS2811 #define NUM_LEDS 30
#define BRIGHTNESS 100 #define FRAMES_PER_SECOND 60
#define RC_INPUT_PIN 2
bool gReverseDirection = false;
int currentPalette = 0; int mode = 0;
CRGB leds[NUM_LEDS];
CRGBPalette16 gPal;
void setup() { delay(3000); // sanity delay FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); FastLED.setBrightness(BRIGHTNESS);
pinMode(RC_INPUT_PIN, INPUT); // Configure RC input pin attachInterrupt(digitalPinToInterrupt(RC_INPUT_PIN), onRCInputChange, CHANGE); // Register interrupt for RC input changes
// Palette setup gPal = CRGBPalette16(CRGB::Red, CRGB::Red, CRGB::Yellow, CRGB::White); }
void loop() { // No need to check button state anymore
// Update palette based on mode switch (mode) { case 0: gPal = CRGBPalette16(CRGB::Red, CRGB::Red, CRGB::Yellow, CRGB::White); break; case 1: gPal = CRGBPalette16(CRGB::Aqua, CRGB::Blue, CRGB::Aqua, CRGB::White); break; case 2: gPal = CRGBPalette16(CRGB::Green, CRGB::Green, CRGB::Yellow); break; }
Fire2012WithPalette(); // run simulation frame, using palette colors
FastLED.show(); // display this frame FastLED.delay(500 / FRAMES_PER_SECOND); }
#define COOLING 55 #define SPARKING 120
//********************************************************************************************// // PLAY WITH FALLING, COOLING AND SPARKLING
void Fire2012WithPalette() { // Array of temperature readings at each simulation cell static uint8_t heat[NUM_LEDS];
// 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++) { // Scale the heat value from 0-255 down to 0-240 // for best results with color palettes. uint8_t colorindex = scale8( heat[j], 240); // Corrected line CRGB color = ColorFromPalette( gPal, colorindex); int pixelnumber; if( gReverseDirection ) { pixelnumber = (NUM_LEDS-1) - j; } else { pixelnumber = j; } leds[pixelnumber] = color; } // Your fire animation code here }
void onRCInputChange() { // Read the RC input to determine the mode mode = digitalRead(RC_INPUT_PIN); }
- Assistant
Yes, you can use a 3-position switch on your Futaba transmitter. In the provided script, the switch is connected to pin 2 (RC_INPUT_PIN) of the Arduino. The script registers an interrupt for changes on this pin using the
attachInterruptfunction. When the switch position changes, theonRCInputChangefunction is called, which reads the state of the switch usingdigitalReadand updates themodevariable accordingly.To use a 3-position switch, you will need to modify the
onRCInputChangefunction to map the switch position to different modes. For example:void onRCInputChange() { // Read the RC input to determine the mode int switchPosition = digitalRead(RC_INPUT_PIN); if (switchPosition == LOW) { mode = 0; // Position 1 on the switch } else if (switchPosition == HIGH) { mode = 2; // Position 3 on the switch } else { mode = 1; // Position 2 on the switch } }In this example, LOW represents the first position, HIGH represents the third position, and any other value represents the second position. You can adjust these values to match your specific switch configuration.
Remember to connect the switch to the appropriate pin on your Arduino and update the value in the script accordingly.
- User
Can you please insert this in the script en give me the complete script
- Assistant