You are reading a single comment by @NoobJS and its replies. Click here to read the full conversation.
  • Thank you so much for the advice. It's good to have a lively community.
    I have not yet figured out how to work with the buffer, and in general, I have huge problems understanding how binary code should work.
    For starters I just changed the font .as I was advised. The rendering speeded up many times over, but the numbers were less beautiful. So I made those readings that change very fast in one font, and those that change slowly in a pretty font.

    Readings of gear and acceleration (0-100km/h) will be calculated on the basis of speed and engine speed, because I do not want to install a sensor for gear selection.
    For clarity, I screwed setTimeout to the speedometer, so it was clear at what speed the readings change. In fact, the data on the speedometer meter will be different (not in increments of 1km/h).
    Not to run to the bike, I think to build an emulator for speedometer and tachometer.
    I will be glad to hear suggestions on code optimization. Is it possible to make "Vector" font to be displayed with the same speed.
    If you choose the color outside the body of the class, the code works, but if the method of the class (line 10 of code), then for some reason the color does not change

    https://youtu.be/O3ZKkRJ4A4Q

    A3.set(); // light on
     require("Font7x11Numeric7Seg").add(Graphics);
    
    SPI1.setup({sck:A5, miso:P2, mosi:P3, baud:10000000000000000});
    
    var g = require("ILI9341").connect(SPI1, A2, A0, A1, function() {
      g.clear();
      g.setRotation(1);
    
      g.drawLine(5, 171, 315, 172);
      g.drawLine(5, 75, 235, 75);
      g.drawLine(70, 36, 235, 36);
      g.drawLine(160, 175, 160, 235);
      g.drawRect(240, 0, 320, 140);
      g.drawRect(0, 0, 65, 71);
      g.fillRect(240, 123, 320, 143);
      g.fillRect(0, 60, 65, 71);
      g.fillRect(120, 175, 160, 195);
      g.fillRect(160, 215, 200, 235);
      g.fillRect(193, 15, 235, 35);
      g.fillRect(70, 36, 120, 56);
      g.setFontVector(21);
    
      g.setColor('#000000');
      g.setFontVector(19);
      g.drawString("GEAR",257,125);
      g.setFontVector(13);
      g.drawString("0-100",15,60);
      g.setFontVector(21);
      g.drawString("km",126,175);
      g.setFontVector(21);
      g.drawString("odo",165,215);
      g.setFontVector(21);
      g.drawString("rpm",195,14);
      g.setFontVector(21);
      g.drawString("temp",71,37);
    
      g.setColor('#ffffff');
      g.setFontVector(21);
      g.drawString("km/h",215,149);
      g.setFontVector(39);
      g.drawString("C",198,40);
    });
    setTimeout(()=>{
    
    let parameters ={
    speedometer:{
    x:140,
    y: 80,
    font:{name:"7x11Numeric7Seg",size:8,hight:88,color:'#ffffff'}
    },
    tachometer:{
    x:170,
    y:1,
    font:{name:"7x11Numeric7Seg",size:3,hight:33,color:'#ffffff'}
    },
    gear:{
    x:250,
    y:5,
    font:{name:"Vector",size:130,hight:60,color:'#00ff00'}
    },
    temperature:{
    x:170,
    y:40,
    font:{name:"Vector",size:39,hight:24,color:'#ffffff'}
    },
    odometer:{
    x:295,
    y:176,
    font:{name:"Vector",size:40,hight:20,color:'#ffffff'}
    },
    run:{
    x:100,
    y:200,
    font:{name:"Vector",size:40,hight:20,color:'#ffffff'}
    },
    acceleration:{
    x:25,
    y:20,
    font:{name:"Vector",size:30,hight:20,color:'#ffffff'}
    }
    };
    
      class Counter {
    constructor(value) {
    this.value = value;
    }
    
     countSym(number,param) {
    number = number.toString();
    let oneSym = {
    value: number.split("").reverse(),
    posX:  param.x,
    posY:  param.y,
    font:  param.font
    };
    this.value = oneSym;
    }
    
     renderNum (numForRender) {
       g.setColor(this.value.font.color);
       g.setFont(this.value.font.name,this.value.font.size);
    let number = numForRender.toString().split("").reverse();
    let step = g.stringWidth(number[0]);
    
    for(let i = 0; i<number.length; i++){
    if(number[i]!==this.value.value[i]){
      if(i===0){
    
      g.clearRect(this.value.posX,this.value.posY,this.value.posX + step,this.value.posY + this.value.font.hight);
      g.setColor(1,1,1);
    
      g.drawString(number[i], this.value.posX, this.value.posY);
    }else{
    
    g.clearRect(this.value.posX - i*step,this.value.posY,this.value.posX - (i===1?0:(i-1)*step),this.value.posY + this.value.font.hight);
      g.drawString(number[i], this.value.posX-step*i, this.value.posY);
    }
      }
    }
      this.value.value = number;
    }
    }
    
    let speedometer = new Counter(0);
    speedometer.countSym(1,parameters.speedometer);
    speedometer.renderNum(0);
    
    let tachometer = new Counter(0);
    tachometer.countSym(1,parameters.tachometer);
    tachometer.renderNum(12000);
    
    let gear = new Counter(0);
    gear.countSym(1,parameters.gear);
    gear.renderNum(6);
    
    let temperature = new Counter(0);
    temperature.countSym(1,parameters.temperature);
    temperature.renderNum(98);
    
    let odometer = new Counter(0);
    odometer.countSym(1,parameters.odometer);
    odometer.renderNum(1140);
    
    let run = new Counter(0);
    run.countSym(1,parameters.run);
    run.renderNum(42657);
    
    let acceleration = new Counter(0);
    acceleration.countSym(1,parameters.acceleration);
    acceleration.renderNum(3);
      
    for(let i = 0; i<=200; i++){
    speedometer.renderNum(i);
    
    }
    
    }, 500);
    
About

Avatar for NoobJS @NoobJS started