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>
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:
cpp
User
Can you please modify the script and give me the complete version
Assistant
Certainly! Here is the modified script with the complete version:
cpp
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 the analogRead() 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:
cpp
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:
cpp
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:
cpp
#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);
}
In this modified code, you would need to replace CHANNEL_PIN with the correct pin number that is connected to the receiver. Additionally, make sure to connect the receiver's output to the Arduino board's input pin.
This modified code reads the receiver channel value and maps it to the currentMode variable, allowing you to change the color mode by adjusting the transmitter's control. A deadband is also included to avoid mode changes when the receiver value is within a certain range.
#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);
}
In this complete version, I have included the necessary pin definitions and added the receiver input pin mode to INPUT. You should replace CHANNEL_PIN with the correct pin number that is connected to the 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);
}
In this updated code, I have replaced the usage of pulseIn() with analogRead() to read the receiver channel value. Make sure to replace CHANNEL_PIN with the correct pin number that is connected to the receiver's PWM output. This should allow you to control the color modes using the Futaba T14SG transmitter.
#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);
}
In this updated code, the analogRead() value from the receiver is mapped from the range 900-2000 to the range 0-COLOR_MODES-1. Ensure that you replace CHANNEL_PIN with the correct pin number connected to the receiver's PWM output. This modified code should work correctly, considering the pulse width range of 900-2000ms for the receiver channel values.
#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);
}
In this updated code, I have used a digital input pin (SWITCH_PIN) to read the state of the switch on your Futaba transmitter. Make sure to replace SWITCH_PIN with the correct pin number that is connected to the switch. The switch state is checked in each iteration of the loop() function, and when the switch transitions from high to low, the currentMode is incremented, allowing you to switch between color modes.
I hope this helps, and I apologize for any confusion caused.