Code is not running, servo does not even spin I am trying to run a program which works as follows:
An LDR is integrated in a box. A block is placed on top. This box is able to be rotated by a servo. The program is supposed to make the box turn until the block slides and lifts off from the LDR.
At that point the servo angle is stored and used to calculate the friction coefficient. Finally the answer to this calculation is printed on an lcd and the program repeats by first returning the box to the original state. The entire programs runs on Arduino and an Arduino Lotus. Why doesn't the servo rotate?
//servo 
#include &lt;Servo.h&gt; 

Servo myservo; 
int previous_angle = 0; 
int angle = 0; 
    
//lightsensor 
int lightsensor = 0;     
int LIGHT = 800;     
int DARK = 940; 
              
//LED screen     
#include &lt;Adafruit_GFX.h&gt;     
#include &lt;Adafruit_SSD1306.h&gt; 
    
#define OLED_RESET 4     
Adafruit_SSD1306 display(OLED_RESET); 
              
void setup() {    
  Serial.begin(9600);     
  myservo.attach(6); 
            
  pinMode(lightsensor, INPUT);               

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); 
    
  delay(100);                 
} 
              
void loop() { 
  int i = previous_angle;     
  int lightStatus = analogRead(lightsensor); 
    
  if (lightStatus &gt;= DARK) {      
    delay(300); 

    while (int i = previous_angle) {
      i&lt;=90;
      i = i+1;
      myservo.write(i);     
      delay(45); 
    };      
  } else if (lightStatus &lt; DARK) {    
    for (int i = previous_angle; i&gt;0;) {     
      delay(300);     
      int angle = tan(i);         
      display.clearDisplay();     
      display.setTextSize(1.5);     
      display.setTextColor(WHITE);     
      display.setCursor(0,0);     
      display.println(angle);     
      display.display();     
      delay(300);  
              
      myservo.write(0);     
      delay(45);     
    };     
  }     
}
For starters: this bit is a strange mixture of for and while syntax:
while (int i = previous_angle) {
  i &lt;= 90; 
  i = i + 1; 
  myservo.write(i);
  delay(45); 
};  

It will compile, but probably not do what you want it to do. It should probably be:
for (int i=previous_angle; i&lt;=90; i=i+1) {
  myservo.write(i);
  delay(45); 
}

Also, previous_angle is never changed in your code after initialisation; it is always 0.
That also means that the for loop below will not do what you want (and that loop also doesn't increment i anywhere):
for (int i = previous_angle; i&gt;0;)

There may be more; make the suggested changes first and see what happens.