//this one dims and brightens the LED //This is meant to run on an ATMEL ATMega328 //I think these are libraries to include #include #include //these are functions you'll call later #define output(directions,pin) (directions |= pin) // set port direction for output #define input(directions,pin) (directions &= (~pin)) // set port direction for input #define set(port,pin) (port |= pin) // set port pin #define clear(port,pin) (port &= (~pin)) // clear port pin #define pin_test(pins,pin) (pins & pin) // test for port pin #define bit_test(byte,bit) (byte & (1 << bit)) // test for bit set //these depend on how you set up the board //inputs = buttons #define button_port PORTC #define button_direction DDRC //do I need this? #define button1 (1 << PC0) #define button2 (1 << PC1) #define button3 (1 << PC2) #define input_pins PINC //All my inputs are in C because I am just such a thoughtful circuit designer //outputs = rgb led #define led_port PORTB #define led_direction DDRB #define red (1 << PB0) #define green (1 << PB1) #define blue (1 << PB2) #define led (green | red | blue) //it's all of them //these are some helpful values you'll want later #define led_delay() _delay_ms(100) // LED delay #define PWM_delay() _delay_us(10) // PWM delay int main (void){ //this is the main function - i.e. what runs all the time // set clock divider to /1 // I don't entirely understand this, I just know it's in all the programs CLKPR = (1 << CLKPCE); CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0); //first initialize the buttons clear(button_port, button1 | button2 | button3); input(button_direction, button1 | button2 | button3); //and initialize the LED clear(led_port, red | green | blue); // | is bitwise operation, || is logical OR output(led_direction, red | green | blue); set(led_port, red | green | blue); //now you want it listening for these buttons //the buttons are connected to ground on one end, and to the IC on the other end //so, you want the ports to listen for when they become ground, because it means the button is pressed set(button_port, button1 | button2 | button3); signed short int pwm_r, pwm_b, pwm_g,count,upper;//so it can hold more upper=350; //this controls how long it takes to dim pwm_r=upper; pwm_g=upper; pwm_b=upper; //clear(led_port,led);//turn them all on //_delay_ms(1000); //set(led_port,led); //_delay_ms(1000); while (1){ //meaning, all the time //in this case decrease the count when button is hit //otherwise let it increase up to upper-1 set(led_port,led); //turn them off for(count=1; count