int text_ok=0;
float delayTime=1;
//POV clock variables
unsigned long currentMillis, elapsed_loop_counter, previousMillis;
unsigned long counter_1, current_count;
//Interruption varaibles to count rotation speed
//We create 4 variables to store the previous value of the input signal (if LOW or HIGH)
byte last_IN_state; //Here we store the previous state on digital pin 13
float one_rot_time=0; //Here we store the full rotation time
float time_per_deg=0; //Here we store the time it takes to make one degree rotation
void setup() {
// put your setup code here, to run once:
PCICR |= (1 << PCIE0); //enable PCMSK0 scan
PCMSK0 |= (1 << PCINT4); //Enable pin state interruption on pin PB4 10 de la placa
//Output pins register configuration
DDRD |= B11111100; //2 to 7 as output
DDRB |= B00011111; //8 to 12 as output
DDRB &= B11011111; //13 input
PORTD &= B00000011; //2 to 7 LOW
PORTB &= B00000000; //8 to 13 LOW
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("1");
}
ISR(PCINT0_vect){ // s’activa amb la interrupció del HALL ISR (PCINT0_vect) para grupo de pines D8 a D13, quan s’aclari el tipo de PIN passar al mio
//First we take the current count value in micro seconds using the micros() function
current_count = micros();
///////////////////////////////////////Channel 1
if(PINB & B00100000){ //We make an AND with the pin state register, We verify if pin 8 is HIGH, PINB suposo es la intruccion per lleguir el registre DDRB, i se pasa pel IF si ha cambiado de estado
if(last_IN_state == 0){ //If the last state was 0, then we have a state change...
last_IN_state = 1; //Store the current state into the last state for the next loop
counter_1 = current_count; //Set counter_1 to current value.
}
}
else if(last_IN_state == 1){ //If pin 8 is LOW and the last state was HIGH then we have a state change
last_IN_state = 0; //Store the current state into the last state for the next loop
one_rot_time = current_count - counter_1; //We make the time difference. Channel 1 is current_time - timer_1.
time_per_deg = one_rot_time/360.0;
previousMillis = micros();
text_ok=1;
}
Serial.println("dins interrupcio");
}