7 segment display not obeying commands

I was trying to follow drone bot workshop's video on the 7 segment digit display. I used the ic and was trying to make "1" appear. Though when I made a binary data array for the characters 1,2,3,4,5,H,O the first two sets were making a weird shape. Here is the array:

int datArray [7] =(B01100000, B11011010);
digitalwrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, datArray[num]);
 digitalWrite(latchPin, HIGH);

do you know what is wrong?

The code you posted is incomplete.
I'm surprised you didn't notice this.

Why have a seven element array 5/7ths full of zeroes?

You should make your datArray a byte array rather than int otherwise you are just wasting memory since shiftOut expects a byte for the data.

Also...post your entire sketch!

Link please.

What IC?

That is most likely because your numbers in the array are wrong.

Shift registor: 74HC595
link: 74HC595 & 74HC165 Shift Registers with Arduino - YouTube

#include "dht.h"
#define dht_apin A0 // Analog Pin sensor is connected to
#define ElecPin A1 
dht DHT;
int num = 0;
int goPin = 2;
int noPin = 3;
int set_Temp = 28;
int toggleState = 0;
 const int latchPin = 10;
// SH_CP pin 11
const int clockPin = 11;
// DS pin 14
const int dataPin = 12;

byte datArray[9] = {B01100000, B11011010, B11110010, B01100110, B10110110, B01101110, B11111100};

void setup(){
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT); 
  pinMode(4, OUTPUT);
 pinMode(goPin, OUTPUT);
 pinMode(noPin, OUTPUT);
}//end "setup()"
void loop(){ 
  //Fastest should be once every two seconds.
}// end loop()

void AC_Norm(){
     float temp = DHT.temperature;    
    if(temp>18.00){ digitalWrite(goPin, HIGH);
      digitalWrite(noPin, LOW);
    else{if(temp<18.00){ digitalWrite(goPin, LOW);
      digitalWrite(noPin, HIGH);
    num = 1; 
    delay(5000);//Wait 5 seconds before accessing sensor again.
     digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, datArray[num+2]);
     digitalWrite(latchPin, HIGH);}

  //Start of Program 

Do you have a question?

Well in the array when I want the display to show 1, I choose B01100000 to do the job, but it makes a weird shape.

oops made a mistake.
this is what I mean
shiftOut(dataPin, clockPin, MSBFIRST, datArray[num]);

Would not "1" be B00000011? :worried:

Segment "a" is the LSB.

This is dronebot's code, did you try it before adding the DHT, to test your display?

  74HC595 Shift Register with 7-segment LED display
  Count in hex from 0-F and display on 7-segment Common Cathode LED display
  DroneBot Workshop 2020
// Define Connections to 74HC595
// ST_CP pin 12
const int latchPin = 10;
// SH_CP pin 11
const int clockPin = 11;
// DS pin 14
const int dataPin = 12;
// Patterns for characters 0,1,2,3,4,5,6,7,8,9,A,b,C,d,E,F
int datArray[16] = {B11111100, B01100000, B11011010, B11110010, B01100110, B10110110, B10111110, B11100000, B11111110, B11110110, B11101110, B00111110, B10011100, B01111010, B10011110, B10001110};
void setup ()
  // Setup pins as Outputs
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
void loop()
  // Count from 0 to 15
  for (int num = 0; num < 16; num++)
    // ST_CP LOW to keep LEDs from changing while reading serial data
    digitalWrite(latchPin, LOW);
    // Shift out the bits
    shiftOut(dataPin, clockPin, MSBFIRST, datArray[num]);
    // ST_CP HIGH change LEDs
    digitalWrite(latchPin, HIGH);

Get the test code working on your project before editing code.

What displays are you using?(part number)
Common anode or common cathode?

Tom... :smiley: :+1: :coffee: :australia:

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