Hello!
How do I make the display to decrease properly? incrementing this working, but when it will show negative numbers it does not show correctly, follow my code:
include <TM74HC595Display.h>
#include <TimerOne.h>
int INTERRUPCAO = 2; // Pino de interrupção.
const int DIRECAO = 4; // Pino para determinar o sentido.
//Pinos de Conexao ao modulo
int PinoSCLK = 7;
int PinoRCLK = 6;
int PinoDIO = 5;
int pos = 0; // variavel
TM74HC595Display disp(PinoSCLK, PinoRCLK, PinoDIO);
unsigned char LED_OF[10];
void setup() {
// Definição dos digitos de 0 a 9
LED_OF[0] = 0xC0; //0
LED_OF[1] = 0xF9; //1
LED_OF[2] = 0xA4; //2
LED_OF[3] = 0xB0; //3
LED_OF[4] = 0x99; //4
LED_OF[5] = 0x92; //5
LED_OF[6] = 0x82; //6
LED_OF[7] = 0xF8; //7
LED_OF[8] = 0x80; //8
LED_OF[9] = 0x90; //9
Timer1.initialize (1500);
Timer1.attachInterrupt (timerIsr);
pinMode (INTERRUPCAO, INPUT_PULLUP); //Pino de interrupção como entrada.
attachInterrupt(digitalPinToInterrupt(INTERRUPCAO), comp, RISING); // Chama interrupção em LOW para HIGH
Serial.begin(9600);
}
void comp() {
if(digitalRead(DIRECAO) == HIGH)
pos++;
else
pos--;
}
void loop() {
disp.clear();
Serial.println(pos, DEC);
disp.digit4(pos, DEC);
Serial.println(pos);
delay(500);
}
void timerIsr(){
disp.timerIsr();