Arduino Leonardo not seen by computer

Hi there!
I'm working on a robotic arm project, using a Leonardo.
However, while working with and uploading the code, the Leonardo somehow "blocked", and i got the error:

processing.app.debug.RunnerException: Couldn’t find a Leonardo on the selected port. Check that you have the correct port selected.  If it is correct, try pressing the board's reset button after initiating the upload.
	at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:152)
	at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:67)
	at processing.app.Sketch.upload(Sketch.java:1671)
	at processing.app.Sketch.exportApplet(Sketch.java:1627)
	at processing.app.Sketch.exportApplet(Sketch.java:1599)
	at processing.app.Editor$DefaultExportHandler.run(Editor.java:2380)
	at java.lang.Thread.run(Thread.java:680)

The leds on the board light up, but it is not seen by the computer, and in Tools > Serial Port there is no usb port option
My guess was that the bootloader was corrupted, so i bought another Leonardo, and used it as ArduinoISP to burn the bootloader to the old "corrupted" one. Didnt succeed there, unfortunately i dont have the error i got available.

The new Leonardo was of course working fine (uploaded examples like the Blink sketch - everything ok), until i uploaded my code and.......same results

Now both of my Leonardos are "stuck", and im not able to upload any sketch to them!

I also have had several tries with the parallel port programmer, no luck there either:

avrdude: verification error, first mismatch at byte 0x00000
         0x0c != 0xff
avrdude: verification error; content mismatch

The parallel programmer actually seems to have gotten things worse....when powering the arduino, i get rx and tx leds blinking REALLY fast, or tx constantly on (different behaviours after each try with the parallel programmer).

As this seems to have been caused by my code :fearful: , here is my program:
(i cant see anything that would cause this kind of behaviour, but anyway)

//ROBOTIC ARM
#include <MyServo.h>
#include <Servo.h>
#include <math.h>

int coordinate_x;
int coordinate_y;

int x;      //true length of arm
int y;
float x2;
float y2;

int baseRot;
int angle1;
int angle2;
int angle3;
int gripperRot;
int gripper;

//servos
MyServo servo2(10,   10, 130, 1000, 2000);         //one of the servos

//levers
const int lever1 = 10;        //cm
const int lever2 = 8;         //cm
const int lever3 = 6;         //cm

const double rad = 3.14159265358979323846 / 180;
const double deg = 180 / 3.14159265358979323846;	
float aux_line;                      //an imaginary line between joint 1 and joint 3
int angle3_toGround;             //the angle of the gripper to the ground
float aux_line_toGround;        //the angle between the imaginary line and the ground

boolean b = true;

void setup()
{
  Serial.begin(115200);
}

void loop()
{
  while(b)
  {
    Serial.println("Enter x coordinate:  ");
    while(!Serial.available())
    {
      delay(1);
    }
    coordinate_x = Serial.parseInt();
  
    Serial.println("Enter y coordinate:  ");
    while(!Serial.available())
    {
      delay(1);
    }
    coordinate_y = Serial.parseInt();
  
  
    baseRot = 57.32 * (atan2(coordinate_y, coordinate_x));
    
    ///////////////////////////////////////////
 
    x = sqrt(coordinate_x*coordinate_x + coordinate_y*coordinate_y);        //true length of arm
    y = 0;
  
    ///////////////////////////////////////////
  
    b = true;
    //try gripper to be as close to 90 degrees to ground as possible
    for(angle3_toGround = 90; angle3_toGround <= 180 && b == true; angle3_toGround++)
    {
      y2 = y + (sin(angle3_toGround * rad) * lever3);
      x2 = x + (cos(angle3_toGround * rad) * lever3);
      aux_line = sqrt(x2*x2 + y2*y2);
      aux_line_toGround = atan2(y2, x2) * deg;
      angle1 = (atan2(y2, x2) + acos((lever1*lever1 - lever2*lever2 + aux_line*aux_line) / (2 * lever1 * aux_line))) * deg;
      angle2 = (acos((lever1*lever1 + lever2*lever2 - aux_line*aux_line) / (2 * lever1 * lever2))) * deg;
      angle3 = (360 - (angle1 + angle2 + (180 - angle3_toGround)));
       
      if((aux_line <= lever1 + lever2) && servo2.check(angle1))
      { b = false; }                                  //make <for> and <while> loops exit 
    }
    


    if (b == true)        //if a solution hasnt been found
    {
      //there is no solution for these coordinates
      Serial.println("ERROR: These coordinates cannot be reached by the arm");
    }
  }
  //////////////////////////////////////////////////////////////////////////
  //print results
  Serial.print("Base Rotation: ");
  Serial.print(baseRot);
  Serial.print("\nx: ");
  Serial.print(x);
  Serial.print("\ny: ");
  Serial.print(y);
  Serial.print("\nx2: ");
  Serial.print(x2);
  Serial.print("\ny2: ");
  Serial.print(y2);
  Serial.print("\naux_line:  ");
  Serial.print(aux_line);
  Serial.print("\naux_line_toGround: ");
  Serial.print(aux_line_toGround);
  Serial.print("\nangle 1: ");
  Serial.print(angle1);
  Serial.print("\nangle 2: ");
  Serial.print(angle2);
  Serial.print("\nangle 3: ");
  Serial.print(angle3);
  Serial.print("\nangle 3 to ground: ");
  Serial.print(angle3_toGround);
  Serial.print("\n--------------------------\n");
  servo2.movement(angle1);                 //move one of the servos to its position
}

