0.56" 7 segment LED HT15K33 allocation

Complete newbie here!

I am trying to allocate different digits on my seven segment display to pair (feet) and (Inches) with my ultrasonic sensor. Basically what I am trying to do here is to use the 0x00 and 0x00 for feet and 0x05 and 0x06 for my inches. For some reasons it seems like the way I am coding everything does not work out. Any clues?

Thanks a lot!

#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"





Adafruit_7segment matrix = Adafruit_7segment();
uint8_t counter = 0;

void setup() {
  
  
  #ifndef __AVR_ATtiny85__
  Serial.begin(9600);
  
    
  Serial.println("V1.08");
#endif


  matrix.begin(0x70);
   
   
  
  matrix.print(1.08);
  matrix.writeDisplay();
  delay(2000);
  
   matrix.clear();
   
  
  
  
  
  
  int n = 1;
 
int trig = 3; // attach pin 3 to Trig
int echo = 4; //attach pin 4 to Echo



}

void loop() {
  
   const int trigPin = 3;
  const int echoPin = 4;
  
 
  
   // establish variables for duration of the ping, 
  // and the distance result in inches and centimeters:
  long duration, inches, cm, feet, boolinches;
 
  // The sensor is triggered by a HIGH pulse of 10 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(trigPin, OUTPUT);
  digitalWrite(trigPin, LOW);
  delayMicroseconds(25);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(25);
  digitalWrite(trigPin, LOW);
  
 
  // Read the signal from the sensor: a HIGH pulse whose
  // duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);
 
  // convert the time into a distance
  boolinches = microsecondsToBoolinches(duration);
  cm = microsecondsToCentimeters(duration);
  inches = microsecondsToInches(duration);
  feet = microsecondsToFeet(duration);
  
  
 //write distance   
      if (feet >= 20)
        matrix.writeDigitNum(0x00, 9999); 
        
   
        
      else 
      {
       matrix.writeDigitNum(0x00,feet);
       matrix.writeDisplay();
        matrix.writeDigitNum(0x05,boolinches);
         matrix.writeDisplay();
       delay(10);
    
        
         }
         
          if (feet >= 20)
          Serial.print("OVER DISTANCE");
        
   
        
      else 
      {
        Serial.print(feet);
        Serial.print("'");
        Serial.print(boolinches);
        Serial.print(" '' "); 
        Serial.println("");
        
         }
        
          matrix.clear();


 
}

long microsecondsToInches(long microseconds)
{
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 73.746 / 2;
}
 
 
 long microsecondsToBoolinches(long microseconds)
{
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
   return ((((microseconds / 29 / 2)*50)/127)%12);;
}
long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}
long microsecondsToFeet(long microseconds)
{
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 884.952 / 2;
}

Hi, Can you post a link to the display please? What model Arduino are you using?

Thnaks, Tom... :)

TomGeorge: Hi, Can you post a link to the display please? What model Arduino are you using?

Thnaks, Tom... :)

I am using an V0.3 arduino Nano with this display https://www.adafruit.com/products/879

Thank you!

Hi Chuck,

a couple months ago, I wrote a demo to write minutes to the first two digits of that display*, and seconds to the last two, and count down an hour. Perhaps this will help:

/***********************************************
* Count down using millis()
*
* Adafruit 7-segment, I2C, LED backpack display
*
* On a UNO:
*   pin SCL -> C (on 7-segment)
*   pin SDA -> D (on 7-segment)
*   pin 9 - button - GND
*
* 021216 clh 3042/263 for tiny85
* 042516 clh 3254/261 for uno
*
************************************************/

#include "Wire.h"
#include "Adafruit_GFX.h"
#include "Adafruit_LEDBackpack.h"
Adafruit_7segment matrix = Adafruit_7segment();

unsigned long previousSecondMillis = 0UL;
const long oneSecond = 1000L; // "milliseconds" per second

#define startMinute 59  // Modify these defines to
#define startSecond 59  // change the timer interval

int minutes = startMinute;
int seconds = startSecond;

#define button 9

boolean isCountingDown = true;

void setup()
{
  matrix.begin(0x72);
  pinMode(button, INPUT_PULLUP);
}

void loop() {

  // --------- Run this every second ------------------
  if (millis() - previousSecondMillis >= oneSecond) {
    previousSecondMillis += oneSecond;

    matrix.writeDigitNum(0, (minutes / 10));
    matrix.writeDigitNum(1, (minutes % 10));
    matrix.writeDigitNum(3, (seconds / 10));
    matrix.writeDigitNum(4, (seconds % 10));
    matrix.writeDisplay();

    isCountingDown = !digitalRead(button);

    if (isCountingDown) decrementCount();

  }
}

void decrementCount() {
  if (seconds-- == 0) {
    if (minutes == 0) {
      minutes = startMinute;
      seconds = startSecond;
      delay(1234);
    } else {
      minutes--;
      seconds = 59;
    }
  }
}
  • this module, right:

thank you I will study your code :)

chuckauger: thank you I will study your code :)

The important part is where it writes the numbers to the LED matrix:

...
    matrix.writeDigitNum(0, (minutes / 10)); // 0 is the left-most digit
    matrix.writeDigitNum(1, (minutes % 10)); // 1 is second from left ... 2 is the colon - not used
    matrix.writeDigitNum(3, (seconds / 10));  // 3 is the second from right
    matrix.writeDigitNum(4, (seconds % 10));  // 4 is the right-most digit
    matrix.writeDisplay();
...

Are you trying to mimic the symbols ' and " ?

aarg: Are you trying to mimic the symbols ' and " ?

I don't follow you.

ChrisTenone: I don't follow you.

Sorry, the question was for the OP. Because of typos, it was a bit of guesswork to know what they really want. What I am referring to is symbol spoofing on a 7 segment display:

  0b00100010, // (34)  "
  0b00000010, // (39)  '

oic

aarg: Sorry, the question was for the OP. Because of typos, it was a bit of guesswork to know what they really want. What I am referring to is symbol spoofing on a 7 segment display:

  0b00100010, // (34)    "
  0b00000010, // (39)  '

What I am trying to achieve is to basically set the first and second digit for the feet and the third and fourth digit for the inches so for exemple for 3'2" i would get something like: 03'02" on my seven segment display, for 10'11' I would get the same result on my seven segment and so on...

I don't really care about showing the " and ' symbols my main objective right now is to place the numbers at the right place which I am not able to do for some strange reasons...

Found the problem. Thanks a lot for your help everyone!

  sevseg.writeDigitNum(0, (feet/10));
  sevseg.writeDigitNum(1, (feet % 10));
  sevseg.writeDigitNum(3, (boolinches/10));
  sevseg.writeDigitNum(4, (boolinches % 10));
  sevseg.writeDisplay();
  delay(100);

chuckauger: Found the problem. Thanks a lot for your help everyone!

  sevseg.writeDigitNum(0, (feet/10));
  sevseg.writeDigitNum(1, (feet % 10));
  sevseg.writeDigitNum(3, (boolinches/10));
  sevseg.writeDigitNum(4, (boolinches % 10));
  sevseg.writeDisplay();
  delay(100);

Yay!