I'm trying to plot the value of the pwm that increases (every 2 sec) then decreases to compare it to the value of an encoder. I was expecting a continued value (like a step ) during 2 seconds but instead I have a triangle signal. Here is my code
const int pwmG = 2;
const int DirG = 8 ;
int a =0;
#define encoder1_CHA 18 //Left encoder
#define pin_channelB_left 6
int b =0;
void setup() {
Serial.begin(9600);
pinMode(pwmG,OUTPUT) ;
pinMode(DirG,OUTPUT) ;
attachInterrupt(digitalPinToInterrupt(encoder1_CHA),interruptUp,RISING);
}
void interruptUp(){
b = !b;
}
void loop() {
Serial.println(b);
//Serial.print(" ");
pwm();
//Serial.println(a);
//Serial.println(b);
}
void pwm(){
for (int i =0; i< 10; i++){
a = a +5;
analogWrite(pwmG, a);
Serial.println(a);
delay(200);
}
//Serial.println(b);
for (int i =0; i< 10; i++){
a = a -5;
analogWrite(pwmG, a);
Serial.println(a);
delay(200);
}
}
What I have :