Getting 2 Separate Graphic Images to Flash Independently.

Hi everyone. I have spent 2 days trying to search for an answer to this one, but alas I have been able to resolve my problem.

I have Separate Images that I want to switch between White and Black but at different intervals. If I run each separately they work fine, but as soon as I try to run more than one the DELAY interferes with the other one.

I have also tried mills and still getting a pause which shouldn’t be there. (Not too hot on the mills timing function)

This is the First Set of Images (2 Small Circles that alternate between White & Black) works great with the Delay Function.

2 Sets of 2 Dots (first Set White and Black, Second Set Black & White, gives the Visual Impression they are Alternating from one to the Other.

display.fillCircle(display.width()/2+45, display.height()/2+25, 5, WHITE); //First Flashing Dot
display.fillCircle(display.width()/2+55, display.height()/2+25, 5, BLACK); //Second Flashing Dot
display.display();
delay(75); //Pause for Flashing Image

display.fillCircle(display.width()/2+45, display.height()/2+25, 5, BLACK); //First Flashing Dot
display.fillCircle(display.width()/2+55, display.height()/2+25, 5, WHITE); //Second Flashing Dot
display.display();
delay(75); //Pause for Flashing Image

The other code is for a set of 8 Small Rectangles that again have the odd one as Black to give the Impression of Flashing Lights in a Random Sequence.

// Start of First Set

display.fillRect(112, 3, 5,5, WHITE); // 1
display.fillRect(120, 3, 5,5, BLACK); // 2
display.fillRect(112, 11, 5,5, WHITE); // 3
display.fillRect(120, 11, 5,5, WHITE); // 4
display.fillRect(112, 19, 5,5, WHITE); // 5
display.fillRect(120, 19, 5,5, WHITE); // 6
display.fillRect(112, 27, 5,5, WHITE); // 7
display.fillRect(120, 27, 5,5, WHITE); // 8

display.display();

delay(75); //Pause for Flashing Image

//End of First Set

//Start of Second Set

display.fillRect(112, 3, 5,5, WHITE); // 1
display.fillRect(120, 3, 5,5, WHITE); // 2
display.fillRect(112, 11, 5,5, WHITE); // 3
display.fillRect(120, 11, 5,5, WHITE); // 4
display.fillRect(112, 19, 5,5, BLACK); // 5
display.fillRect(120, 19, 5,5, WHITE); // 6
display.fillRect(112, 27, 5,5, WHITE); // 7
display.fillRect(120, 27, 5,5, WHITE); // 8

display.display();

delay(75); //Pause for Flashing Image

//End of Second Set

//Start of Third Set

display.fillRect(112, 3, 5,5, BLACK); // 1
display.fillRect(120, 3, 5,5, WHITE); // 2
display.fillRect(112, 11, 5,5, BLACK); // 3
display.fillRect(120, 11, 5,5, WHITE); // 4
display.fillRect(112, 19, 5,5, WHITE); // 5
display.fillRect(120, 19, 5,5, WHITE); // 6
display.fillRect(112, 27, 5,5, BLACK); // 7
display.fillRect(120, 27, 5,5, WHITE); // 8

display.display();

delay(75); //Pause for Flashing Image

//End of Third Set

//Start of Forth Set

display.fillRect(112, 3, 5,5, WHITE); // 1
display.fillRect(120, 3, 5,5, WHITE); // 2
display.fillRect(112, 11, 5,5, WHITE); // 3
display.fillRect(120, 11, 5,5, BLACK); // 4
display.fillRect(112, 19, 5,5, WHITE); // 5
display.fillRect(120, 19, 5,5, BLACK); // 6
display.fillRect(112, 27, 5,5, WHITE); // 7
display.fillRect(120, 27, 5,5, WHITE); // 8

display.display();

delay(75); //Pause for Flashing Image

//End of Fourth

//Start of Fith Set

display.fillRect(112, 3, 5,5, WHITE); // 1
display.fillRect(120, 3, 5,5, BLACK); // 2
display.fillRect(112, 11, 5,5, WHITE); // 3
display.fillRect(120, 11, 5,5, BLACK); // 4
display.fillRect(112, 19, 5,5, WHITE); // 5
display.fillRect(120, 19, 5,5, BLACK); // 6
display.fillRect(112, 27, 5,5, WHITE); // 7
display.fillRect(120, 27, 5,5, WHITE); // 8

display.display();

delay(75); //Pause for Flashing Image

//End of Fith Set

//Start of Sith Set

display.fillRect(112, 3, 5,5, WHITE); // 1
display.fillRect(120, 3, 5,5, WHITE); // 2
display.fillRect(112, 11, 5,5, BLACK); // 3
display.fillRect(120, 11, 5,5, WHITE); // 4
display.fillRect(112, 19, 5,5, WHITE); // 5
display.fillRect(120, 19, 5,5, WHITE); // 6
display.fillRect(112, 27, 5,5, WHITE); // 7
display.fillRect(120, 27, 5,5, BLACK); // 8

display.display();

delay(75); //Pause for Flashing Image

//End of Sith Set

This again runs fine if on its own, but as soon as try to run both at the same time I get problems with Delay and a Pause.

I will also have another couple of Lines that will need to be sort of animated, moved in different places to look like a Sweeping Hand

This is all being Displayed on SS1306 128x64 OLED Screen

Any Help would be Much Apprieciated

Test.ino (10.4 KB)

well how about first you show us how you plan putting the images together and please use code tags.
If possible i would put the shapes in separate functions so the whole thing gets a lot more overview.

Hi, this is what I have so far, each component runs fine on its own but the DELAY stops the others form running again until the long one has finished.

I still have to somehow create a rotating line from the centre of the Crosshair too. This is purely an Animation for display and not a working program.

Here is the Code I have (Attachment)

Test.ino (10.5 KB)

What you need to do is keep track of the patterns within the function... something like this (untested)
It will never wait for a delay..

void Twin_Dots() {

  static unsigned long lastDisplayTime = 0;
  static int state = 0;

  const unsigned long pauseTime = 75;

  // Start of Twin Flashing Dots

  switch (state) {
    case 0:   // first time through, do setup
      lastDisplayTime = millis();
      state = 1;  // move to next state
      break;

    case 1:   // doing a delay
    case 3:   // doing a delay
      if ( millis() - lastDisplayTime >= pauseTime ) {
        state++;
      }
      break;

    case 2:   // display
      display.fillCircle(display.width() / 2 + 45, display.height() / 2 + 25, 5, WHITE); //First Flashing Dot
      display.fillCircle(display.width() / 2 + 55, display.height() / 2 + 25, 5, BLACK); //Second Flashing Dot
      display.display();
      lastDisplayTime = millis();
      state++;
      break;

    case 4:   // display
      display.fillCircle(display.width() / 2 + 45, display.height() / 2 + 25, 5, BLACK); //First Flashing Dot
      display.fillCircle(display.width() / 2 + 55, display.height() / 2 + 25, 5, WHITE); //Second Flashing Dot
      display.display();
      lastDisplayTime = millis();
      state = 1;  // last pattern, just to first delay so patterns repeat
      break;
  }
  // End of Twin Flashing Dots
}

void Flashing_Squares() {

  static unsigned long lastDisplayTime = 0;
  static int state = 0;

  const unsigned long pauseTime = 75;

  // Start of Small Flashing Squares


  //  delay(75);  //Pause for Flashing Image

  switch (state) {
    case 0:   // initial setup
      lastDisplayTime = millis();
      state = 2;  // skip initial delay
      break;

    case 1:   // doing a delay
    case 3:   // doing a delay
    case 5:   // doing a delay
    case 7:   // doing a delay
    case 9:   // doing a delay
    case 11:  // doing a delay
      if ( millis() - lastDisplayTime >= pauseTime ) {
        state++;
      }
      break;

    case 2:
      //Start of First Row
      display.fillRect(112, 3, 5, 5, WHITE);  // 1
      display.fillRect(120, 3, 5, 5, BLACK);  // 2
      display.fillRect(112, 11, 5, 5, WHITE); // 3
      display.fillRect(120, 11, 5, 5, WHITE); // 4
      display.fillRect(112, 19, 5, 5, WHITE); // 5
      display.fillRect(120, 19, 5, 5, WHITE); // 6
      display.fillRect(112, 27, 5, 5, WHITE); // 7
      display.fillRect(120, 27, 5, 5, WHITE); // 8
      display.display();
      //End of First Row

      lastDisplayTime = millis();
      state++;
      break;

    case 4:
      //Start of Second Row
      display.fillRect(112, 3, 5, 5, WHITE);  // 1
      display.fillRect(120, 3, 5, 5, WHITE);  // 2
      display.fillRect(112, 11, 5, 5, WHITE); // 3
      display.fillRect(120, 11, 5, 5, WHITE); // 4
      display.fillRect(112, 19, 5, 5, BLACK); // 5
      display.fillRect(120, 19, 5, 5, WHITE); // 6
      display.fillRect(112, 27, 5, 5, WHITE); // 7
      display.fillRect(120, 27, 5, 5, WHITE); // 8
      display.display();
      //End of Second Row
      lastDisplayTime = millis();
      state++;
      break;

    case 6:
      //Start of First Row
      display.fillRect(112, 3, 5, 5, BLACK);  // 1
      display.fillRect(120, 3, 5, 5, WHITE);  // 2
      display.fillRect(112, 11, 5, 5, BLACK); // 3
      display.fillRect(120, 11, 5, 5, WHITE); // 4
      display.fillRect(112, 19, 5, 5, WHITE); // 5
      display.fillRect(120, 19, 5, 5, WHITE); // 6
      display.fillRect(112, 27, 5, 5, BLACK); // 7
      display.fillRect(120, 27, 5, 5, WHITE); // 8
      display.display();
      //End of First Row
      lastDisplayTime = millis();
      state++;
      break;

    case 8:
      //Start of Second Row
      display.fillRect(112, 3, 5, 5, WHITE);  // 1
      display.fillRect(120, 3, 5, 5, WHITE);  // 2
      display.fillRect(112, 11, 5, 5, WHITE); // 3
      display.fillRect(120, 11, 5, 5, BLACK); // 4
      display.fillRect(112, 19, 5, 5, WHITE); // 5
      display.fillRect(120, 19, 5, 5, BLACK); // 6
      display.fillRect(112, 27, 5, 5, WHITE); // 7
      display.fillRect(120, 27, 5, 5, WHITE); // 8
      display.display();
      //End of Second Row
      lastDisplayTime = millis();
      state++;
      break;

    case 10:
      //Start of First Row
      display.fillRect(112, 3, 5, 5, WHITE);  // 1
      display.fillRect(120, 3, 5, 5, BLACK);  // 2
      display.fillRect(112, 11, 5, 5, WHITE); // 3
      display.fillRect(120, 11, 5, 5, BLACK); // 4
      display.fillRect(112, 19, 5, 5, WHITE); // 5
      display.fillRect(120, 19, 5, 5, BLACK); // 6
      display.fillRect(112, 27, 5, 5, WHITE); // 7
      display.fillRect(120, 27, 5, 5, WHITE); // 8
      display.display();
      //End of First Row
      lastDisplayTime = millis();
      state++;
      break;

    case 12:
      //Start of Second Row
      display.fillRect(112, 3, 5, 5, WHITE);  // 1
      display.fillRect(120, 3, 5, 5, WHITE);  // 2
      display.fillRect(112, 11, 5, 5, BLACK); // 3
      display.fillRect(120, 11, 5, 5, WHITE); // 4
      display.fillRect(112, 19, 5, 5, WHITE); // 5
      display.fillRect(120, 19, 5, 5, WHITE); // 6
      display.fillRect(112, 27, 5, 5, WHITE); // 7
      display.fillRect(120, 27, 5, 5, BLACK); // 8
      display.display();
      //End of Second Row
      lastDisplayTime = millis();
      state = 1;  // last pattern, just to first delay so patterns repeat
      break;
  }
// End of Small Flashing Squares
}


void loop()  {

  Twin_Dots();
  Flashing_Squares();

}

Hi blh64,

Thats great, I'm no programmer and only tinker with code and little projects. This is all to go in on a smaller screen inside a Sub Sight (Toy One).

One last question how the hell do I create a Line to travel around from the Centre of the Crosshair? The only way I can think of doing it is with a Line,,is there a piece of code for this? again I have searched for Clock hands etc to see if I could adapt some code but can't find anything. Any help would be appreciated.

I will try to add the Small Graph bit on the Left Tomorrow following the Code you have written. If I get stuck I hope you wont mind me posting back on here.

Thanks Again, your a STAR ***

Hi blh64,

Tried using your code for the other graphic, but there must be a delay in there somewhere as it stops the others from running, they only run when this code has finished (once only) here is the code I inserted

void Twin_Dots() {

static unsigned long lastDisplayTime = 0;
static int state = 0;

const unsigned long pauseTime = 75;

// Start of Twin Flashing Dots

switch (state) {
case 0: // first time through, do setup
lastDisplayTime = millis();
state = 1; // move to next state
break;

case 1: // doing a delay
case 3: // doing a delay
if ( millis() - lastDisplayTime >= pauseTime ) {
state++;
}
break;

case 2: // display
display.fillCircle(display.width() / 2 + 45, display.height() / 2 + 25, 5, WHITE); //First Flashing Dot
display.fillCircle(display.width() / 2 + 55, display.height() / 2 + 25, 5, BLACK); //Second Flashing Dot
display.display();
lastDisplayTime = millis();
state++;
break;

case 4: // display
display.fillCircle(display.width() / 2 + 45, display.height() / 2 + 25, 5, BLACK); //First Flashing Dot
display.fillCircle(display.width() / 2 + 55, display.height() / 2 + 25, 5, WHITE); //Second Flashing Dot
display.display();
lastDisplayTime = millis();
state = 1; // last pattern, just to first delay so patterns repeat
break;
}
// End of Twin Flashing Dots
}

What am I doing wrong?

Many Thanks Phil

Since I do not have that display, it’s hard to say. Try this code and see what comes out on the serial monitor. I increased the baud rate to 115200 so change that in the serial monitor to match.

Note: the code is too large to include, so it is attached.

Test.ino (12.4 KB)

Hi blh64,

I added the wrong code sorry. The Twin Dots and Squares work Fine, but when I try adding the Bar-graph, the Dots and squares only run once when the Bar-graph has done its sequence… Here is the Correct Code which I tried with your coding but there is obviously some kind of delay in there.

void Bargraph() {

// Start of Bargraph Frame

display.drawLine (10, 5, 10, 59, WHITE);
display.display();

display.drawLine (20, 5, 20, 59, WHITE);
display.display();

display.drawLine (10, 5, 20, 5, WHITE);
display.display();

display.drawLine (10, 59, 20, 59, WHITE);
display.display();

// End of Bargraph Frame

static unsigned long lastDisplayTime = 0;
static int state = 0;

const unsigned long pauseTime = 0;

// Start of Bargraph

switch (state) {
case 0: // first time through, do setup
lastDisplayTime = millis();
state = 1; // move to next state
break;

case 1: // doing a delay
case 3: // doing a delay
if ( millis() - lastDisplayTime >= pauseTime ) {
state++;
}
break;

case 2: // display
for(int x = 58; x > 8; x–){
display.drawLine(12, x, 18, x, WHITE);
display.display();
}
// lastDisplayTime = millis();
// state++;
// break;

// case 4: // display
for(int x = 8; x < 58; x++){
display.drawLine(12, x, 18, x, WHITE);
display.display();
display.drawLine(12, x, 18, x, BLACK);
display.display();
}
lastDisplayTime = millis();
state = 1; // last pattern, just to first delay so patterns repeat
break;
}
// End of Bargraph
}

It doesn't look like the bargraph ever changes so you only really need to draw it once and leave it. Also, you call display.display() every time through both for loops. This is very wasteful. Draw the entire bargraph and then display it.

Hi, tried that and still causing delay on the others. They don't change until the bar has moved up then down, will take a video of it and attach the code later

philipedwards:
Hi, tried that and still causing delay on the others. T

Of course it does !! you put the graphics in functions of their own, each with their own delay system and then call them after the other.. I am not a big fan of the whole switch-case system as it is now( you may as well be using delay() ), but you can continue with it though then you would need to integrate any graphics into the individual 'case:' section together with the other graphics part.

Tried the others in individual “case” but still having the problems. I’m no programmer just a dabbler and basically copy and alter code to get it to hopefully do what I want. I don’t understand all the functions and what they do. Plus at my age its a little harder to learn all this programming stuff.

It’s places like this that really help as there are many that understand the programming and know exactly what to do to get round certain issues.

This little project is just to go inside a Cosplay Gun (Inside the Scope) to display some moving Graphics, they don’t actually do anything else.

The Main Reticle - Static Bitmap

Two small dots alternating on the Right side at the Bottom

Set of 8 Small Rectangles alternating random On/Off Pattern

Bar Graph on the Left which is Filled and Emptied

Set of either small Random Numbers or Letters in the Bottom Left

And the One Part I haven’t even started on is a Line Rotating round from the Centre of the Reticle

I’m sure these can all run at the same time, but I haven’t got a Clue how to.

I can get them all to Run on there Own no problem…

Attached is the Code I have so Far

Working_Copy.ino (14.4 KB)

Here is Video of what is happening. along with the code again with the removed errors.

http://www.bwof.co.uk/SCOPE.MOV

Working_Copy.ino (14.3 KB)

Yes well the code needs to be restructured a bit. First of all the delay system need to be removed from the switch-case and the call to display needs to be removed from every graphics function. Anyway i moved Bargraph into setup() it doesn’t have a time delay build in, and neither does the the random Number thing, so i just haven’t called it for now. i am not sure how much time the drawing of the actually but 75ms doesn’t look like a very long time,anyway, this is what i’ve done.

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>


#define OLED_RESET 12
#define SPEED 75

Adafruit_SSD1306 display(OLED_RESET);

long randNumber;
uint32_t lastmoment;
uint8_t twindotstate=0,flashsquarestate=0;

// Crosshair, 128x64px

  
void setup() {               
  Serial.begin(9600);
  while ( !Serial );
  randomSeed(analogRead(A0));  // read froam A0 then it makes sense to do an analogRead
  
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3D (for the 128x64)  
  display.clearDisplay();   // clears the screen and buffer ** DO NOT REMOVE **
  display.drawBitmap(0, 0,  myBitmap, 128, 64, 1); //Draws the Crosshair
  Bargraph();  // since bargraph has no delay time we may as well draw it once but not there after
  display.display();
  
} 

void loop()  {
  if (lastmoment + SPEED <millis()) {
    twindotstate=Twin_Dots(twindotstate);
    flashsquarestate=Flashing_Squares(flashsquarestate);
    display.display();
    lastmoment=millis();
    
  }
}

uint8_t Twin_Dots(uint8_t state) {

  /*static unsigned long lastDisplayTime = 0;
  static int state = 0;

  const unsigned long pauseTime = 75;

  // Start of Twin Flashing Dots

  Serial.print( "Twin_Dots: " );
  Serial.print( millis() );
  Serial.print( ", state = " ); Serial.println(state);  */

  switch (state) {
    case 0:   // display
      display.fillCircle(display.width() / 2 + 45, display.height() / 2 + 25, 5, WHITE); //First Flashing Dot
      display.fillCircle(display.width() / 2 + 55, display.height() / 2 + 25, 5, BLACK); //Second Flashing Dot
      return 1;
    case 1:   // display
      display.fillCircle(display.width() / 2 + 45, display.height() / 2 + 25, 5, BLACK); //First Flashing Dot
      display.fillCircle(display.width() / 2 + 55, display.height() / 2 + 25, 5, WHITE); //Second Flashing Dot
      return 0;
  }
  return 0;
}

uint8_t Flashing_Squares(uint8_t state) {
  switch (state) {
    case 0:
      //Start of First Row
      display.fillRect(112, 3, 5, 5, WHITE);  // 1
      display.fillRect(120, 3, 5, 5, BLACK);  // 2
      display.fillRect(112, 11, 5, 5, WHITE); // 3
      display.fillRect(120, 11, 5, 5, WHITE); // 4
      display.fillRect(112, 19, 5, 5, WHITE); // 5
      display.fillRect(120, 19, 5, 5, WHITE); // 6
      display.fillRect(112, 27, 5, 5, WHITE); // 7
      display.fillRect(120, 27, 5, 5, WHITE); // 8
      return 1;
    case 1:
      //Start of Second Row
      display.fillRect(112, 3, 5, 5, WHITE);  // 1
      display.fillRect(120, 3, 5, 5, WHITE);  // 2
      display.fillRect(112, 11, 5, 5, WHITE); // 3
      display.fillRect(120, 11, 5, 5, WHITE); // 4
      display.fillRect(112, 19, 5, 5, BLACK); // 5
      display.fillRect(120, 19, 5, 5, WHITE); // 6
      display.fillRect(112, 27, 5, 5, WHITE); // 7
      display.fillRect(120, 27, 5, 5, WHITE); // 8
      return 2;
    case 2:
      //Start of First Row
      display.fillRect(112, 3, 5, 5, BLACK);  // 1
      display.fillRect(120, 3, 5, 5, WHITE);  // 2
      display.fillRect(112, 11, 5, 5, BLACK); // 3
      display.fillRect(120, 11, 5, 5, WHITE); // 4
      display.fillRect(112, 19, 5, 5, WHITE); // 5
      display.fillRect(120, 19, 5, 5, WHITE); // 6
      display.fillRect(112, 27, 5, 5, BLACK); // 7
      display.fillRect(120, 27, 5, 5, WHITE); // 8
      return 3;
    case 3:
      //Start of Second Row
      display.fillRect(112, 3, 5, 5, WHITE);  // 1
      display.fillRect(120, 3, 5, 5, WHITE);  // 2
      display.fillRect(112, 11, 5, 5, WHITE); // 3
      display.fillRect(120, 11, 5, 5, BLACK); // 4
      display.fillRect(112, 19, 5, 5, WHITE); // 5
      display.fillRect(120, 19, 5, 5, BLACK); // 6
      display.fillRect(112, 27, 5, 5, WHITE); // 7
      display.fillRect(120, 27, 5, 5, WHITE); // 8
      return 4;
    case 4:
      //Start of First Row
      display.fillRect(112, 3, 5, 5, WHITE);  // 1
      display.fillRect(120, 3, 5, 5, BLACK);  // 2
      display.fillRect(112, 11, 5, 5, WHITE); // 3
      display.fillRect(120, 11, 5, 5, BLACK); // 4
      display.fillRect(112, 19, 5, 5, WHITE); // 5
      display.fillRect(120, 19, 5, 5, BLACK); // 6
      display.fillRect(112, 27, 5, 5, WHITE); // 7
      display.fillRect(120, 27, 5, 5, WHITE); // 8
      return 5;
    case 5:
      //Start of Second Row
      display.fillRect(112, 3, 5, 5, WHITE);  // 1
      display.fillRect(120, 3, 5, 5, WHITE);  // 2
      display.fillRect(112, 11, 5, 5, BLACK); // 3
      display.fillRect(120, 11, 5, 5, WHITE); // 4
      display.fillRect(112, 19, 5, 5, WHITE); // 5
      display.fillRect(120, 19, 5, 5, WHITE); // 6
      display.fillRect(112, 27, 5, 5, WHITE); // 7
      display.fillRect(120, 27, 5, 5, BLACK); // 8
      return 0;
  }
  // End of Small Flashing Squares
  return 0;
}

void Bargraph() {

// Start of Bargraph Frame 
  display.drawLine (5, 5, 5, 59, WHITE);
  display.drawLine (15, 5, 15, 59, WHITE);   
  display.drawLine (5, 5, 15, 5, WHITE);   
  display.drawLine (5, 59, 15, 59, WHITE);
  for(int x = 58; x > 8; x--){   
    display.drawLine(7, x, 13, x, WHITE); 
    display.display();     
  } 
  for(int x = 8; x < 58; x++){
    display.drawLine(7, x, 13, x, WHITE);
    display.drawLine(7, x, 13, x, BLACK); 
    display.display();   
  }
}


 void Random_Numbers() {
  randNumber = random(1000, 9999);                              
    display.setTextSize(1);
    display.setCursor(20,55);                          
    display.setTextColor(WHITE);                           
    display.print(randNumber); 
    display.display(); 

  randNumber = random(9999, 9999);                              
    display.setTextSize(1);
    display.setCursor(20,55);                          
    display.setTextColor(BLACK);                           
    display.fillRect(18, 53, 28, 11, BLACK);
    display.display(); 
    //display.clearDisplay(18, 53, 28, 11);   // clearDisplay() doesn't take any arguments you provide 4 hence i commented it out 
}

i had to remove the bitmap (9000 chars thing) you can put it back.
It compiles but i don’t have an OLED display so i can’t see how it works, but you can test it and see if this is going in the right direction

That was quick, thank You. Had a quick play and its certainly getting there.

The Bar Graph only Runs Once, and while it's running the Dots, Small Squares and Numbers don't Show on the Screen.

Once the Bar Graph has Gone up then Down again the other 3 Run OK.

Taken another Video to show what it's doing.

Also the Random Number display I had to put a Black Rectangle to Blank out the Numbers as I couldn't use the Clear Screen Function, as this Clears the whole Screen. Without it the Numbers just kept writing on top of each other, hence why the Black Rectabgle.is there a way to show fast running Random Numbers without using Clear Screen?

Video - http://www.bwof.co.uk/SCOPE2.MOV

Many Thanks Phil

Yeah well i think you can figure out what i've done and how you can implement the other parts (again) that with the numbers would work just fine, but then i would print the rectangle first and then the numbers over the top

 void Random_Numbers() {
  randNumber = random(1000, 9999);                      
  display.fillRect(18, 53, 28, 11, BLACK);                              
  display.setTextSize(1);
  display.setCursor(20,55);                          
  display.setTextColor(WHITE);                           
  display.print(randNumber); 
}

should already do it. The Bar graph i'll leave for you. You understand how it works don't you ?

Hi Deva_Rish,

Thanks the Random numbers works great and works with the Dots and Squares.

I have moved Bargraph(); into Void Loop, so it repeats but alas the same problem is there, all the others stop running while the Bargraph is moving up then down. When it reaches the Bottom, the others do a quick run, then the Bargraph goes through the motions again casing the others to pause.

This will take some woking out i fear. but I'll stick at ir.

Many thanks for all your help

Regards Phil

yeah, you'll have to create a switch-case for the bargraph, it's own bargraphstate variable, let it take the argument and return a new value at the end of each case. Look at the original function for the dots and how it is now.

Hi Deva_Rishi,

Have done what you said and it’s still pausing the Dots, Squares and Radom Numbers while the Line moves UP, the Dots, Squares and Numbers then run very briefly then stop while the Line in the Bar Graph moves down, the Dots, Squares and Numbers then Run agin for a split second until the Line in the Bar Graph moves again.

IS there a way to Draw the Moving Line in the Bar Graph differently as this is what appears to be causing the Problem.

UP

for(int x = 58; x > 8; x–){
display.drawLine(7, x, 13, x, WHITE);
display.display();

DOWN

for(int x = 8; x < 58; x++){
display.drawLine(7, x, 13, x, WHITE);
display.drawLine(7, x, 13, x, BLACK);
display.display();

As the display is only pausing while this line is moving.

Video attached so you can see as well as the code.

Video - http://www.bwof.co.uk/SCOPE3.MOV

Again thanks for all your help you have done what have taken me weeks… Very much appreciated.

Forum1.ino (11.9 KB)

yeah, the loops are holding it back a tad i guess, i changed bargraph() into this

uint8_t Bargraph(uint8_t state) {
  if (state==108) {
    display.drawLine (5, 5, 5, 59, WHITE);
    display.drawLine (15, 5, 15, 59, WHITE);   
    display.drawLine (5, 5, 15, 5, WHITE);   
    display.drawLine (5, 59, 15, 59, WHITE);
    return 0;
  }
  if (state<50) {
    display.drawLine(7, 58-state, 13, 58-state, WHITE); 
    state++;
    return state;
  }
  else {
    display.drawLine(7, 8+(state-50), 13, 8+(state-50), BLACK);
    state++;
    if (state>100) state=0;
    return state;
  }
}

since actually every line drawn is a ‘state’ . By now an ‘if-else’ is more efficient than a ‘switch-case’

and i changed loop() to this

void loop()  {
  
  bargraphstate=Bargraph(bargraphstate);
  display.display();
  
  if (lastmoment + SPEED <millis()) {
    twindotstate=Twin_Dots(twindotstate);
    flashsquarestate=Flashing_Squares(flashsquarestate);
    Random_Numbers();
    //display.display();  // since this is now called every loop there is no need to specifically call it here anymore
    lastmoment=millis();    
  }  
}

Since the bargraph is running at maximum speed there is no conditional executing depending on the elapsed time. i suspect that drawing all the other things does slow it down momentarily though. Of course doing it like this for you defeats the purpose of training a little, but i overlooked the extra problems caused by bargraph having all these extra states, i should have gotten you to do the dots after i did the squares, but how about you find a way of slowing the bargraph down just a little bit…