I am fairly new to the arduino world, and as I am going through examples and learning I also am combining projects together to help me learn, and see new things. My current project how ever is giving me some trouble.
What I would like to do is control a series of LED's by way of a remote control. I have 8 LED's connected to an arduino UNO by way of a 8 bit shift resister (IC SN74HC595N), and a IR receiver. I have code that I know works with the IR receiver, and I have code that works with my shift resister. The following is a simple proof of concept to make them work together:
#include "IRremote.h"
int LatchPin = 5;
int ClockPin = 6;
int DataPin = 4;
int OutputEnablePin = 10;
int LedTest = 10;
bool t = true;
bool f = false;
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
byte Leds = 0;
void setup() {
irrecv.enableIRIn();
pinMode(LatchPin, OUTPUT);
pinMode(DataPin, OUTPUT);
pinMode(ClockPin, OUTPUT);
pinMode(OutputEnablePin, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (irrecv.decode(&results))
{
Serial.println("Does this actually work?");
LedTester();
Serial.println("after LedTester()");
irrecv.resume();
}
//IrInput();
}
void updateShiftRegister()
{
digitalWrite(LatchPin, LOW);
shiftOut(DataPin, ClockPin, LSBFIRST, Leds);
digitalWrite(LatchPin, HIGH);
}
void setBrightness(int brightness)
{
analogWrite(OutputEnablePin, 255-brightness);
}
void IrInput()
{
if (irrecv.decode(&results)) {
Serial.println("This finally works");
irrecv.resume();
}
}
void LedTester()
{
for (int i = 0; i < 8; i++)
{
bitSet(Leds, i);
updateShiftRegister();
delay(100);
}
for (int b = 255; b > 0; b--)
{
Serial.print("Byte Brightness: ");
Serial.println(b);
setBrightness(b);
updateShiftRegister();
delay(30);
}
}
If you run the code as is, it will start up and as soon as you push a button on a remote, it triggers the LEDTester(). and also prints out following line. So I know it is getting stuck on the irrecv.resume() but I do not know why. I have my shift resister hooked up through 4,5,6,10 and my IR sensor is hooked up through 11.
My theory is it has something to do with timing and PWM, but I am not sure what. I have looked and searched around. Most sites suggested trying to switch the pins that I am using around which I did, and it made it work up till this point.
Any suggestions, or hints towards the right direction would be more then greatly appreciated.
Attached is the schematic that I used for my hook up.
Paul
