Controlling brushless motor: compilation error "does not name a type"

Hi there,

I am trying to control a brushless motor with the arduino. The ESC instruction says that when connecting the motor to the power supply one should first put the control value to max (in my case: “speed=180”), wait until the motor makes a beep sound, then put it on the min value and again wait for the beep sound. If I am doing that outside the loop section, I am receiving the error below. If it is inside the loop section, the motor works. However I only want to put the motor on max at the very beginning of the program to initialize it and not over and over again…

#include <Servo.h>
Servo ESC;
int speed;

void setup() {
ESC.attach(9,1000,2000);
}

speed=180;
ESC.write(speed);
delay(3000);
speed=0;
ESC.write(speed);
delay(3000);

void loop() {
speed=50;
ESC.write(speed);
delay(3000);

}

Error says:
Arduino: 1.8.10 (Windows 10), Board: “Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)”

Brushless.lnk:9:1: error: ‘speed’ does not name a type

speed=180;

^~~~~

What is my mistake?
Many thanks for help in advance.

(deleted)

that’s what happens when green horns learn programming. it works now :slight_smile: thanks mate.