Defining start up state

Hi,

Can anyone explain how I would initiate the PLAY/PAUSE state on startup without sending the IR signal?

Thankyou all

#include <IRremote.h>


int receiver = 2; //  IR receiver to Arduino digital pin 2

IRrecv irrecv(receiver);           // create instance of 'irrecv'
decode_results results;            // create instance of 'decode_results'



void setup()   
{
  Serial.begin(9600);
  Serial.println("ACTIVE");
  irrecv.enableIRIn(); // Start the receiver

}


void loop()   
{
  if (irrecv.decode(&results)) // Check for IR signal
  
  {
//    Serial.println(results.value, HEX);  UN Comment to see raw values
    translateIR(); 
    irrecv.resume(); // receive the next value
  }  
}/* --(end main loop )-- */

/*-----( Declare Functions )-----*/
void translateIR() // takes action based on IR code received



{

  switch(results.value)

  {

  case 0xFFA25D:  
    Serial.println(" CH-            "); 
    break;

     case 0xFFE01F: 
    Serial.println(" CH             "); 
    break;

  case 0xFFE21D:  
    Serial.println(" CH+            "); 
    break;

  case 0xFF22DD:  
    Serial.println(" PREV           "); 
    break;
    
case 0xFFC23D:

    Serial.println(" NEXT           "); 
    break;

 case 0xFF02FD:   
    Serial.println(" PLAY/PAUSE     "); 
    break;

 
  case 0xFFA857: 
    Serial.println(" VOL-           "); 
    break;

  
  case 0xFF629D: 
    Serial.println(" VOL+           "); 
    break;

  case 0xFF906F:  
    Serial.println(" EQ             "); 
    break;

    case 0xFF4AB5:  
    Serial.println(" 0              "); 
    break;

  
    Serial.println("*          "); 
    break;

   
    Serial.println(" #           "); 
    break;

   
  case 0xFF6897:
    Serial.println(" 1              "); 
    break;

case 0xFF9867:  
  // 
    Serial.println(" 2              "); 
    break;
    
case 0xFFB04F: 
    Serial.println(" 3              "); 
    break;
    
case 0xFF30CF: 
  //  
    Serial.println(" 4              "); 
    break;

case 0xFF18E7: 
// 
    Serial.println(" 5              "); 
    break;

case 0xFF7A85:  
//    
    Serial.println(" 6              "); 
    break;

case 0xFF10EF:
 // case 0xFF42BD:  
    Serial.println(" 7              "); 
    break;

 case 0xFF38C7:  
//  
    Serial.println(" 8              "); 
    break;

case 0xFF5AA5:
//  case 0xFF52AD:  
    Serial.println(" 9              "); 
    break;

  default: 
    Serial.println(" other button   ");

  }

  delay(500);


} //END translateIR

Could you alter your translateIR procedure to take an optional parameter that (if present) is used instead of 'results.value'

I'm a bit unsure of that one, I was considering possibly a feature where if no IR was detected then state = play/pause. This would hopefully cause it to activate a certain state if no IR is detected immediately upon start up?

Kind Regards

void translateIR() // takes action based on IR code received

Why not pass it a parameter, rather than relying on a global?

Untested code but if it does not work you should get the idea.

#include <IRremote.h>


int receiver = 2;                   //  IR receiver to Arduino digital pin 2

IRrecv irrecv(receiver);            // create instance of 'irrecv'
decode_results results;             // create instance of 'decode_results'



void setup()   
{
  Serial.begin(9600);
  Serial.println("ACTIVE");
  irrecv.enableIRIn();              // Start the receiver
  translateIR(0xFF02FDUL);          // Play/Pause
}


void loop()   
{
  if (irrecv.decode(&results))      // Check for IR signal
  
  {
    //    Serial.println(results.value, HEX);  UN Comment to see raw values
    irrecv.resume(); // receive the next value
    translateIR(results.value); 
  }  
}/* --(end main loop )-- */

