Sign In

Trouble In Reducing The Code

ASHISH NATH nath23ashish@gmail.com India

Hardware: Aurdino Uno ATMEGA32 Software: Aurdino IDE

i bought your kit and made it successfully using aurdino ,but the code become too big it is
about 11.6K ,
how you did that in under 8K ,did u used interrupts for TOSP too.
or did u used any specific library for that.z plz reply.i used iRremote lib for IR sensor .
PLz reply son

Images

Program

#include <IRremote.h>
const int RECV_PIN=11;
IRrecv irrecv(RECV_PIN);
decode_results results;
boolean Power=0;  // Flag to indicate we have crossed zero
volatile boolean zerocross=0;  
int Delay=4;
#define AC_pin 10              // Output to Opto Triac
               
byte numbers[10] = { 
                    B0110000, B1101101, B1111001, B0110011, 
                    B1011011, B1011111, B1110000, B1111111, B1110011
                    };
        
 
void setup()                    // Begin setup
  
{
  Serial.begin(9600);   
  pinMode(AC_pin, OUTPUT);
  attachInterrupt(0, zero_cross_detect, RISING);    // Attach an Interupt to Pin 2 (interupt 0) for Zero Cross Detection
  irrecv.enableIRIn();                              // Start the receiver
  irrecv.blink13(true);
  for(int i = 3; i <= 9; i++) 
       {
        pinMode(i, OUTPUT);
        digitalWrite(i,HIGH);  
       }
    
}

void zero_cross_detect()
{
  zerocross=1;
}
 
void loop()
{  
  
 if (irrecv.decode(&results)) 
   {
    
     if(results.value==0xFF28D7)
     {
       Power=!Power;
       Delay=4;
     }
     else if(results.value==0xFF48B7)
     {
       if(Delay)
       Delay=Delay-1;
     }
     else if(results.value==0xFF609F)
     {
       if(Delay<8)
       Delay=Delay+1;
     }
       
     
       writeNumber(8-Delay);
       irrecv.resume(); 
 }
   
if(Power)
   if(zerocross) 
   {
      if(Delay)
            delayMicroseconds((Delay-1)*550+1); 
       
       digitalWrite(AC_pin, HIGH);
       delayMicroseconds(50);
       zerocross=0;
    }
if (Delay)
digitalWrite(AC_pin, LOW);


}
void writeNumber(int number) 
{
   if(!Power )
      for(int i = 3; i <= 9; i++)
           digitalWrite(i,HIGH);
      
  else  { 
    byte mask = numbers[number];
    byte currentPinMask = B1000000;
    for(int i = 3; i <= 9; i++) {
    if(mask & currentPinMask) 
    digitalWrite(i,LOW); 
    else digitalWrite(i,HIGH);
    currentPinMask = currentPinMask >> 1;
        }
  
      }

}

Replies

R Avinash
2016-08-26 12:19:58
what you are telling is NOT clear!

You said "i bought your kit and made it successfully using aurdino..."

which KIT did you brought? What is your order ID?

Post a reply to ASHISH NATH

Think you can help ASHISH NATH ? Then post your thoughts that might help ASHISH NATH. You will earn a lot of reputation in the technical community.

If your program is in multiple files, then ZIP the entire folder and attach below

Images and Screenshots

These helps other better understand your suggestion.