Go Down

Topic: 7 Segment Scrolling Text (Read 49 times) previous topic - next topic

evalonso

Sep 13, 2017, 11:06 pm Last Edit: Sep 13, 2017, 11:18 pm by evalonso Reason: Added photos of scrolling text; code;
Good afternoon! I am a long time reader of this community and a first time poster.

I have resurrected A project i started when i first began using an Arduino. I am trying to optimize my logic, however i am slightly stuck with trying to properly scroll text across 4 seven-segment displays (adafruit 7segment display). 5s example of operation shown here(photos also attached): https://youtu.be/vFIgaakMxRo

I am trying to implement a delay with the scroll in order to give the user time to read. The PCB has an "option" button to scroll through menus and a "Sync" button. The Sync Button synchronizes my circuit when pressed first, or is used as an "Enter" Button when the option menu is accessed (Option > 0);

I would like the text (SOLAR CURRENT) to begin scrolling when the 2nd option is selected. If the user hits "Sync/Enter" (before the text is finished scrolling), the text should disappear and the The current measurement from the solar cell will then be displayed (Option == 2 && Sync == 1).

Here is the relevant section of the old code (works):


Code: [Select]

#define S B01101101 // letter definitions for the 7 segment display;
#define O B00111111
#define L B00111000
#define A B01110111
#define R B00110001
#define BLANK B00000000
#define C B00111001
#define U B00111110
#define E B01111001
#define N B00110111
#define T B01111000 // "SOLAR CURRENT"

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

int k = 1;
int p = 0;

