0

The goal of the project is to display numbers from 0 to 9 using seven segment indicator, 74HC595 and pushing remote control buttons. It is assumed that brightness of the numbers that are displayed have to be changed by toggling OE pin to LOW and HIGH. I built the scheme physically. Numbers are displayed correct, but when I press "down" button offTime is changing to 51 (increasing HIGH level pulse length, but it means less brightness cause OE is inverted). After that program loops and Arduino doesn't respond. I assumed further brightness adjustment or starting to display other number in this time. The code is updated.

#include <IRremote.h>
int RECV_PIN = 12;
int data = 7;
int OE = 6;
int latch = 9;
int clock = 10;
//int reset = 11;

unsigned long offTime = 0;
boolean changed = false;
int input;

unsigned long debounce_delay = 2000;
unsigned long last_press = 0;
boolean flag = false;

const int button0 = 82;
const int button1 = 22; 
const int button2 = 25;
const int button3 = 13;
const int button4 = 12;
const int button5 = 24;
const int button6 = 94;
const int button7 = 8;
const int button8 = 28;
const int button9 = 90;
const int down = 21;
const int up = 70;


//1 - dp, 2 - e, 3 - d, 4 - c
//5 - g, 6 - f, 7 - a, 8 - b

void clearDisplay() {
  digitalWrite(latch, LOW);
  shiftOut(data, clock, LSBFIRST, 0b00000000);
  digitalWrite(latch, HIGH);
}

void print_0()
{
  //a,b,c,d,e,f = 1     g,dp = 0
  digitalWrite(latch, LOW);
  //digitalWrite(OE, LOW);
  shiftOut(data, clock, LSBFIRST, 0b01110111);
  digitalWrite(latch, HIGH);
}

void print_1()
{
  //b,c = 1     g,dp,a,e,f,d = 0
  digitalWrite(latch, LOW);
  //digitalWrite(OE, LOW);
  shiftOut(data, clock, LSBFIRST, 0b00010001);
  digitalWrite(latch, HIGH);
}

void setup()
{
  Serial.begin(9600);
  pinMode(RECV_PIN, INPUT);
  IrReceiver.begin(RECV_PIN, DISABLE_LED_FEEDBACK);
  pinMode(data, OUTPUT);
  pinMode(clock, OUTPUT);
  pinMode(latch, OUTPUT);
  pinMode(OE, OUTPUT);
  analogWrite(OE, 0);
  clearDisplay();
  //pinMode(OE, OUTPUT);
  //digitalWrite(OE, LOW);
  
  /*digitalWrite(latch, LOW);
  shiftOut(data, clock, LSBFIRST, 0b01110111);
  digitalWrite(latch, HIGH);*/

}
             
void loop() {
  if (IrReceiver.decode() && millis() - last_press > debounce_delay) {
    input = IrReceiver.decodedIRData.command;
    Serial.print("Received command: ");
    Serial.println(input);
    last_press = millis();
    switch (input) {
    case button0:
      print_0();
      break;
    case button1:
      print_1();
      break;
    case up:
      if (offTime >= 51) {
          offTime -= 51;
        } else {
          offTime = 0;
        }
      changed = true;
      break;
    case down:
      if (offTime <= 204) {
          offTime += 51;
        } else {
          offTime = 255;
        }
      changed = true;
      break;
    }
    if (changed) {
      Serial.print("Updating OE to: ");
      Serial.println(offTime);
      analogWrite(OE, offTime);
      changed = false;
    }
    IrReceiver.resume();
  }
}

enter image description here

12
  • 1
    start by writing simple code that turns on some segments and uses analog output to control the OE signal
    – jsotola
    Commented May 11 at 19:26
  • 1
    If you use analogWrite() to control the brightness of the display then you do not explicitly set an 'on' or an 'off' time. You are setting the duty cycle of pulse stream (980Hz on pin 6 on a Uno) where an analog value of 255 is 100% 'on', 127 is 50% 'on', 0 is 0% 'on' etc. Once analogWrite() has been called, the stream continues. As a test, delete everything in the loop(), write a '1' to the display in setup() then call analogWrite( OE, 24) . The 1 should be quite dim.
    – 6v6gt
    Commented May 12 at 2:49
  • 1
    @ArturKrush It could well be the simulator. Since you are using pin OE for analogWrite() you don't need the pinMode(OE, OUTPUT); and you can then replace digitalWrite(OE, LOW); with analogWrite(OE, 0); . To test if the simulator is capable of representing different brightness levels you could try connecting a led and 220R series resistor directly between pin 6 and ground to see what happens with different analog values .
    – 6v6gt
    Commented May 12 at 9:35
  • 1
    I've just seen from the data sheet that the output enable pin is actually /OE (that is NOT OE) so LOW is ON and HIGH is OFF. In other words, it is inverted. Try instead analogWrite( OE, 230). analogWrite(OE, 255) would then switch the display off. Anyway, I think it is safe to assume that it will work in real life.
    – 6v6gt
    Commented May 12 at 9:52
  • 1
    Can you share the link to your Wokwi simulation. It could be that the 74HC595 is not very well implemented regarding the behaviour of the OE pin or their seven segment displays (common cathode in your case) don't respond well to PWM.
    – 6v6gt
    Commented May 18 at 10:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.