hiii
iam using arduino uno and sm0038 ir receiver
it works good for the following code
#include <IRremote.h>
int receiver = 7;
IRrecv irrecv(receiver);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop()
{
if (irrecv.decode(&results))
{
Serial.println(results.value);
irrecv.resume();
}
}
i want to make a ball and bat game on 16x16 led matrix display using 4 shift registers (74hc595)
i want to move the bat using ir remote(bat=>3 leds glowing).so to check the motion of the bat moving in a coloumn
i wrote the following code
#include <SPI.h>
#include <IRremote.h>
int latchpin = 4;
int clockPin = 13;
int dataPin = 11;
int receiver = 7; //pin going to output pin of sm0038
IRrecv irrecv(receiver);
decode_results results;
unsigned long int bswitchvalue=0;
int batpos[3]={601,701,801};//601 represents the position of bat leds i.e 6th row and 1st coloumn
int batc,batr; //of the byte array l1[]
//i wrote in such a way that i can use those 6 and 1 values in bitset(),bitclear()
byte x;
byte l1[8]=
{
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B10000000,//here the three ones represent the bat position
B10000000,
B10000000
};
byte l2[8]={
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000
};
byte l3[8]={
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000
};
byte l4[8]={
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000
};
void setup()
{
pinMode(latchpin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
SPI.setBitOrder(LSBFIRST);
SPI.begin();
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop()
{
if (irrecv.decode(&results)==true)
{
bswitchvalue =results.value;
Serial.println(results.value);
irrecv.resume();
if(bswitchvalue>0)
{
switch(bswitchvalue)
{
case 3249147378:
batmotion1();
bswitchvalue=0;
break;
case 3249163698:
batmotion2();
bswitchvalue=0;
break;
}
}
}
disp();
}
void batmotion1() //function for corresponding button here bat moves up
{
if(batpos[0]>101)
{
batr=batpos[2]/100;
clearingbits(batr,1);
for(int i=0;i<3;i++)
{
batpos[i]=batpos[i]-100;
}
batr=batpos[0]/100;
settingbits(batr,1);
}
}
void batmotion2()
{
if(batpos[2]<1601)
{
batr=batpos[0]/100;
clearingbits(batr,1);
for(int i=0;i<3;i++)
{
batpos[i]=batpos[i]+100;
}
batr=batpos[2]/100;
settingbits(batr,1);
}
}
void settingbits(int R,int C)
{
if(R<9&&C<9)
{
R=R-1;
C=8-C;
bitSet(l1[R],C);
}
if(R<9&&C>8)
{
R=R-1;
C=16-C;
bitSet(l2[R],C);
}
if(R>8&&C<9)
{
R=R-9;
C=8-C;
bitSet(l3[R],C);
}
if(R>8&&C>8)
{
R=R-9;
C=16-C;
bitSet(l4[R],C);
}
}
void clearingbits(int R,int C)
{
if(R<9&&C<9)
{
R=R-1;
C=8-C;
bitClear(l1[R],C);
}
if(R<9&&C>8)
{
R=R-1;
C=16-C;
bitClear(l2[R],C);
}
if(R>8&&C<9)
{
R=R-9;
C=8-C;
bitClear(l3[R],C);
}
if(R>8&&C>8)
{ R=R-9;
C=16-C;
bitClear(l4[R],C);
}
}
void disp()
{
int i;
x=B10000000;
for(i=0;i<8;i++)
{
digitalWrite(latchpin,LOW);
SPI.transfer(B11111111);
SPI.transfer(~l1[i]);
SPI.transfer(B00000000);
SPI.transfer(x);
digitalWrite(latchpin,HIGH);
delayMicroseconds(500);
x=x>>1;
}
x=B10000000;
for(i=0;i<8;i++)
{
digitalWrite(latchpin,LOW);
SPI.transfer(~l2[i]);
SPI.transfer(B11111111);
SPI.transfer(B00000000);
SPI.transfer(x);
digitalWrite(latchpin,HIGH);
delayMicroseconds(500);
x=x>>1;
}
x=B10000000;
for(i=0;i<8;i++)
{
digitalWrite(latchpin,LOW);
SPI.transfer(B11111111);
SPI.transfer(~l3[i]);
SPI.transfer(x);
SPI.transfer(B00000000);
digitalWrite(latchpin,HIGH);
delayMicroseconds(500);
x=x>>1;
}
x=B10000000;
for(i=0;i<8;i++)
{
digitalWrite(latchpin,LOW);
SPI.transfer(~l4[i]);
SPI.transfer(B11111111);
SPI.transfer(x);
SPI.transfer(B00000000);
digitalWrite(latchpin,HIGH);
delayMicroseconds(500);
x=x>>1;
}
}
when i upload the above code values other than the remote are found in serial monitor.

iam getting values even without pressing the buttons on remote.
please help me with the reason why this happening.
thank you