Lang nichts mehr gehört.
Aber ich hab es hin bekommen um die setConfig mit RC zu ändern über ein Zweite Kanal.
Hier die codes
#if defined (INPUT_TERMINAL)
#include <SerialCommand.h>
SerialCommand sCmd;
void setupInputTerminal(){
Serial.begin(115200);
initSerialCommands();
SERIAL_PRINTLN("*** SETUP COMPLETE ***");
}
void loopInputTerminal(){
sCmd.readSerial();
}
void initSerialCommands(){
sCmd.addCommand("setR", serialSetR);
sCmd.addCommand("setG", serialSetG);
sCmd.addCommand("setB", serialSetB);
sCmd.addCommand("setColor", serialSetColor);
sCmd.addCommand("getColor", serialGetColor);
sCmd.addCommand("printColor", printCurrentColor);
sCmd.addCommand("setConfig", serialSetConfig);
sCmd.addCommand("saveColors", serialSaveColors);
sCmd.addCommand("saveLeds", serialSaveLeds);
sCmd.addCommand("clearEeprom", clearEeprom);
sCmd.addCommand("setArm", serialSetArm);
sCmd.addCommand("setLed", serialSetLed);
sCmd.addCommand("m+", serialNextMode);
sCmd.addCommand("m-", serialPreviousMode);
sCmd.addCommand("d", serialSetDelay);
sCmd.addCommand("s+", serialNextConfig); //Dies ist neu
sCmd.addCommand("s-", serialPreviousConfig); //Dies ist neu
}
int readIntArg(){
char *arg;
arg = sCmd.next();
if (arg != NULL) return atoi(arg);
return -1;
}
void printCurrentColor(){
SERIAL_PRINT("current RGB color = (");
SERIAL_PRINT(currentRGB.r);
SERIAL_PRINT(", ");
SERIAL_PRINT(currentRGB.g);
SERIAL_PRINT(", ");
SERIAL_PRINT(currentRGB.b);
SERIAL_PRINTLN(")");
}
void serialSetR(){
int newColor = readIntArg();
if (newColor>=0 && newColor<256){
currentRGB.r = newColor;
printCurrentColor();
}
}
void serialSetG(){
int newColor = readIntArg();
if (newColor>=0 && newColor<256){
currentRGB.g = newColor;
printCurrentColor();
}
}
void serialSetB(){
int newColor = readIntArg();
if (newColor>=0 && newColor<256){
currentRGB.b = newColor;
printCurrentColor();
}
}
void serialSetColor(){
int idx = readIntArg()%MAX_EEPROM_COLORS;
if (idx>=0 && idx<MAX_EEPROM_COLORS){
SERIAL_PRINT("Set color ");
SERIAL_PRINT(idx);
SERIAL_PRINTLN(" to current color.");
storedColorsRGB[idx] = currentRGB;
currentColorIdx = idx;
}
}
void serialSetConfig(){
config = readIntArg()%MAX_LED_CONFIGS;
SERIAL_PRINT("new config = ");
SERIAL_PRINTLN(config);
}
void serialGetColor(){
int idx = readIntArg()%MAX_EEPROM_COLORS;
currentRGB = storedColorsRGB[idx];
currentColorIdx = idx;
printCurrentColor();
}
void serialSaveColors(){
writeColors();
SERIAL_PRINTLN("Colors saved to EEPROM.");
}
void serialSaveLeds(){
writeLeds();
SERIAL_PRINTLN("Led colors saved to EEPROM.");
}
void serialSetArm(){
int arm = readIntArg() % NUM_ARMS;
if (arm>=0 && arm<NUM_ARMS){
setArmColor(currentColorIdx, arm, config);
SERIAL_PRINT("Updated arm ");
SERIAL_PRINTLN(arm);
}
}
void serialSetLed(){
int led = readIntArg() % NUM_LEDS;
if (led>=0 && led<NUM_LEDS){
setLedColor(currentColorIdx, led, config);
}
}
void printNewMode(){
SERIAL_PRINT("new mode = ");
SERIAL_PRINTLN(mode);
}
void serialNextMode(){
mode = (mode+1) % NUM_MODES;
printNewMode();
}
void serialPreviousMode(){
mode = (mode+(NUM_MODES-1)) % NUM_MODES;
printNewMode();
}
void printNewConfig(){ //Dies ist neu
SERIAL_PRINT("new config = "); //Dies ist neu
SERIAL_PRINTLN(config); //Dies ist neu
}
void serialNextConfig(){ //Dies ist neu
config = (config+1) % NUM_CONFIGS; //Dies ist neu
printNewConfig(); //Dies ist neu
}
void serialPreviousConfig(){ //Dies ist neu
config = (config+(NUM_CONFIGS-1)) % NUM_CONFIGS; //Dies ist neu
printNewConfig(); //Dies ist neu
}
void serialSetDelay(){
int newDelay = readIntArg();
if (newDelay>0 && newDelay<10000){
DELAY = newDelay;
SERIAL_PRINT("new delay = ");
SERIAL_PRINTLN(DELAY);
}
}
void serialReversed(){
reverse = !reverse;
SERIAL_PRINTLN("reversed");
}
#endif
----------------------------------------------------------------------------------------------------------------------------
#if defined (INPUT_RC)
void setupInputRC(){
pinMode(RC_PIN_1, INPUT);
pinMode(RC_PIN_2, INPUT); //Dies ist neu
}
void loopInputRC(){
int rc1 = pulseIn(RC_PIN_1, HIGH, 25000);
int rc2 = pulseIn(RC_PIN_2, HIGH, 25000); //Dies ist neu
boolean lostConnection = rc1<650;
if (rc1<1000) rc1 = 1000;
else if (rc1>2000) rc1 = 2000;
if (lostConnection) mode = MODE_RC_NO_CONNECTION;
else if (rc1<1350) mode = MODE_RC_LOW;
else if (rc1>1700) mode = MODE_RC_HIGH;
else mode = MODE_RC_MID;
if (rc2<1000) rc2 = 1000; //Dies ist neu
else if (rc2>2000) rc2 = 2000; //Dies ist neu
if (lostConnection) config = CONFIG_RC_NO_CONNECTION; //Dies ist neu
else if (rc2<1350) config = CONFIG_RC_LOW; //Dies ist neu
else if (rc2>1700) config = CONFIG_RC_HIGH; //Dies ist neu
else config = CONFIG_RC_MID; //Dies ist neu
}
#endif
-----------------------------------------------------------------------------------------------------------------------------
// select (uncomment) one of the following input modes
//#define INPUT_TERMINAL // use serial terminal to control lightning mode and configure led colors
#define INPUT_RC // use rc inputs to control lightning mode
#define NUM_ARMS 4 // number of arms on the multicopter
#define LEDS_PER_ARM 15// leds per arm
#define LED_PIN 9 // led pin => data of led strip
// input mode depending configs
#if defined (INPUT_TERMINAL)
#define NUM_MODES 4
#define NUM_CONFIGS 4 //Dies ist neu
#elif defined (INPUT_RC)
#define RC_PIN_1 6 // PIN for RC input channel 1
#define RC_PIN_2 10 // PIN for RC input channel 1 //Dies ist neu
#define MODE_RC_LOW MODE_0
#define MODE_RC_MID MODE_1
#define MODE_RC_HIGH MODE_2
#define MODE_RC_NO_CONNECTION MODE_3
#define CONFIG_RC_LOW CONFIG_0 //Dies ist neu
#define CONFIG_RC_MID CONFIG_1 //Dies ist neu
#define CONFIG_RC_HIGH CONFIG_2 //Dies ist neu
#define CONFIG_RC_NO_CONNECTION CONFIG_3 //Dies ist neu
#define REQUEST_DELAY 250 // request delay, smaller delay = faster update of MultiWii values = more cpu power
#endif
/////////////////////////////////////////////////////////////////////////////////
// !!! Do not modify anything below this line, except you know what you do !!! //
/////////////////////////////////////////////////////////////////////////////////
#define MODE_0 0
#define MODE_1 1
#define MODE_2 2
#define MODE_3 3
#define CONFIG_0 0 //Dies ist neu
#define CONFIG_1 1 //Dies ist neu
#define CONFIG_2 2 //Dies ist neu
#define CONFIG_3 3 //Dies ist neu
#define NUM_LEDS (NUM_ARMS * LEDS_PER_ARM) // calculate total number of leds
#if defined (INPUT_TERMINAL)
#define SERIAL_PRINT(x) Serial.print(x)
#define SERIAL_PRINTLN(x) Serial.println(x)
#else
#define SERIAL_PRINT(x)
#define SERIAL_PRINTLN(x)
#endif
MFG. Arnoud