Module 74HC595 - Negative numbers

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();

It looks like not all your code has been copied. Please also use code tags around your code so that it does not get corrupted by the forum post management software.

In any event, if you are relying on the TM74HC595Display library to show your number, what does the library do when you pass it a negative number? You will need to look at the header file and the library code file.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.