I'm programming a stm32F103C6 with platformio
I'm being mad with this script.
i have setup 2 interrupt pins, one to rise the variable "start" value and one to decrease it.
then the a pwm pin will be set with the "start" value.
The problem rise when I change the logic from RAISING to FALLING.
because the Interrupt don't trigger only when the pin change state from HIGH to LOW , but also from LOW to HIGH
in fact the result are the same as CHANGE
anyone excepted the same behaviour?
here my code
Code: Select all
#include <Arduino.h>
#define PWM PA6 //T3
#define INDIETRO PB10 //T4
#define AVANTI PB9 //T2 sono stati invertiti
#define period 1000
int start = 0;
unsigned long tempo = 0;
void newstep (){
start++;
}
void newstep_i (){
start--;
}
void setup() {
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(AVANTI),newstep,FALLING);
attachInterrupt(digitalPinToInterrupt(INDIETRO),newstep_i,FALLING);
pinMode(PWM,OUTPUT);
digitalWrite(PWM, LOW);
pinMode(AVANTI,INPUT_PULLUP);
pinMode(INDIETRO,INPUT_PULLUP);
Serial.println("Ready 1.1.4");
}
void loop() {
if (start > 255 )start = 255;
else if (start < 0) start = 0;
analogWrite(PWM, start);
if (millis()>= tempo + period){
tempo += period;
Serial.println(start);
}
}