Beginner Stumped

OK, I'm going to try this again. I want to use a RF remote control to operate a couple of things. The problem is the remote is only a pulse output. So I'm going to use pulse on the Arduino which will in turn drive a relay so I can have a switch. It is pulse on pulse off type of arrangement. The code I have below works very well for one relay. Now I need to write more code like it so I can use the other 3 outputs from the remote. In the end I want 4 pulse on pulse off relays. I just don't know what code I need now. Is it the same as I have but change the input and output pin numbers for the Aurduino? I have more or less tried taking this code and adding it at the bottom but I changed to pin 4 and 5. I have tried to find similar examples but didn't have any luck. Looked at a couple of references to no avail. Your help will be appreciated.

Thanks Greg

#define LED  2                           // Channel 1 Output
#define BUTTON 3                         // Channel 1 Input
                               
int val = 0;                              // val will be used to store the state
// of the input pin    
//int old_val = 0;                         // this variable stores the previous
// value of "val"    
int state = 0;                              // 0 = LED off and 1 = LED on 

void setup() { 
  pinMode(LED, OUTPUT);                    // tell Arduino LED is an output 
  pinMode(BUTTON, INPUT);                  // and BUTTON is an input 
} 

void loop(){ 
  val = digitalRead(BUTTON);                // read input value and store it 
  // yum, fresh 

  // check if there was a transition 
  if ((val == HIGH) && (old_val == LOW)){ 
    state = 1 - state;
    delay(10);
  } 

  old_val = val;                            // val is now old, let's store it 

  if (state == 1) {      
    digitalWrite(LED, HIGH); // turn LED ON 
  } 
  else { 
    digitalWrite(LED, LOW); 
  } 
}

You really should read the sticky at the top of the (this) forum.

Its difficult to tell what you are trying to do, and difficult to read your code. The advice above tells you how to write a better question.

Sorry about the code being messy but I tried several ways to get it pasted nd it all turned out bad. As for the question I thinks its very plain. Sorry to have bothered anyone here I will look else where.

You just have to put code tags around it, it's not that hard. There is a button marked "#" above the posting area that does it.

#define LED  2          // Channel 1 Output
#define BUTTON 3    // Channel 1 Input
// Remote channel 1 connected
int val = 0;             // val will be used to store the state
// of the input pin 
int old_val = 0;      // this variable stores the previous
// value of "val"
int state = 0;        // 0 = LED off and 1 = LED on 

void setup () {
  pinMode(LED, OUTPUT);   // tell Arduino LED is an output 
  pinMode (BUTTON, INPUT );  // and BUTTON is an input 
}

void loop(){
  val = digitalRead(BUTTON);      // read input value and store it 
  // yum, fresh 
  // check if there was a transition 
  if ((val == HIGH) && (old_val == LOW)){
    state = 1 - state;
    delay(10);
  } 

  old_val = val; // val is now old, let's store it

  if (state == 1) {     
    digitalWrite(LED, HIGH); // turn LED ON
  } 
  else {
    digitalWrite(LED, LOW);
  } 
}

Sorry to have bothered anyone here I will look else where.

OK, well if you don't want any help, goodbye.

Nick Thank you for the help. I asked the question the best I know how. As for the code I did try the # button but when I pasted the code in I got the code along with all the code for text color etc. I'm not sure how to get rid of all that.

Thanks Greg

Going to try posting code one more time. Not sure what I did different but it looks OK now.

#define LED  2    // Channel 1 Output
#define BUTTON 3  // Channel 1 Input
// Remote channel 1 connected
int val = 0;      // val will be used to store the state
// of the input pin 
//int old_val = 0;  // this variable stores the previous
// value of "val" 
int state = 0;    // 0 = LED off and 1 = LED on 

void setup() { 
  pinMode(LED, OUTPUT);   // tell Arduino LED is an output 
  pinMode(BUTTON, INPUT); // and BUTTON is an input 
} 

void loop(){ 
  val = digitalRead(BUTTON); // read input value and store it 
  // yum, fresh 

  // check if there was a transition 
  if ((val == HIGH) && (old_val == LOW)){ 
    state = 1 - state;
    delay(10);
  } 

  old_val = val; // val is now old, let's store it 

  if (state == 1) {      
    digitalWrite(LED, HIGH); // turn LED ON 
  } 
  else { 
    digitalWrite(LED, LOW); 
  } 
}

Ah I see. You used the "Copy for Forum" feature. Unfortunately that doesn't work very well. Just copy your code as text, paste it and use the "#" button to put code tags around it. That's all you have to do.

I have it working for 1 output but cannot find how to write additional code to be able to assign other pins on the Arduino for the remaining 3 channels

If you can clarify your intentions here, I'm sure someone will be pleased to help.

If I understand your question correctly, what you would do is:

    #define LED_1 2
    #define LED_2 3
    #define LED_3 4
//above is your 3 outputs
    #define BUTTON_1 7
    #define BUTTON_2 8
    #define BUTTON_3 9
//above is your 3 inputs

and in your setup()

    pinMode(LED_1, OUTPUT);   
    pinMode(LED_2, OUTPUT);  
    pinMode(LED_3, OUTPUT);  
//set digital pins 2,3 and 4 to OUTPUT
    pinMode (BUTTON_1, INPUT );  
    pinMode (BUTTON_2, INPUT );  
    pinMode (BUTTON_3, INPUT );  
//7,8 and 9 to INPUT

I hope I understood your question right and was of help.

Yes I think you understood what I was needing. I'm going to give it a try and see what happens.

Thanks Greg

intlab_sulas: If I understand your question correctly, what you would do is:

    #define LED_1 2
    #define LED_2 3
    #define LED_3 4
//above is your 3 outputs
    #define BUTTON_1 7
    #define BUTTON_2 8
    #define BUTTON_3 9
//above is your 3 inputs

and in your setup()

    pinMode(LED_1, OUTPUT);   
    pinMode(LED_2, OUTPUT);  
    pinMode(LED_3, OUTPUT);  
//set digital pins 2,3 and 4 to OUTPUT
    pinMode (BUTTON_1, INPUT );  
    pinMode (BUTTON_2, INPUT );  
    pinMode (BUTTON_3, INPUT );  
//7,8 and 9 to INPUT

I hope I understood your question right and was of help.