/*-----( Declare Functions )-----*/
void translateIR(unsigned long irValue) // takes action based on IR code received
{
  
  switch(irValue)
  {
    
    case 0xFFA25D:  
    Serial.println(" CH-            "); 
    break;
    
    case 0xFFE01F: 
    Serial.println(" CH             "); 
    break;
    
    case 0xFFE21D:  
    Serial.println(" CH+            "); 
    break;
    
    case 0xFF22DD:  
    Serial.println(" PREV           "); 
    break;
    
    case 0xFFC23D:
    
    Serial.println(" NEXT           "); 
    break;
    
    case 0xFF02FD:   
    Serial.println(" PLAY/PAUSE     "); 
    break;
    
    
    case 0xFFA857: 
    Serial.println(" VOL-           "); 
    break;
    
    
    case 0xFF629D: 
    Serial.println(" VOL+           "); 
    break;
    
    case 0xFF906F:  
    Serial.println(" EQ             "); 
    break;
    
    case 0xFF4AB5:  
    Serial.println(" 0              "); 
    break;
    
    
    Serial.println("*          "); 
    break;
    
    
    Serial.println(" #           "); 
    break;
    
    
    case 0xFF6897:
    Serial.println(" 1              "); 
    break;
    
    case 0xFF9867:  
    // 
    Serial.println(" 2              "); 
    break;
    
    case 0xFFB04F: 
    Serial.println(" 3              "); 
    break;
    
    case 0xFF30CF: 
    //  
    Serial.println(" 4              "); 
    break;
    
    case 0xFF18E7: 
    // 
    Serial.println(" 5              "); 
    break;
    
    case 0xFF7A85:  
    //    
    Serial.println(" 6              "); 
    break;
    
    case 0xFF10EF:
    // case 0xFF42BD:  
    Serial.println(" 7              "); 
    break;
    
    case 0xFF38C7:  
    //  
    Serial.println(" 8              "); 
    break;
    
    case 0xFF5AA5:
    //  case 0xFF52AD:  
    Serial.println(" 9              "); 
    break;
    
    default: 
    Serial.println(" other button   ");
    
  }
  
  delay(500);
  
  
} //END translateIR
Serial.println(" CH-            ");

Excellent way of wasting precious RAM.
Use Serial.println(F(" CH-            ")); instead

I really appreciate the guidance, I am a total novice as far as programming goes..

Take a look at the code below, When Play/pause activates, I'm trying to find how to get it to loop unless say the 1 button on my IR is pressed at which point it would go to case 1 and loop whilst checking?

Kind Regards, Thanks for your time..

edit.. I am just adding the suggested

AWOL:

Serial.println(" CH-            ");

Excellent way of wasting precious RAM.
Use Serial.println(F(" CH-            ")); instead

#include <IRremote.h>
int receiver = 2;                   //  IR receiver to Arduino digital pin 2

IRrecv irrecv(receiver);            // create instance of 'irrecv'
decode_results results;             // create instance of 'decode_results'

int led = 13;

void setup()   
{
  Serial.begin(9600);
  Serial.println("ACTIVE");
  irrecv.enableIRIn();              // Start the receiver
  translateIR(0xFF02FDUL);          // Play/Pause
  pinMode(led, OUTPUT);
}


void loop()   
{
  if (irrecv.decode(&results))      // Check for IR signal
  
  {
    //    Serial.println(results.value, HEX);  UN Comment to see raw values
    irrecv.resume(); // receive the next value
    translateIR(results.value); 
  }  
}/* --(end main loop )-- */

/*-----( Declare Functions )-----*/
void translateIR(unsigned long irValue) // takes action based on IR code received
{
  
  switch(irValue)
  {
    
    case 0xFFA25D:  
    Serial.println(" CH-            "); 
    break;
    
    case 0xFFE01F: 
    Serial.println(" CH             "); 
    break;
    
    case 0xFFE21D:  
    Serial.println(" CH+            "); 
    break;
    
    case 0xFF22DD:  
    Serial.println(" PREV           "); 
    break;
    
    case 0xFFC23D:
    
    Serial.println(" NEXT           "); 
    break;
    
    case 0xFF02FD:   
    Serial.println(" PLAY/PAUSE     ");
    digitalWrite(led, HIGH);
    delay(1000);
    digitalWrite(led, LOW);
    delay(1000);
    break;
    
    
    case 0xFFA857: 
    Serial.println(" VOL-           "); 
    break;
    
    
    case 0xFF629D: 
    Serial.println(" VOL+           "); 
    break;
    
    case 0xFF906F:  
    Serial.println(" EQ             "); 
    break;
    
    case 0xFF4AB5:  
    Serial.println(" 0              "); 
    break;
    
    
    Serial.println("*          "); 
    break;
    
    
    Serial.println(" #           "); 
    break;
    
    
    case 0xFF6897:
    Serial.println(" 1              "); 
    digitalWrite(led, HIGH);
    break;
    
    case 0xFF9867:  
    // 
    Serial.println(" 2              "); 
    break;
    
    case 0xFFB04F: 
    Serial.println(" 3              "); 
    break;
    
    case 0xFF30CF: 
    //  
    Serial.println(" 4              "); 
    break;
    
    case 0xFF18E7: 
    // 
    Serial.println(" 5              "); 
    break;
    
    case 0xFF7A85:  
    //    
    Serial.println(" 6              "); 
    break;
    
    case 0xFF10EF:
    // case 0xFF42BD:  
    Serial.println(" 7              "); 
    break;
    
    case 0xFF38C7:  
    //  
    Serial.println(" 8              "); 
    break;
    
    case 0xFF5AA5:
    //  case 0xFF52AD:  
    Serial.println(" 9              "); 
    break;
    
    default: 
    Serial.println(" other button   ");
    
  }
  
  delay(500);
  
  
} //END translateIR

