segunda-feira, 25 de janeiro de 2021



Link2fs com Fsx, Display 8 digitos com 7 segmentos, enconder e botão







 


para baixar a biblioteca:

https://github.com/ozhantr/DigitLedDisplay


depois que baixar a biblioteca você vai colocar dentro da pasta de libraries do seu arduino

C:\Program Files (x86)\Arduino\libraries



#include "DigitLedDisplay.h"


#define DIN 8

#define CS 9

#define CLK 10 

#define DEBUG 0


DigitLedDisplay ld = DigitLedDisplay(DIN, CS, CLK);


unsigned long currentTime;

unsigned long lastTime;


unsigned long currentTime1;

unsigned long lastTime1;


const int pinA = 3;

const int pinB = 2;


const int pinC = 11;

const int pinD = 12;


boolean encA;

boolean encB;

boolean lastA = false;


boolean encC;

boolean encD;

boolean lastC = false;


int botao = 7;

int estado_do_botao = 0;

int valor_atual = 1;

  

void setup() { 

  

   pinMode(pinA, INPUT_PULLUP);

   pinMode(pinB, INPUT_PULLUP);

   

   pinMode(pinC, INPUT_PULLUP);

   pinMode(pinD, INPUT_PULLUP);

   

   pinMode(botao, INPUT_PULLUP);


   currentTime = millis();

   lastTime = currentTime;


   currentTime1 = millis();

   lastTime1 = currentTime1;

   

   ld.setBright(6);

   ld.setDigitLimit(8);

   

   Serial.begin(115200);

}

  

String leStringSerial(){

String conteudo = "";

char caractere;

  

  while(Serial.available() > 0) {

    caractere = Serial.read();

    if (caractere != '\n'){

      conteudo.concat(caractere);

    }

    delay(10);

  }

  ld.clear();

  //Serial.print("Recebi: ");

  conteudo.replace("b","");

  conteudo.replace("=","");

  Serial.println(conteudo.toInt());

  ld.printDigit(conteudo.toInt());

  

  return conteudo;

}

  

void loop() {

  if (Serial.available() > 0){

    String recebido = leStringSerial();

  }


   //-----------------------------------------------------

   currentTime = millis();

  if (currentTime >= (lastTime + 5))  {

    encA = digitalRead(pinA);

    encB = digitalRead(pinB);

       if ((!encA) && (lastA)) {

          if (encB){ Serial.println("B12");}else{Serial.println("B11");}

        }

   

    lastA = encA;

    lastTime = currentTime;

  } 

//-------------------------------------------------------


 

  currentTime1 = millis();

 if (currentTime1 >= (lastTime1 + 5))

  {

    

    encC = digitalRead(pinC);

    encD = digitalRead(pinD);

   

    if ((!encC) && (lastC)){

        if (encD){Serial.println("D080");}else{Serial.println("D090");}

    }

    

    lastC = encC;

    lastTime1 = currentTime1;

  }

//-------------------------------------------------------


 estado_do_botao = digitalRead(botao); //Armazena o Estado do botão.

            if ((estado_do_botao == LOW) && (valor_atual == 1))

                {

                    Serial.println("D070");  //d020 se refere ao pino 2 do arduino usado no link2fs

                    delay(200);

                    valor_atual = 0;

                    estado_do_botao = 1;

                }


            if ((estado_do_botao == LOW) && (valor_atual == 0))

                {

                    Serial.println("D070");

                    delay(200);

                    valor_atual = 1;

                    estado_do_botao = 0;

                }


}