i also have made a class, called MyServo. Here is MyServo.cpp:

#include "Arduino.h"
#include "MyServo.h"
#include "Servo.h"

MyServo::MyServo(int pin, int minAngle, int maxAngle, int minValue, int maxValue)
{
  _minAngle = minAngle;
  _maxAngle = maxAngle;
  _minValue = minValue;
  _maxValue = maxValue;
  _pin = pin;
}

MyServo::~MyServo()
{
}

boolean MyServo::check(int Angle)
{
  if (Angle >= _minAngle && Angle <= _maxAngle)
  { return true; }
  else
  { return false; }
}

void MyServo::movement(int Angle)
{
  servo.attach(_pin);
  servo.writeMicroseconds(map(Angle, _minAngle, _maxAngle, _minValue, _maxValue));
  delay(500);
  servo.detach();
}

And here is MyServo.h:

#ifndef MyServo_h
#define MyServo_h

// the #include statement and code goes here...
#include "Arduino.h"
#include "Servo.h"

class MyServo
{
  public:
    ~MyServo();
    MyServo(int pin, int minAngle, int maxAngle, int minValue, int maxValue);
    boolean check(int Angle);
    void movement(int Angle);
  private:
    int _minAngle;
    int _maxAngle;
    int _minValue;
    int _maxValue;
    int _pin;
};

#endif

Restart each and everything

Cybernetician:
Restart each and everything

Thanks for the reply. Already did, also tried on several other machines

Hey, im suspicious of something....
My MacBook Pro is giving zaps (static discharges) when it is plugged to power.
Could this be the reason both leonardos are malfunctioning? Or worse, does that mean that they are fried?

Hey, im suspicious of something....

I would be, too.

My MacBook Pro is giving zaps (static discharges) when it is plugged to power.

That is not, as Martha Stewart is fond of saying, "a Good Thing".

Could this be the reason both leonardos are malfunctioning?

Yes.

Or worse, does that mean that they are fried?

I suspect that's WHY they are malfunctioning.

so static discharges can damage the arduino that much?
arduinos, R.I.P. then :~....

so static discharges can damage the arduino that much?

If you are feeling something from the Mac, it isn't a static discharge. You have a power supply problem. That can affect anything you are powering from it.

If you are feeling something from the Mac, it isn't a static discharge. You have a power supply problem. That can affect anything you are powering from it.

So this could not be the reason then.
But if it is not static discharges, what is it then???

Before you attach ANYTHING to that power supply, the Mac, another Arduino, anything, you should get it checked out. It IS most likely what toasted your Arduino. And, no, it ISN'T static electricity.

Before you attach ANYTHING to that power supply, the Mac, another Arduino, anything, you should get it checked out. It IS most likely what toasted your Arduino. And, no, it ISN'T static electricity.

Ok, there is nothing wrong with the power supply, this seems to be a common issue:
https://discussions.apple.com/thread/1008031?start=0&tstart=0

im using the us 3-prong AC cord attached to an american to european adapter, which is 2-prong...
i will get a european 3-prong one, the problem will probably go away...

But anyway, it's too late now. I guess i learned something more, the unpleasant way. Thanks for your help.