main{

     if(Option == 2){  //k is used to set the OptionCount once
    if(k == 1){
      OptionCount = millis();
      k++;

    }
    if(((millis() - OptionCount) > 5000) && (Sync == 0)){  //break if 5 sec passed w/o pressing enter
      Option = 0;
      k = 0;
    }
    if(((millis() - OptionCount) > 10000) && (Sync == 1)){ // If enter, show for 10s
      Option = 0;
      k = 0;
      Sync = 0;
    }
    if(((millis() - OptionCount) < 250) && (Option == 2) && (Sync == 0)){
      matrix.writeDigitRaw(0,S);
      matrix.writeDigitRaw(1,O);
      matrix.writeDigitRaw(3,L);
      matrix.writeDigitRaw(4,A);
      matrix.writeDisplay();
    }
        if(((millis() - OptionCount) > 500) && ((millis() - OptionCount) < 750) && (Option == 2) && (Sync == 0)){
      matrix.writeDigitRaw(0,O);
      matrix.writeDigitRaw(1,L);
      matrix.writeDigitRaw(3,A);
      matrix.writeDigitRaw(4,R);
      matrix.writeDisplay();
    }
        if(((millis() - OptionCount) > 750) && ((millis() - OptionCount) < 1000) && (Option == 2) && (Sync == 0)){
      matrix.writeDigitRaw(0,L);
      matrix.writeDigitRaw(1,A);
      matrix.writeDigitRaw(3,R);
      matrix.writeDigitRaw(4,BLANK);
      matrix.writeDisplay();
    }
      
.
..
...
....
.....
......
.......
........

        if(((millis() - OptionCount) > 2750) && ((millis() - OptionCount) < 3000) && (Option == 2) && (Sync == 0)){
      matrix.writeDigitRaw(0,R);
      matrix.writeDigitRaw(1,E);
      matrix.writeDigitRaw(3,N);
      matrix.writeDigitRaw(4,T);
      matrix.writeDisplay();
    }
      
    if((Sync == 1) && (Option == 2)){ // if enter pressed, sample current
     if(p == 0){
      ChargeCount = millis(); //Timer for delay of displayed current. similar to OptionCount

      sample.current();
      p++;
}
if((millis() - ChargeCount) > 250){
 Display current()
p = 0;
}



This is what im working with now (currently using serial for testing). I have since spent a few hours before pressing "post" and have made changes to my current code (shown below) and it appears to function. Given this, can anyone give a suggestion to a more compressed solution? I'm trying to 1.) simplify as much as possible, and 2.) Learn.:
Code: [Select]

char* Solar[] = {" ", " ", " ", "S", "O", "L", "A", "R", " ", "C", "U", "R", "R", "E", "N", "T", " ", " ", " " };
int SolarSize = 15;
int ScrollDelay = 250;
int i = 0;
int Timer;
int Enter = 1;
int Option = 2;
int Sync = 0;
int Begin = 1;

void solarScroll(){
  for(;((millis() - Timer) > ScrollDelay*(i)) && (i < (SolarSize+1));i++){
    Serial.print(Solar[i]);
    Serial.print(Solar[i+1]);
    Serial.print(Solar[i+2]);
    Serial.println(Solar[i+3]);
    //Serial.println(i);  
  }
}
void setup() {
Serial.begin(9600);
}
void loop() {
  if(Option == 2){
    if(Begin > 0){ // Statement to initialize "Timer" Once.
      Timer = millis();
      Begin--; // Prevents this statement from being entered until Option returns to 0;
      //Serial.println("Timer Initialized"); //debug
   }
    if(Sync < 1){ // Sync == "Enter", which has not been pressed;
     solarScroll();
   }else{
     Enter = 2; //Doubles time spent in Option 2 via "if" statement below
     //sampleCurrent();
     //displayCurrent();
   }
    if(((millis() - Timer) > (ScrollDelay*((SolarSize+1)*Enter)))){
     Option = 0; // Return to main
     Sync = 0;
     Enter = 1;
     i = 0; //Reset i count for SolarScroll
     Begin++; // Begin back to 1 in order to set Timer when accessed again
     Serial.println("Resetting Option to 0"); //debug
   }
 }
  if((millis() - Timer) > ScrollDelay*(SolarSize+2)){
    Option = 2; //Returns us to Option 2 in order to test exit and re-entry;
    Serial.println("Returning Option to 2"); //debug
  }
}



I should mention that this is only working with Serial and not with the display. my main issue that still stands is writing the binary values to the display. I have defined letters after testing to find these associations between the 7 segment LEDs and the binary values to illuminate them:
Code: [Select]


2^0 = a; 2^1 = b; 2^2 = c; 2^4 = d; 2^8 =e; 2^16 = f; 2^32 =g;



Therefore, I wrote these definitions:
Code: [Select]

#define A B01110111
#define C B00111001
#define E B01111001
#define L B00111000
#define N B00110111
#define O B00111111
#define R B00110001
#define S B01101101
#define U B00111110



As shown in the first code. I show this because i would like to add the address of my defined letters to an array(Direct Addressing?), where i can then run a loop to display the characters. I cant get this to work.

Example:
Code: [Select]


Array[] = {S, O, L,A,R,BLANK,C,U,R,R,E,N,T);

for(....{
matrix.writeDigitRaw(0,Solar[i+0]);
matrix.writeDigitRaw(0,Solar[i+1]);
matrix.writeDigitRaw(0,Solar[i+2]);
matrix.writeDigitRaw(0,Solar[i+3]);
matrix.writeDisplay();
}



This is all i have working currently:
Code: [Select]


int Solar[] = {1,2,4,8,16,32,64,128,256,57,62,49,49,121,55,120,0,0,0};

for(...{
      matrix.writeDigitRaw(0,Solar[i+0]);
      matrix.writeDigitRaw(1,Solar[i+1]);
      matrix.writeDigitRaw(3,Solar[i+2]);
      matrix.writeDigitRaw(4,Solar[i+3]);
      matrix.writeDisplay();


Where the array values are the defined binary values written in decimal.


Thanks for your input!

DangerToMyself

Edit your post and replace "quote" with "code" inside your brackets. :)

evalonso

Edit your post and replace "quote" with "code" inside your brackets. :)
Done :)

Go Up