1

Servo keeps jittering at start up, buttons only reset to initial position being held, if let goes back to jittering. There is a line of code as well for an osciloscope but im not using it if you can please point it out, also this is the original website and functioning, the tinkercad simulation works like intended, but on my arduino keeps jittering https://www.tinkercad.com/things/3jdNc6hhgZl-arduino-servo-wo-servo-lib

Edit: I've checked that on the simulation it also jitters..

const unsigned int _PERIOD_US = 2200;
const unsigned int _0_DEG_US = 500;   
const unsigned int _90_DEG_US = 1500;
const unsigned int _180_DEG_US = 2500;

unsigned int us_elapsed = 0;
unsigned int duty_us = _90_DEG_US;
unsigned int aux = 0;

void setup()
{
  pinMode(8, OUTPUT);
  pinMode(4, INPUT);
  pinMode(3, INPUT);
  pinMode(2, INPUT);
  digitalWrite(8, LOW);
}

void loop()
{
  if (digitalRead(4) == LOW) {
  duty_us = _0_DEG_US;
}

  if (digitalRead(3) == LOW) {
  duty_us = _90_DEG_US;
}

  if (digitalRead(2) == LOW) {
  duty_us = _180_DEG_US;
}

  aux = micros() - us_elapsed;  

  if (aux >= duty_us) {
  digitalWrite(8, LOW);
} 
  if (aux >= _PERIOD_US) {
  digitalWrite(8, HIGH);
  us_elapsed = micros();
 }
}
Juraj
  • 3,490
  • 4
  • 18
  • 25

0 Answers0