AC dimmer

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Hi all,

Please help me. I am trying to create an AC dimmer controlled with remote. I  have done it. But the problem is, I want to add two push button to increase and decrease the speed.

 

void main()
{

    uint8_t rcmd; //Command from remote

    Initialize();

    while(1)
    {

        rcmd=GetRemoteCmd(1);

        //Seed Up
        if(rcmd==RV_UP)  // Here I want to add a button (in-case lost or malfunction of remote)
        {
            if(speed<9)
                speed++;

        }

        //Speed Down
        if(rcmd==RV_DOWN)  // Here I want to add a button (in-case lost or malfunction of remote)
        {
            if(speed>0)
                speed--;
        }

        //Turn ON/OFF
        if(rcmd==RV_ON)
        {
            if(fan_on)
            {
                POWER_LED_OFF();
                fan_on=0;    //Turn Off
            }
            else
            {
                POWER_LED_ON();
                fan_on=1;    //Turn On
            }
        }

        Display(speed);

    }
}

 

Last Edited: Sun. Sep 24, 2017 - 06:13 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It is an ATmega8 based dimmer. crystal Oscillator is 16MHz. Please help me.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

you need to add two pushbuttons then debounce them. Do a bit of Googling.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have tried more, but no success. would u help me?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Nahidulalam wrote:

I have tried more, but no success. would u help me?

 

Show what you tried.

 

You need to read a button, debounce it, adjust the speed, and do this at some reasonable rate (just sitting in a while(1) loop could zoom the speed down to 0 or up to MAX in a single button push unless you regulate how often you respond to the buttons).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kk6gm wrote:
Show what you tried.

 

Sir, I have added those line but what was the mistake.

#define BUTIN() (PIND & 0x01)==0;
char but;
char butl;
char butos;


void main()
{
but=BUTIN();
butos=but && !butl;
butl=but;

    uint8_t rcmd; //Command from remote

    Initialize();

    while(1)
    {

        rcmd=GetRemoteCmd(1);

        //Seed Up
        if((rcmd==RV_UP)||(butos))  
        {
            if(speed<9)
                speed++;

        }

        //Speed Down
        if(rcmd==RV_DOWN)  
        {
            if(speed>0)
                speed--;
        }

        //Turn ON/OFF
        if(rcmd==RV_ON)
        {
            if(fan_on)
            {
                POWER_LED_OFF();
                fan_on=0;    //Turn Off
            }
            else
            {
                POWER_LED_ON();
                fan_on=1;    //Turn On
            }
        }

        Display(speed);

    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also tried

  DDRB &= ~(1<<PINB2);// Input
  PORTB |= 1<<PINB2;  // PIN High
  
  
		if(bit_is_clear(PINB, 2))
		{
			if(speed<9)
				{
				speed = speed + 1;
				}

		}
 

but still failure.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also tried

  DDRB &= ~(1<<PINB2);// Input
  PORTB |= 1<<PINB2;  // PIN High
  
  
		if(bit_is_clear(PINB, 2))
		{
			if(speed<9)
				{
				speed = speed + 1;
				}

		}
 

but still failure.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

How exactly does it fail?

 

Can you write a program that just turns on an LED when you push your button?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sir,

thanks for ur reply.

#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
  DDRC |= 1<<PINC4; //Output
  DDRC &= ~(1<<PINC5);// Input
  PORTC |= 1<<PINC5;  // PIN High

  while(1) //infinite loop
  {

    if(bit_is_clear(PINC, 5)) //If switch is pressed
    {
      PORTC |= 1<<PINC4;
	  _delay_ms(100); 
    }
	else
	{
	PORTC &= ~(1<<PINC4);;
	      _delay_ms(100); 
}
  }
}

I have tried it.

Last Edited: Mon. Sep 25, 2017 - 03:48 PM