Hi All,
I am new to arduino (but like it very much). I have connected a 7 segment display to my arduino uno via a shift register (74HC595). I developed a code which must display "2" on the seven segment display when button 1 on ir remote is pressed. But "2" must change to "3" if button 2 on ir remote is pressed and vice versa. By using the below code, 2 is displayed at the instance the code is recieved from ir transmitter and then the display resets within a few milliseconds. i want the display to show the same number unless i press another button on the ir transmitter. Any help will be appreciated.
Here is the code:
#include <IRremote.h>
const int latchPin = 5; //Pin connected to Pin 12 of 74HC595 (Latch)
const int dataPin = 6; //Pin connected to Pin 14 of 74HC595 (Data)
const int clockPin = 7; //Pin connected to Pin 11 of 74HC595 (Clock)
int i =0;
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
const byte numbers[16] = {
0b11111100,
0b01100000,
0b11011010,
0b11110010,
0b01100110,
0b10110110,
0b10111110,
0b11100000,
0b11111110,
0b11100110,
0b11101110,
0b00111110,
0b10011100,
0b01111010,
0b10011110,
0b11111111
};
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
{
//set pins to output
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
}
void loop()
{
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
{
if(results.value == 0xFF22DD) show(numbers[2]);
if(results.value == 0x52A3D41F) show(numbers[2]);
if(results.value == 0xFFF00F) show(numbers[3]);
if(results.value == 0x35A9425F) show(numbers[3]);
}
}
void show( byte number)
{
/* Loop over each segment in the "number" we're about to display,
* and illuminate only one segment at a time.
*/
for(int j=0; j<=7; j++)
{
byte toWrite = number & (0b11011010 >> j);
if(!toWrite) { continue; }
shiftIt(toWrite);
}
}
void shiftIt (byte data)
{
digitalWrite(latchPin, LOW);
for (int k=0; k<=7; k++)
{
// clockPin LOW prior to sending bit
digitalWrite(clockPin, LOW);
if ( data & (1 << k) )
{
digitalWrite(dataPin, LOW); // turn "On"
}
else
{
digitalWrite(dataPin, HIGH); // turn "Off"
}
// and clock the bit in
digitalWrite(clockPin, HIGH);
}
//stop shifting out data
digitalWrite(clockPin, LOW);
//set latchPin to high to lock and send data
digitalWrite(latchPin, HIGH);
}