Go Down

Topic: blink led with remote (Read 3162 times) previous topic - next topic

Henrywallace

Okay ill try those pins. The problem is that pin 5 is the reset pin on my attiny, is that going to affect anything. Im not sure how the reset pin actually works. And youre right about using

digitalWrite(RELAY_PIN, signal_on);
digitalWrite(LED_PIN, signal_on);

the example code i based my work off of showed it the other way but that seems way more complicated.

larryd

I don't have an attiny, pick the pins you want.



.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

Henrywallace

#32
Aug 17, 2017, 10:02 pm Last Edit: Aug 17, 2017, 10:08 pm by Henrywallace
These are the pins. Any ideas which ones would be best to use?

larryd



I plead ignorance, as mentioned don't have a tiny. :(
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

larryd

Looks like 0,1,2,5  might be okay.


.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

Henrywallace

Looks like 0,1,2,5  might be okay.


.
Sorry. I tried to link the image the first time but it looks like it didnt work so i just attatched an image of it on my last post. So a pin layout like this should be correct?


int RECV_PIN = 0;
int RELAY_PIN = 1;
int LED_PIN = 2;
int BLINK_PIN = 5;

larryd

You will just have to try it.


.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

Henrywallace

I definitely will. Im off in 2 hours. I will let you know how it works so you know, also so future people know how to fix the problem.

Henrywallace

I went home and had a couple issues but here is the final code that worked perfectly. I will be making a final version without the two leds so it just controls the leds. They were only there for testing purposes but now i am working on the final copy. I will be starting another project today and hope to finish it by the end of the weekend. It will have to do with IR control of a motor. Look for my thread in the forums if youre interested.

Code: [Select]
#include <IRremote.h>
#include <IRremoteInt.h>
int RECV_PIN = 0;
int RELAY_PIN = 1;
int LED_PIN = 2;
int BLINK_PIN = 4;
int ON_TIME = 10000;

bool signal_on = 0;
bool led_on = 0;

unsigned long previousMillis = 0;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
  pinMode(RELAY_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  pinMode(BLINK_PIN, OUTPUT);
  pinMode(RECV_PIN, INPUT);
  irrecv.enableIRIn();

  digitalWrite(RELAY_PIN, LOW);
  digitalWrite(LED_PIN, LOW);
  digitalWrite(BLINK_PIN, LOW);
}
void loop() {


  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= 250) {

    previousMillis = currentMillis;
    led_on = !led_on;
    digitalWrite(BLINK_PIN, led_on);

  }

  if (irrecv.decode(&results)) {
    signal_on = !signal_on;
    digitalWrite(RELAY_PIN, signal_on ? HIGH : LOW);
    digitalWrite(LED_PIN, signal_on ? HIGH : LOW);
    irrecv.resume();
  }

}

larryd

#39
Aug 18, 2017, 08:53 pm Last Edit: Aug 18, 2017, 08:53 pm by larryd
FYI
If a remote sends a repeat code after an initial code, use this to ignore the repeat code.

Code: [Select]
 if (irrecv.decode(&results))
  {
    if (results.value != 0xFFFFFFFF) //NEC repeat code
    {
      signal_on = !signal_on;
      digitalWrite(RELAY_PIN, signal_on);
      digitalWrite(LED_PIN, signal_on);
    }
    
    irrecv.resume();
  }





.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

Henrywallace

FYI
If a remote sends a repeat code after an initial code, use this to ignore the repeat code.

Code: [Select]
if (irrecv.decode(&results))
  {
    if (results.value != 0xFFFFFFFF) //NEC repeat code
    {
      signal_on = !signal_on;
      digitalWrite(RELAY_PIN, signal_on);
      digitalWrite(LED_PIN, signal_on);
    }
   
    irrecv.resume();
  }


Illl try that because sometimes if i dont quickly press the button and i hold it for a second it will flicker on then off. I just didnt think it was a big deal because i usually just quick click the button. Thank you for that help.


.

Go Up