Take a look at the code below, When Play/pause activates, I'm trying to find how to get it to loop unless say the 1 button on my IR is pressed at which point it would go to case 1 and loop whilst checking?

Sorry I have lost you. I'm not understanding what it is your trying to achieve.

When the arduino is powered up, this code will run case PLAY/PAUSE but it only seems to run it once as there is no instruction for it to repeat. As far as I have read the 'For' statement will allow me to achieve a loop although I'm not certain if it I can use that instruction within a switch case.. So the end result would be, repeat PLAY/PAUSE unless IR Receives hex in which case it will run whatever case I key

Sorry, As I explained I really am novice here so, thanks..

Edited

#include <IRremote.h>

int pump1 = 5;
int pump2 = 13;
int receiver = 2;                   //  IR receiver to Arduino digital pin 2

IRrecv irrecv(receiver);            // create instance of 'irrecv'
decode_results results;             // create instance of 'decode_results'



void setup()   
{
    pinMode(pump1, OUTPUT);
  pinMode(pump2, OUTPUT);

  Serial.begin(9600);
  Serial.println("ACTIVE");
  irrecv.enableIRIn();              // Start the receiver
  translateIR(0xFF02FDUL);          // Play/Pause
}


void loop()   
{
  if (irrecv.decode(&results))      // Check for IR signal
  
  {
    //    Serial.println(results.value, HEX);  UN Comment to see raw values
    irrecv.resume(); // receive the next value
    translateIR(results.value); 
  }  
}/* --(end main loop )-- */

/*-----( Declare Functions )-----*/
void translateIR(unsigned long irValue) // takes action based on IR code received
{
  
  switch(irValue)
  {
    
    case 0xFFA25D:  
    Serial.println(" CH-            "); 
    break;
    
    case 0xFFE01F: 
    Serial.println(" CH             "); 
    break;
    
    case 0xFFE21D:  
    Serial.println(" CH+            "); 
    break;
    
    case 0xFF22DD:  
    Serial.println(" PREV           "); 
    break;
    
    case 0xFFC23D:
    
    Serial.println(" NEXT           "); 
    break;
    
    case 0xFF02FD:   
    Serial.println(" PLAY/PAUSE     "); 
        digitalWrite(pump1, HIGH);
    digitalWrite(pump2, LOW);
    delay(800);
    digitalWrite(pump1, LOW);
    digitalWrite(pump2, HIGH);
    delay(800);
    break;
    
    
    case 0xFFA857: 
    Serial.println(" VOL-           "); 
    break;
    
    
    case 0xFF629D: 
    Serial.println(" VOL+           "); 
    break;
    
    case 0xFF906F:  
    Serial.println(" EQ             "); 
    break;
    
    case 0xFF4AB5:  
    Serial.println(" 0              "); 
    digitalWrite(pump1, LOW);
    digitalWrite(pump2, LOW);
    break;
    
    
    Serial.println("*          "); 
    break;
    
    
    Serial.println(" #           "); 
    break;
    
    
    case 0xFF6897:
    Serial.println(" 1              "); 
    break;
    
    case 0xFF9867:  
    // 
    Serial.println(" 2              "); 
    break;
    
    case 0xFFB04F: 
    Serial.println(" 3              "); 
    break;
    
    case 0xFF30CF: 
    //  
    Serial.println(" 4              "); 
    break;
    
    case 0xFF18E7: 
    // 
    Serial.println(" 5              "); 
    break;
    
    case 0xFF7A85:  
    //    
    Serial.println(" 6              "); 
    break;
    
    case 0xFF10EF:
    // case 0xFF42BD:  
    Serial.println(" 7              "); 
    break;
    
    case 0xFF38C7:  
    //  
    Serial.println(" 8              "); 
    break;
    
    case 0xFF5AA5:
    //  case 0xFF52AD:  
    Serial.println(" 9              "); 
    break;
    
    default: 
    Serial.println(" other button   ");
    
  }
  
  delay(500);
  
  
} //END translateIR

