How to control pwm with switches

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all. I'm still noob in the c programming and would like to ask how to control the pwm with the switches on the board using atmega88. For now, i managed to fade the RGB led using 3 different pwm. I want to control the colour and to control also the speed of the led. Can you give me the ideas how i want to do this?

My current code is like this:


//----------------------------------
#ifndef F_CPU									//If Crystal-Frequency not defined then:
#define F_CPU 18432000UL 						//define Crystal-Frequency
#endif											//end of if-case
//----------------------------------

//---Header Files-------------------
#include 								//header-file for I/O configurations
#include 						//header-fatei for global interrupt activation (bspw. sei() und cli())
#include 								//header-file to define datatypes (int, char, unsigned char usw.)
#include 							//header-file to define bool
//----------------------------------

enum { UP, DOWN }; 

volatile unsigned int i =0; 
volatile unsigned int delay = 5; 
volatile unsigned int pwm; 
volatile unsigned int direction; 

void Stellfunktion(void); // for the switches

#define RED DDRD |= (1 << 6);   //PD6 =  output LED 
#define BLUE DDRB |= (1 << 1);   			//PB1 =  output LED
#define GREEN DDRB |= (1 << 3);   		//PB3 =  output LED 	

// ========================
// Mainprogramm 
// ========================

int main(void) 

{
	RED;
    	GREEN; 
  	BLUE;
	
   timer0();
   timer1();
   timer2();
   sei(); 
   while(1) {
	_delay_ms (1000);
  	Stellfunktion();
	
        _delay_ms (1000); 
	    
   }        
}


ISR (TIMER0_OVF_vect){ 


   for (i=0;i

Any help will be appreciated :D