Skip to content

Instantly share code, notes, and snippets.

@avr-programmierung
Created May 16, 2019 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avr-programmierung/c7a7a7ee99f18a88eda2416612211987 to your computer and use it in GitHub Desktop.
Save avr-programmierung/c7a7a7ee99f18a88eda2416612211987 to your computer and use it in GitHub Desktop.
ATmega88 @ 8MHz LED fading 03
/*
* LED_fading_03.c
* Controller: ATmega88 @ 8MHz
*/
#include <avr/io.h>
#include <util/delay.h>
#include // Einbinden der Headerdatei math.h für mathematische Funktionen
int main(void)
{
DDRB |= (1<<PB1); // OC1A = output
ICR1 = 65535; // ICR1 = Top Value
// Mode 10: PWM, Phase Correct, Prescaler = 1, Clear OC1A on compare match
TCCR1A = (1 << COM1A1) + (1 << WGM11);
TCCR1B = (1 << WGM13) + (1 << CS10);
while(1)
{
float result; // Datentyp float für Gleitkommaberechnungen
uint8_t basis = 80, steps = 72; // Basiswert und steps ausprobieren
for(uint8_t i=0; i<= 254; i++)
{
result = ((pow(basis,(float)i/100))/(basis-1))*steps; // Typecast i
OCR1A = (uint16_t)result; // Typecast result
_delay_ms(100);
}
for(uint8_t i=255; i>= 1; i--)
{
result = ((pow(basis,(float)i/100))/(basis-1))*steps; // Typecast i
OCR1A = (uint16_t)result; // Typecast result
_delay_ms(100);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment