sowbug / G35Arduino

An Arduino library for GE Color Effects G-35 holiday lights.
Other
64 stars 24 forks source link

Help with Mod #12

Closed MrCarlos closed 12 years ago

MrCarlos commented 12 years ago

Hi,

I'm new to all this so if I posting this in the wrong section I apologize. I have been working on adding xbee communication to allow remote program changing. I have it working pretty much as a hack as I'm not a a programmer. I'm sort of at the end of my knowledge base and I just don't know what to do next to get it to work exactly how I want it.

My main problem is I had to use some delays to read the serial input from the Xbee. Those delays slowed the light programs down too much. I reduced the two delays to 5ms, the light programs are slightly slower than the stock code but they still look good, but now I have to push the key many times before the program picks up my key input. Not ideal. Maybe someone can help me learn the right way execute this idea?

Long term I want to also add a menu to select any program and jump right into it and add the ability to increase or decrease the program run times via xbee connection.

I modified the ProgramRunner.h

/* G35: An Arduino library for GE Color Effects G-35 holiday lights. Copyright © 2011 The G35 Authors. Use, modification, and distribution are subject to the BSD license as described in the accompanying LICENSE file.

By Mike Tsao <github.com/sowbug>.

See README for complete attributions. */

ifndef INCLUDE_G35_PROGRAM_RUNNER_H

define INCLUDE_G35_PROGRAM_RUNNER_H

include

//setup for xbee communication

include

SoftwareSerial mySerial = SoftwareSerial(2, 3); int incomingByte; char chrValue;

// ProgramRunner manages a collection of LightPrograms. // // It gives the current program a slice of time to run, decides when it's // time to switch to the next program, and asks the program_creator callback // to give it the next program when it's time. In Arduino terms, it's what // you want to call in your loop() method. // // switch_program() is public because the application might sometimes want // to change programs more frequently, for example if you've implemented // a remote control receiver. class ProgramRunner { public: ProgramRunner(LightProgram* (*program_creator)(uint8_t program_index), uint8_t program_count, uint16_t program_duration_seconds) : programcount(program_count), program_durationseconds(program_duration_seconds), programindex(programcount - 1), next_switchmillis(0), programcreator(programcreator), program(NULL) {}

void loop() {

//get data from incoming xbee communcation incomingByte = (mySerial.read()); chrValue = incomingByte;

// check xbee for in coming character
delay(5); if (incomingByte >= 0 && incomingByte <= 254) { Serial.print(chrValue); mySerial.println(chrValue); Serial.println(" was received "); }

// if it's an H (ASCII 72) turn ON the LED and goto switch program:
if (incomingByte == 'H') { digitalWrite(8, HIGH); //for debugging mySerial.print("Switching to "); delay(5); switch_program(); }

uint32_t now = millis();
if (now >= next_switch_millis_) {
  switch_program();
}
if (now >= next_do_millis_) {
  next_do_millis_ = now + program_->Do();
}

}

void switch_program() {

//setup counter to display program name
unsigned int count; 

uint32_t now = millis();
next_switch_millis_ = now + program_duration_seconds_ * 1000;
next_do_millis_ = now;
if (++program_index_ == program_count_) {
  program_index_ = 0;

}
if (program_ != NULL) {
  delete program_;
}

//setup counter for program switching
count = program_index_;

//print to xbee count number for debugging
mySerial.print ("Count = ");
mySerial.println (count, DEC);

//print running program name to xbee 
switch(count)
{
case 0:
    mySerial.print ("CrossOverWave");
    break;

case 1:
    mySerial.print ("ForwardWave");
    break;

case 2:
    mySerial.print ("ChasingRainbow");
    break;

case 3:
    mySerial.print ("AlternateDirectionalWave");
    break;

case 4:
    mySerial.print ("FadeInFadeOutSolidColors");
    break;

case 5:
    mySerial.print ("BidirectionalWave");
    break;

case 6:
    mySerial.print ("ChasingSolidColors");
    break;

case 7:
    mySerial.print ("FadeInFadeOutMultiColors");
    break;

case 8:
    mySerial.print ("ChasingTwoColors");
    break;

case 9:
    mySerial.print ("RandomSparkling");
    break;

case 10:
    mySerial.print ("ChasingMultiColors");
    break;

case 11:
    mySerial.print ("ChasingWhiteRedBlue");
    break;

case 12:
    mySerial.print ("Meteorite");
    break;

case 13:
    mySerial.print ("Twinkle");
    break;

case 14:
    mySerial.print ("RedGreenChase");
    break;

case 15:
    mySerial.print ("Pulse");
    break;

case 16:
    mySerial.print ("Orbit");
    break;

case 17:
    mySerial.print ("Cylon");
    break;

case 18:
    mySerial.print ("Stereo");
    break;

case 19:
    mySerial.print ("Inchworm");
    break;

case 20:
    mySerial.print ("RandomSparkling");
    break;
default:
    mySerial.print ("Count Out of Range");

    }
program_ = program_creator_(program_index_);

}

private: uint8_t programcount; uint16_t program_durationseconds; uint8_t programindex; uint32_t next_switchmillis; uint32_t next_domillis; LightProgram* (_programcreator)(uint8_t programindex); LightProgram program_; };

endif // INCLUDE_G35_PROGRAM_RUNNER_H

sowbug commented 12 years ago

Your issue report doesn't appear to describe a problem with the G35Arduino library. Are you describing an issue in this library that needs to be fixed or improved? If you're having trouble with your XBee hardware or the programming of it, there are likely to be good sources of information or support elsewhere for that commercial product. If you are describing a problem with this library, please reopen this issue and be more specific.

Incidentally, you shouldn't have to modify the G35Arduino library to switch programs remotely. See Ticon2011 for an example of a sketch that controls switching without library modifications. The reason this is important is that your changes will be overwritten as library improvements come in.

MrCarlos commented 12 years ago

Hi Mike,

Thanks for the reply. I don't have a problem with the g35 libraries. I was just looking for some friendly advice. I didn't see a forum on github setup for that specific purpose.

The example you provided in ticon2011 was helpful, but my main problem is that I don't know how to reliably monitor the serial port for an incoming character in such a way that it doesn't slow down the entire light program.

Best,

Carlos

On May 7, 2012, at 7:03 AM, Mike Tsao reply@reply.github.com wrote:

Your issue report doesn't appear to describe a problem with the G35Arduino library. Are you describing an issue in this library that needs to be fixed or improved? If you're having trouble with your XBee hardware or the programming of it, there are likely to be good sources of information or support elsewhere for that commercial product. If you are describing a problem with this library, please reopen this issue and be more specific.

Incidentally, you shouldn't have to modify the G35Arduino library to switch programs remotely. See Ticon2011 for an example of a sketch that controls switching without library modifications. The reason this is important is that your changes will be overwritten as library improvements come in.


Reply to this email directly or view it on GitHub: https://github.com/sowbug/G35Arduino/issues/12#issuecomment-5550630

sowbug commented 12 years ago

avrfreaks.net is a good forum for general microcontroller-related programming questions. You're more likely to find people who know about the hardware you're using. I know nothing about XBee, so I can't help.

Generally, the Arduino serial library isn't going to be compatible with speed-critical code. It's very slow, and it seems to be pretty liberal with its use of interrupts, which will upset the timing of the light signals.