When the arduino is powered up, this code will run case PLAY/PAUSE but it only seems to run it once as there is no instruction for it to repeat. As far as I have read the 'For' statement will allow me to achieve a loop although I'm not certain if it I can use that instruction within a switch case.. So the end result would be, repeat PLAY/PAUSE unless IR Receives hex in which case it will run whatever case I key

If you put a for..loop in the translateIR routine that needs a different key press to break out it will never receive the new ir code as it being read somewhere else (main loop).
Why do you need the play/pause command to continually execute until another ir code is received and is it only the play/pause you want to repeat or any received ir code?
If you can break down the sequence you want to happen on startup and when ir codes are received it will help us to write a better reply.

Marine Aquarium controller..

2 mosfets Controlled by ds1307 creating a linear 2 hour fade from 0-1023 pwm for two channels (Sun / Moon) for sunrise/sunset simulation.

two further mosfets currently being used as simple gates for alternating between two pumps (wave simulation)

temp probe for monitoring temps

LCD 16x2

Now, I will include the code below as an attachment but please be aware that I am a total non-academic rookie when it comes to programming and this literally is my first arduino build with function..

In an ideal world, Id like to be able to trigger different lighting and pump schemes based on my IR and then click it back to RTC controlled..

so the Switch Case method was a way of testing the water for different code structures...

Tankcontrol_modified_LCDTEMP.ino (10.2 KB)

When the arduino is powered up, this code will run case PLAY/PAUSE but it only seems to run it once as there is no instruction for it to repeat.

I don't have the hardware at hand to test the IR library but I altered the original code so it should keep calling the translateIR procedure with the last received IR value (or play/pause) until a new one is received.

#include <IRremote.h>


int receiver = 2;                   //  IR receiver to Arduino digital pin 2

IRrecv irrecv(receiver);            // create instance of 'irrecv'
decode_results results;             // create instance of 'decode_results'



void setup()   
{
  Serial.begin(9600);
  Serial.println("ACTIVE");
  irrecv.enableIRIn();              // Start the receiver
  results.value = 0xFF02FDUL
}


void loop()   
{
  if (irrecv.decode(&results))      // Check for IR signal
  {
    irrecv.resume(); // receive the next value
  }  
  translateIR(results.value); 
}

void translateIR(unsigned long irValue) // takes action based on IR code received
{
  
  switch(irValue)
  {
    
    case 0xFFA25D:  
    Serial.println(" CH-            "); 
    break;
    
    case 0xFFE01F: 
    Serial.println(" CH             "); 
    break;
    
    case 0xFFE21D:  
    Serial.println(" CH+            "); 
    break;
    
    case 0xFF22DD:  
    Serial.println(" PREV           "); 
    break;
    
    case 0xFFC23D:
    
    Serial.println(" NEXT           "); 
    break;
    
    case 0xFF02FD:   
    Serial.println(" PLAY/PAUSE     "); 
    break;
    
    
    case 0xFFA857: 
    Serial.println(" VOL-           "); 
    break;
    
    
    case 0xFF629D: 
    Serial.println(" VOL+           "); 
    break;
    
    case 0xFF906F:  
    Serial.println(" EQ             "); 
    break;
    
    case 0xFF4AB5:  
    Serial.println(" 0              "); 
    break;
    
    
    Serial.println("*          "); 
    break;
    
    
    Serial.println(" #           "); 
    break;
    
    
    case 0xFF6897:
    Serial.println(" 1              "); 
    break;
    
    case 0xFF9867:  
    // 
    Serial.println(" 2              "); 
    break;
    
    case 0xFFB04F: 
    Serial.println(" 3              "); 
    break;
    
    case 0xFF30CF: 
    //  
    Serial.println(" 4              "); 
    break;
    
    case 0xFF18E7: 
    // 
    Serial.println(" 5              "); 
    break;
    
    case 0xFF7A85:  
    //    
    Serial.println(" 6              "); 
    break;
    
    case 0xFF10EF:
    // case 0xFF42BD:  
    Serial.println(" 7              "); 
    break;
    
    case 0xFF38C7:  
    //  
    Serial.println(" 8              "); 
    break;
    
    case 0xFF5AA5:
    //  case 0xFF52AD:  
    Serial.println(" 9              "); 
    break;
    
    default: 
    Serial.println(" other button   ");
  }
  delay(500);
} //END translateIR