this is my code for controlling a servomotor by Arduino Mega 2560
#include <Servo.h>
Servo servo_test;
int angle = 0;
void setup()
{
servo_test.attach(9);
}
void loop()
{
for(angle = 0; angle < 180; angle += 1)
{
servo_test.write(90);
delay(15);
}
delay(1000);
for(angle = 180; angle>=1; angle-=5)
{
servo_test.write(90);
delay(5);
}
delay(1000);
}
and the error message I got was =>
Arduino: 1.8.1 (Windows 8.1), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
Sketch uses 3108 bytes (1%) of program storage space. Maximum is 253952 bytes.
Global variables use 167 bytes (2%) of dynamic memory, leaving 8025 bytes for local variables. Maximum is 8192 bytes.
avrdude: ser_open(): can't open device "\.\COM1": The system cannot find the file specified.
avrdude: ser_drain(): read error: The handle is invalid.
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.
the selected serial port avrdude: stk500_send(): failed to send command to serial port
does not exist or your board is not connected
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: ser_send(): write error: sorry no info avail
avrdude: stk500_send(): failed to send command to serial port
avrdude: ser_recv(): read error: The handle is invalid.
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer