SHARE
TWEET

Untitled

a guest May 26th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * LED_fading_03.c
  3. * Controller: ATmega88 @ 8MHz
  4. */
  5. #include <avr/io.h>
  6. #include <util/delay.h>
  7. #include        // Einbinden der Headerdatei math.h für mathematische Funktionen
  8.  
  9. int main(void)
  10. {
  11.     DDRB |= (1<<PB1); // OC1A = output
  12.     ICR1 = 65535;       // ICR1 = Top Value
  13.      
  14.     // Mode 10: PWM, Phase Correct, Prescaler = 1, Clear OC1A on compare match
  15.     TCCR1A = (1 << COM1A1) + (1 << WGM11);
  16.     TCCR1B = (1 << WGM13) + (1 << CS10);
  17.      
  18.     while(1)
  19.     {
  20.         float result;                       // Datentyp float für Gleitkommaberechnungen
  21.         uint8_t basis = 80, steps = 72;     // Basiswert und steps ausprobieren
  22.          
  23.         for(uint8_t i=0; i<= 254; i++)
  24.         {
  25.             result = ((pow(basis,(float)i/100))/(basis-1))*steps;   // Typecast i
  26.             OCR1A = (uint16_t)result;       // Typecast result
  27.             _delay_ms(100);
  28.         }
  29.          
  30.         for(uint8_t i=255; i>= 1; i--)
  31.         {
  32.             result = ((pow(basis,(float)i/100))/(basis-1))*steps;   // Typecast i
  33.             OCR1A = (uint16_t)result;       // Typecast result
  34.             _delay_ms(100);
  35.         }
  36.     }
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top