//#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
//#include <avr/sleep.h>
//#include <avr/wdt.h>
//#include <TinyDebug.h>
volatile boolean guzik=false;
volatile int licznik=1;
volatile boolean kierunek=false;
ISR (PCINT0_vect){
// cli();
static unsigned long last_interupt=0;
unsigned long interrupt_time = millis();
//Debug.print(F("milis = "));
// Debug.println(interrupt_time);
// Debug.print(F("last = "));
//Debug.println(last_interupt);
if(interrupt_time-last_interupt>100){
guzik = !guzik;
licznik++;
if(licznik%2==0){
kierunek= !kierunek;
}
} else {
//guzik=false;
}
last_interupt=interrupt_time;
//digitalWrite(PB0, LOW);
//Debug.print(F("Pressed! "));
//Debug.println(licznik);
// Debug.println(guzik);
//Debug.println(guzik);
//sei();
}
void myconfigure() {
cli();
// Debug.begin();
// Debug.println(F("Hello, TinyDebug!"));
TCCR0A=0x00; //Normal mode
TCCR0B=0x00;
TCCR0B |= (1 << CS01);
//TCCR0B |= (1<<CS00); //prescaling with 1024
TIMSK |= (1 << TOIE0);
TCNT0=0;
GIMSK |= (1<<PCIE);
PCMSK|=(1<<PCINT0);
//MCUCR |= (1<<ISC01)|(1<<ISC00);
DDRB |= (1 << PB1)|(1<<PB4);
DDRB &= ~(1 << PB0);
//TIMSK |= (1<<TOIE0);
// put your setup code here, to run once:
//pinMode(PB1, INPUT_PULLUP);
// attachInterrupt(PB0,przerwanie, FALLING);
//pinMode(PB0, OUTPUT);
sei();
}
int main() {
// Debug.begin();
// Debug.println(F("Hello, TinyDebug!"));
// DDRB |= (1 << PB1);
// DDRB &= ~(1 << PB0);
// GIMSK |= (1<<PCIE);
// PCMSK|=(1<<PCINT0);
myconfigure();
while(1){
//delayMicroseconds(100);
if(digitalRead(PB0)==LOW){
//if(guzik){
if(kierunek){
PORTB |= (1<<PB1);
PORTB &= ~(1<<PB4);
kierunek =1;
}
else{
PORTB &= ~(1<<PB1);
PORTB |= (1<<PB4);
kierunek =0;
}
}
else {
PORTB &= ~(1<<PB1);
PORTB &= ~(1<<PB4);
//guzik=false;
}
}
}