#include <avr/io.h>
#include <avr/interrupt.h>
volatile int x = 0;
volatile int button_status = 0;
void timer_setup()
{
cli();
TCCR1A = 0x00;
TCCR1B = 0x00;
TCCR1B |= (1<<0)|(1<<2)|(1<<3); //CTC Modus, Prescaler 1024
TIMSK1 |= (1<<1); //Timer aktivieren
OCR1A = 15625; //Schnelligkeit auf 1 Sekunde einstellen
//PWM
TCCR0A |= (1<<WGM00)|(1<<WGM01)|(1<<COM0B1); //fast PWM Modus
TCCR0B |= (1<<CS00)|(1<<CS02); //Prescaler(Vorteiler) 1024
sei();
}
void taster_setup()
{
Serial.begin(9600);
DDRD &= ~(1<<6);
}
void led_setup()
{
DDRD |= (1<<5);
}
void poti_setup()
{
DDRC &= ~(1<<5);
}
void pruefe_taster()
{
if((PIND &(1<<6)) == 64)
{
button_status = 1;
}
}
void ausgabe()
{
if(x == 4 && button_status == 1)
{
Serial.println("Button wurde gedrückt!");
button_status = 0;
x = 0;
}
else if(x == 4 && button_status == 0)
{
Serial.println("Der Button wurde nicht gedrückt!");
x = 0;
}
}
int main()
{
int wert = 0;
timer_setup();
taster_setup();
led_setup();
OCR0B = 1;
while(1)
{
pruefe_taster();
ausgabe();
}
return 0;
}
ISR(TIMER1_COMPA_vect)
{
x = x + 1;
}