Go Down

Topic: Getting 2 Separate Graphic Images to Flash Independently. (Read 1 time) previous topic - next topic

Deva_Rishi

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
Code: [Select]
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 ?
To 'Correct' you have to be Correct. (and not be condescending..)

philipedwards

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
Norfolk Bits

Deva_Rishi

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.
To 'Correct' you have to be Correct. (and not be condescending..)

philipedwards

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.

Norfolk Bits

Deva_Rishi

yeah, the loops are holding it back a tad i guess, i changed bargraph() into this
Code: [Select]
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
Code: [Select]
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..
To 'Correct' you have to be Correct. (and not be condescending..)

Deva_Rishi

Another idea ! can you modify the bargraph() function to take arguments for the horizontal offset (the  'x' value) so you could use it to draw several next to each other ?
To 'Correct' you have to be Correct. (and not be condescending..)

philipedwards

#21
Dec 18, 2018, 01:12 pm Last Edit: Dec 18, 2018, 01:13 pm by philipedwards
Hi Deva_Rishi, what can I say, you are a blooming genius******

I have attached a Video showing it working.....

I had to move the Drawing of the Bar Graph from a into Setup as it want showing for some reason, but that was simple enough.

I can now try to do the Rotating line in the Centre of the Reticle. (I have started playing with this....

Yes I will look at changing the speed but at the Moment IT WORKS!!!! and you know what they say? If it ain't broke don't fix it..... LOL

I can't thank you enough for what you have done, and all your help. It must be great to be able to Program like you do, but at 60 I'm a little too old to learn it all, I'm now more of a Copy & Paste Guy...

I do try to work out what parts of the program do what and in most cases do find a way, but as for understating the whole Programming Language... I'm useless.

Anyway thanks again.

I'm sure I will be back on here for more help in the not too distance future..

Happy Christmas by the way.

All the best

Phil

Forgot to add video of it Working

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

Norfolk Bits

Deva_Rishi

and you know what they say? If it ain't broke don't fix it..... LOL
No but can fiddle with it and see what that does. Create more then one bar and have them run at different speeds etc...
It must be great to be able to Program like you do, but at 60 I'm a little too old to learn it all, I'm now more of a Copy & Paste Guy...
Well after playing with it for a while, reading a book on C++ programming can be a real help to make the next step, age is not a factor, only death is.
To 'Correct' you have to be Correct. (and not be condescending..)

philipedwards

Hi again, quick update,

I have been playing around and I think I have managed to get each part to have its own Speed setting, which can be changed if needed.

Possibly not the best way to do it, but it appears to work!

Here is what I have done - Attached

Thanks again

Regards Phil
Norfolk Bits

Deva_Rishi

yep that's perfect !
FYI, the Bargraph frame, could have just been created by calling 'my' Bargraph()
just like this within setup()
Code: [Select]
bargraphstate=Bargraph(bargraphstate); but what you did also works just fine.
Since the call to
Code: [Select]
display.display();probably takes quite a bit of time and you don't want to do it when it is not necessary, you could do something like this
Code: [Select]
void loop()  {
  bool dodisplay=false; 
  if (lastmomentbargraph + BARGRAPHSPEED <millis()) {
    bargraphstate=Bargraph(bargraphstate);
    lastmomentbargraph=millis();
    dodisplay=true;   
  }
  if (lastmomentdots + DOTSSPEED <millis()) {
    twindotstate=Twin_Dots(twindotstate);
    lastmomentdots=millis();
    dodisplay=true;   
  }     
  if (lastmomentsquares + SQUARESSPEED <millis()) {
    flashsquarestate=Flashing_Squares(flashsquarestate);
    lastmomentsquares=millis();
    dodisplay=true; 
  }
  if (lastmomentnumbers + RANDOMNUMBERSSPEED <millis()) {
    randomnumbersstate=Random_Numbers(randomnumbersstate);
    lastmomentnumbers=millis();
    dodisplay=true;   
  }
  if (dodisplay) display.display();
}
To 'Correct' you have to be Correct. (and not be condescending..)

blh64

if (lastmomentbargraph + BARGRAPHSPEED <millis()) {
  }
  if (lastmomentdots + DOTSSPEED <millis()) {
  }     
  if (lastmomentsquares + SQUARESSPEED <millis()) {
  }
  if (lastmomentnumbers + RANDOMNUMBERSSPEED <millis()) {
  }
Those all have a rolloever problem.  Granted, it will only happen every ~49 days, but still better not to code problems.  The safe way to deal with millis() is elapsed time only.

Go Up