Help with IR Remote code, Mega2560-TLC5940-RBGs


hello , thank time,


i need little help/direction ir remote code.  made simplified working sketch of trying do.  in included sketch there 2 functions call using ir remote.  functions work on own when put them switch case statement ir remote runs first millisecond (or so) of function , stops. if keep pushing button run little more each button push.  need way write sketch loop function while check additional ir button presses.

code: [select]

#include "tlc5940.h"
#include <irremote.h>

int recv_pin = 46;
irrecv irrecv(recv_pin);
decode_results results;


unsigned long previousmillis1 = 0;       
unsigned long interval1 = 10;                 
int fadevalue1 = 0;

int redfadevalue1 = 0;
int greenfadevalue1 = 0;
int bluefadevalue1 = 0;

int led1state = 0;
boolean next1 = false;




void setup(){
 
  serial.begin(9600);
  irrecv.enableirin();
  tlc.init();         
  led1state = 0;

}


void loop()   
{


  if (irrecv.decode(&results)) {

    switch(results.value) {
    case 0xff6897:
      serial.println("1"); 
      test1();
      break;
    case 0xff9867:
      serial.println("2"); 
      test2();
      break;

    }

    irrecv.resume();
  }

}




void test1(){

  switch (led1state) {
  case 0:
    {   
      interval1 = 4;         
      magentaon1();
      if (next1){
        next1 = false;
        led1state = 1;
      }
      break;
    }



  case 1:
    {   
      interval1 = 6;         
      magentaoff1();
      if (next1){
        next1 = false;
        led1state = 2;
      }
      break;
    }



  case 2:
    {   
      interval1 = 7;         
      blueon1();
      if (next1){
        next1 = false;
        led1state = 3;
      }
      break;
    }



  case 3:
    {   
      interval1 = 6;         
      blueoff1();
      if (next1){
        next1 = false;
        led1state = 0;
      }
      break;
    }

  }
}


void test2(){

  switch (led1state) {


  case 0:
    {
      interval1 = 2;         
      whiteon1();
      if (next1){
        next1 = false;
        led1state = 1;
      }
      break;
    }


  case 1:
    {
      interval1 = 8;         
      whiteoff1();
      if (next1){
        next1 = false;
        led1state = 2;
      }
      break;
    }

  case 2:
    {
      interval1 = 4;         
      blueon1();
      if (next1){
        next1 = false;
        led1state = 3;
      }
      break;
    }


  case 3:
    {
      interval1 = 8;         
      blueoff1();
      if (next1){
        next1 = false;
        led1state = 0;
      }
      break;
    }
  }
}



void blueon1(){ 
  unsigned long currentmillis1 = millis();                     
  if(currentmillis1 - previousmillis1 > interval1) {
    previousmillis1 = currentmillis1;   
    if(bluefadevalue1 <= 4000, bluefadevalue1 +=5) {

      tlc.set(2, bluefadevalue1);               

    }
    tlc.update();
  }
  if(bluefadevalue1 >= 4000){
    next1 = true;
  } 
}




void blueoff1(){
  unsigned long currentmillis1 = millis();
  if(currentmillis1 - previousmillis1 > interval1) {
    previousmillis1 = currentmillis1;
    if(bluefadevalue1 >=0, bluefadevalue1 -=5){

      tlc.set(2, bluefadevalue1);             

    }
    tlc.update();
  }
  if(bluefadevalue1 <= 0){
    next1 = true;
  }
}


void whiteon1(){ 
  unsigned long currentmillis1 = millis();                     
  if(currentmillis1 - previousmillis1 > interval1) {
    previousmillis1 = currentmillis1;   
    if(redfadevalue1 <= 2000, redfadevalue1 +=5, greenfadevalue1 <= 2000, greenfadevalue1 +=5, bluefadevalue1 <= 2000, bluefadevalue1 +=5) {

      tlc.set(0, redfadevalue1);               
      tlc.set(1, greenfadevalue1);
      tlc.set(2, bluefadevalue1);

    }
    tlc.update();
  }
  if(redfadevalue1 >= 2000){
    next1 = true;
  } 
}




void whiteoff1(){
  unsigned long currentmillis1 = millis();
  if(currentmillis1 - previousmillis1 > interval1) {
    previousmillis1 = currentmillis1;
    if(redfadevalue1 >=0, redfadevalue1 -=5, greenfadevalue1 >=0, greenfadevalue1 -=5, bluefadevalue1 >=0, bluefadevalue1 -=5){

      tlc.set(0, redfadevalue1);             
      tlc.set(1, greenfadevalue1);
      tlc.set(2, bluefadevalue1);

    }
    tlc.update();
  }
  if(redfadevalue1 <= 0){
    next1 = true;
  }
}



void magentaon1(){ 
  unsigned long currentmillis1 = millis();                     
  if(currentmillis1 - previousmillis1 > interval1) {
    previousmillis1 = currentmillis1;   
    if(redfadevalue1 <= 4000, redfadevalue1 +=5, bluefadevalue1 <= 4000, bluefadevalue1 +=5) {

      tlc.set(0, redfadevalue1);               
      tlc.set(2, bluefadevalue1);


    }
    tlc.update();
  }
  if(bluefadevalue1 >= 4000){
    next1 = true;
  } 
}




void magentaoff1(){
  unsigned long currentmillis1 = millis();
  if(currentmillis1 - previousmillis1 > interval1) {
    previousmillis1 = currentmillis1;
    if(redfadevalue1 >=0, redfadevalue1 -=5, bluefadevalue1 >=0, bluefadevalue1 -=5){

      tlc.set(0, redfadevalue1);             
      tlc.set(2, bluefadevalue1);

    }
    tlc.update();
  }
  if(bluefadevalue1 <= 0){
    next1 = true;
  }
}



i reading code until wtf light came on:
code: [select]
    if(redfadevalue1 <= 4000, redfadevalue1 +=5, bluefadevalue1 <= 4000, bluefadevalue1 +=5) {
this nonsense.


Arduino Forum > Using Arduino > Programming Questions > Help with IR Remote code, Mega2560-TLC5940-RBGs


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support