Can you adapt following sc ript to change color raiocontrolle with my futaba T14SG an a…
- User
Can you adapt following sc ript to change color raiocontrolle with my futaba T14SG an a futaba receiver. Please keep the color script, this is exactly what I need. #include <FastLED.h>
#define LED_PIN 6 #define LED_COUNT 22 #define BUTTON_PIN 2 #define COLOR_MODES 3
CRGB leds[LED_COUNT];
const byte flickerDelay = 20;
int currentMode = 0;
void setup() { FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, LED_COUNT); FastLED.setBrightness(100); pinMode(BUTTON_PIN, INPUT_PULLUP); }
void loop() { if (digitalRead(BUTTON_PIN) == LOW) { currentMode = (currentMode + 1) % COLOR_MODES; delay(200); }
switch (currentMode) { case 0: flameEffect(CRGB::OrangeRed); break; case 1: flameEffect(CRGB::GreenYellow); break; case 2: flameEffect(CRGB::Blue); break; } }
void flameEffect(const CRGB& color) { for (int i = 0; i < LED_COUNT; i++) { int flicker = random(192, 255); leds[i] = color; leds[i].fadeToBlackBy(flicker); } FastLED.show(); delay(flickerDelay); }
- Assistant
To adapt the code to use a Futaba T14SG transmitter and a Futaba receiver, you will need to use the receiver's output to control the color modes.
Here is an example of how you can modify the code:
#include <FastLED.h> #define LED_PIN 6 #define LED_COUNT 22 #define COLOR_MODES 3 CRGB leds[LED_COUNT]; const byte flickerDelay = 20; int currentMode = 0; void setup() { FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, LED_COUNT); FastLED.setBrightness(100); } void loop() { // Read the receiver channel value to determine the color mode int receiverValue = pulseIn(CHANNEL_PIN, HIGH, 25000); // Replace CHANNEL_PIN with the correct pin connected to the receiver // Map the receiver value to the currentMode range currentMode = map(receiverValue, 1000, 2000, 0, COLOR_MODES); // Apply a deadband to avoid mode changes when the receiver value is within a certain range if (receiverValue > 1400 && receiverValue < 1600) { currentMode = 0; } // Switch between color modes switch (currentMode) { case 0: flameEffect(CRGB::OrangeRed); break; case 1: flameEffect(CRGB::GreenYellow); break; case 2: flameEffect(CRGB::Blue); break; } } void flameEffect(const CRGB& color) { for (int i = 0; i < LED_COUNT; i++) { int flicker = random(192, 255); leds[i] = color; leds[i].fadeToBlackBy(flicker); } FastLED.show(); delay(flickerDelay); } - User
Can you please modify the script and give me the complete version
- Assistant
Certainly! Here is the modified script with the complete version:
#include <FastLED.h> #define LED_PIN 6 #define LED_COUNT 22 #define CHANNEL_PIN 2 // Replace with the correct pin connected to the receiver #define COLOR_MODES 3 CRGB leds[LED_COUNT]; const byte flickerDelay = 20; int currentMode = 0; void setup() { FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, LED_COUNT); FastLED.setBrightness(100); pinMode(CHANNEL_PIN, INPUT); } void loop() { // Read the receiver channel value to determine the color mode int receiverValue = pulseIn(CHANNEL_PIN, HIGH, 25000); // Replace CHANNEL_PIN with the correct pin connected to the receiver // Map the receiver value to the currentMode range currentMode = map(receiverValue, 1000, 2000, 0, COLOR_MODES); // Apply a deadband to avoid mode changes when the receiver value is within a certain range if (receiverValue > 1400 && receiverValue < 1600) { currentMode = 0; } // Switch between color modes switch (currentMode) { case 0: flameEffect(CRGB::OrangeRed); break; case 1: flameEffect(CRGB::GreenYellow); break; case 2: flameEffect(CRGB::Blue); break; } } void flameEffect(const CRGB& color) { for (int i = 0; i < LED_COUNT; i++) { int flicker = random(192, 255); leds[i] = color; leds[i].fadeToBlackBy(flicker); } FastLED.show(); delay(flickerDelay); } - User
Sorry, it does not work. Is there
- Assistant
Apologies for the inconvenience. I realize there was a mistake in the code provided. The
pulseIn()function should not be used to read the receiver channel value since it blocks the execution of code for the specified timeout. Instead, we can use theanalogRead()function to read the receiver channel value using a PWM input pin.Here is the updated code that should work with a Futaba T14SG transmitter and a Futaba receiver:
#include <FastLED.h> #define LED_PIN 6 #define LED_COUNT 22 #define CHANNEL_PIN A0 // Replace with the correct pin connected to the receiver #define COLOR_MODES 3 CRGB leds[LED_COUNT]; const byte flickerDelay = 20; int currentMode = 0; void setup() { FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, LED_COUNT); FastLED.setBrightness(100); } void loop() { // Read the receiver channel value to determine the color mode int receiverValue = analogRead(CHANNEL_PIN); // Replace CHANNEL_PIN with the correct pin connected to the receiver // Map the receiver value to the currentMode range currentMode = map(receiverValue, 0, 1023, 0, COLOR_MODES); // Switch between color modes switch (currentMode) { case 0: flameEffect(CRGB::OrangeRed); break; case 1: flameEffect(CRGB::GreenYellow); break; case 2: flameEffect(CRGB::Blue); break; } } void flameEffect(const CRGB& color) { for (int i = 0; i < LED_COUNT; i++) { int flicker = random(192, 255); leds[i] = color; leds[i].fadeToBlackBy(flicker); } FastLED.show(); delay(flickerDelay); } - User
Sorry it does not work. Do we have to account pulswith (900 - 2000ms)?
- Assistant
Apologies for the confusion. If you want to account for the pulse width range of 900-2000ms for the receiver channel values, you can modify the mapping in the code. Instead of mapping the analogRead() value directly to the currentMode, you can map it to the range 900-2000 and then map that range to the desired number of color modes.
Here's an updated version of the code that accounts for the pulse width range:
#include <FastLED.h> #define LED_PIN 6 #define LED_COUNT 22 #define CHANNEL_PIN A0 // Replace with the correct pin connected to the receiver #define COLOR_MODES 3 CRGB leds[LED_COUNT]; const byte flickerDelay = 20; int currentMode = 0; void setup() { FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, LED_COUNT); FastLED.setBrightness(100); } void loop() { // Read the receiver channel value to determine the color mode int receiverValue = analogRead(CHANNEL_PIN); // Replace CHANNEL_PIN with the correct pin connected to the receiver // Map the receiver value (900-2000) to the currentMode range (0-COLOR_MODES-1) currentMode = map(receiverValue, 900, 2000, 0, COLOR_MODES); // Switch between color modes switch (currentMode) { case 0: flameEffect(CRGB::OrangeRed); break; case 1: flameEffect(CRGB::GreenYellow); break; case 2: flameEffect(CRGB::Blue); break; } } void flameEffect(const CRGB& color) { for (int i = 0; i < LED_COUNT; i++) { int flicker = random(192, 255); leds[i] = color; leds[i].fadeToBlackBy(flicker); } FastLED.show(); delay(flickerDelay); } - User
It does not work, how does the arduino knows the position of my switch on my ffutaba transmitter?
- Assistant
Apologies for the confusion. If you want to control the color modes using a switch on your Futaba transmitter, you will need to use a digital input pin on the Arduino to detect the switch position.
Here's an updated version of the code that uses a digital input pin to read the switch position:
#include <FastLED.h> #define LED_PIN 6 #define LED_COUNT 22 #define SWITCH_PIN 2 // Replace with the correct pin connected to the switch #define COLOR_MODES 3 CRGB leds[LED_COUNT]; const byte flickerDelay = 20; int currentMode = 0; bool switchState = false; bool prevSwitchState = false; void setup() { FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, LED_COUNT); FastLED.setBrightness(100); pinMode(SWITCH_PIN, INPUT_PULLUP); } void loop() { // Read the switch state switchState = digitalRead(SWITCH_PIN); // Detect switch press if (switchState == LOW && prevSwitchState == HIGH) { currentMode = (currentMode + 1) % COLOR_MODES; delay(200); } prevSwitchState = switchState; // Switch between color modes switch (currentMode) { case 0: flameEffect(CRGB::OrangeRed); break; case 1: flameEffect(CRGB::GreenYellow); break; case 2: flameEffect(CRGB::Blue); break; } } void flameEffect(const CRGB& color) { for (int i = 0; i < LED_COUNT; i++) { int flicker = random(192, 255); leds[i] = color; leds[i].fadeToBlackBy(flicker); } FastLED.show(); delay(flickerDelay); }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.