Advertisement
Guest User

Untitled

a guest
Jun 20th, 2014
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | None | 0 0
  1. //MiniMo -- minimalistic driver firmware for momentary buttons (no blinkies)  --  DrJones 2014
  2. //Up&Down variant ("Werner's UI")
  3. #define F_CPU 4800000                    //use fuses  low:0x75  high:0xff
  4. #include <avr/io.h>
  5. #include <util/delay.h>
  6. //change modes here; just change/add/delete values. The "0" is 'off'
  7. uint8_t modes[]={0, 255};          //PWM values, 5..255 - LEAVE THE "0" THERE
  8. int main() {
  9.   DDRB=2; PORTB=8;                       //define PB1 as output and pull-up switch on PB3
  10.   TCCR0A=0b00100001; TCCR0B=0b00000001;  //PWM setup, 9kHz
  11.  
  12.  
  13.   //uint8_t count=0, lasmode=1, waspressed=0;
  14.   uint8_t mode=0 //define some variables used below
  15.  
  16.   while(1) {                             //endless loop
  17.  
  18.     if ((PINB&8)==0) {                   //when the button is pressed (PB3 pulled down)
  19.         mode=1;  //only one mode is needed, so if button is presses, use 100% mode
  20.  
  21.     else {  // if button is not pressed, just turn off the light  
  22.         mode=0;
  23.     }    
  24.  
  25.   OCR0B=modes[mode];                     //set PWM level (0 is off)
  26.   _delay_ms(25);                         //wait a bit before checking again, important for counting
  27.   }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement