On declared variables IDE say not bug.

void atm12864::line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t p = 1){
  char Dx = x2 - x1; 
  char Dy = y2 - y1;
  if(abs(Dx) >= abs(Dy)){
    char xStep = 1;
    float yStep = Dy / Dx;
    Dy = abs(Dx);
  }else{
    char yStep = 1;
    float xStep = Dx / Dy;
    Dy = abs(Dy);
  }
  for(Dx=0;Dx<=Dy;Dx++){
    point(round(x1+xStep),round(y1+yStep),p);
  }
}

Why Arduino IDE say not declared xStep ? xStep and yStep was declared. If and else is in full range <, > and = …

exit status 1
'xStep' was not declared in this scope

http://en.cppreference.com/w/cpp/language/scope

You can't have the same name and a different type for xStep and yStep.

Also, I'm pretty sure you mean int8_t, not char.

Pieter

Yeah, but not in the scope you try to use them :wink:

if(abs(Dx) >= abs(Dy)){
    char xStep = 1;
    float yStep = Dy / Dx;
    Dy = abs(Dx);
  }

After the } all all variables declared after the { are gone. That's called variable scope.

It looks like you are trying to rasterize a line.

There's absolutely no need to reinvent the wheel. It has been done many times before. Research the Bresenham line algorithm, for instance.
Or look at this implementation by Adafruit:

PieterP:
It looks like you are trying to rasterize a line.

There's absolutely no need to reinvent the wheel. It has been done many times before. Research the Bresenham line algorithm, for instance.
Or look at this implementation by Adafruit:
https://github.com/adafruit/Adafruit-GFX-Library/blob/master/Adafruit_GFX.cpp#L87-L126

But where is the fun in that? :smiley:

sterretje:
But where is the fun in that? :smiley:

Fair enough, that was a bit hypocritical of me to say :slight_smile: I've reinvented a lot of wheels too ... many turned out to be square ones though :smiley:

Thanks that all. Functions is done and work.

void atm12864::line(int8_t x1, int8_t y1, int8_t x2, int8_t y2, uint8_t p = 1){
  int8_t Dx = x2 - x1;
  int8_t Dy = y2 - y1;
  float xStep;
  float yStep;
  if(Dx == 0 && Dy == 0){
    point(x1,y1,p);
  }else{
    if(abs(Dx) >= abs(Dy)){
      if(Dx > 0){
        xStep = 1.0;
      }else{
        xStep = -1.0;
      }
      yStep = float(Dy) / abs(Dx);
      Dy = abs(Dx);
    }else{
      if(Dy > 0){
        yStep = 1.0;
      }else{
        yStep = -1.0;
      }
      xStep = float(Dx) / abs(Dy);
      Dy = abs(Dy);
    }
    for(Dx=0;true;Dx++){
      point(round(x1+Dx*xStep),round(y1+Dx*yStep),p);
      if(Dx == 127){
        break;
      }
    }
  }
}

Keep in mind that floating point numbers are pretty slow on an arduino, and they take up twice or even four times more memory.

Take a look at the link I posted for some inspiration, the entire graphics library doesn't contain a single float, not even for drawing circles etc.

Yes. Float is 4bytes and slow. Ok i try different alogorithm in optimalization steps making SW.