Pages: 1 2 [3]   Go Down
Author Topic: blink without delay brain problem  (Read 1842 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26489
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Boffin1, re. part 2.

You must really enjoy typing - have you noticed anything about your switch/case statements?
They're virtually identical, which means only one thing - time for a lookup table.
Code:
const byte digitTable [10] = { B01111110, B00110000, B01101101, B01111001, B00110011,
                               B01011011, B01011111, B01110000, B01111111, B01111011};

void show ()
{
  // WANT TO PUT IF  ( T OR PERIOD HAS CHANGED) DO DISPLAY

  if ( T >= 99 ) {
    divided = T/10;
  }  else {
    divided = T ;
    period = HIGH;
  }

  if ( T == 0 ) {
    period = LOW ;
  }

  secNibble10 = divided / 10;  // extract the tens digit from the time
  secNibble = divided % 10;  // extract the units digit

  tens = (secNibble10) ? digitTable [ secNibble10] : 0; // leading zero blanking
  units = digitTable [secNibble];
  units |= ( period) ? B10000000 : 0;

  digitalWrite(latchPin, LOW);

  shiftOut(dataPin, clockPin, LSBFIRST, tens);
  shiftOut(dataPin, clockPin, LSBFIRST, units);

  digitalWrite(latchPin, HIGH);
}  // end of showT function
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks AWOL,, yes I need to tidy up and learn lots of short cuts, I actually saw a lookup table like this last night, but now you have shown me the right way to do it.

I must also find how to run a function if something has changed, but I just want to see if I can get the countdown working OK first.
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

   tens = (secNibble10) ? digitTable [ secNibble10] : 0; // leading zero blanking
  units = digitTable [secNibble];
  units |= ( period) ? B10000000 : 0;

Whats the question mark ?   I am trying to understand this part...
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26489
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
tens = (secNibble10) ? digitTable [ secNibble10] : 0;
is a shorthand way of writing
Code:
if (secNibble10) // ie is secNibble10 non-zero?
  tens = digitTable [ secNibble10];
else
  tens = 0;
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, that makes sense now, so much to learn, so little time
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 129
Posts: 8594
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
so will you be "somewhere else in Australia" on your avatar tomorrow?
Yep, just moved 80k east to get away from the coast. Got better phone reception than we had 10k from town. Out here in West Aus that often happens, you can be 200k from any town but get perfect reception because there happens to be a mine nearby and they put in a tower for them.

Quote
and I get 232 out for T at the Rx end
Suspiciously similar to 1234, the 232 is HEX isn't it?

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 129
Posts: 8594
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think there's a bug in this line

Code:
    vw_send((uint8_t *)msg, strlen(msg));     // send the character out
 

msg is not a null-terminated string so strlen will count until it finds a '\0', wherever that may be. I suspect you are transmitting 10s or even 100s of bytes.

Try

Code:
    vw_send((uint8_t *)msg, 4);     // send the character out

I haven't looked at the Rx code yet to see how this would be handled.
______
Rob

 
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Rob
I will try that code, I do define the array msg as 4 in the setup, is that part of it?

I will stick the scope on and see what the transmission length is, I should have done that anyway.

I will also look up the hex/dec story  when I get a chance ( 4am and I am soldering hundreds of LEDs for a rush job! )


Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 129
Posts: 8594
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
do define the array msg as 4 in the setup, is that part of it?
That doesn't help, it merely tells the compiler how much memory to allocate but at run time that means nothing.

You can't use strlen() on it because the contents of msg is not a string, it's binary data.

You can use "sizeof (msg)" which is probably the best way to do it, but just for debugging use "4" to see what happens.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

right, I see now, I will give it a try, thanks
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Right thanks everyone, its working !

And a stupid thing I had forgotten was that when it was just counting down seconds, I was worried about losing the first second, so I started the clock from 24.9 seconds for the 24 second timer.
This was because as soon as you hit "run" it would flick over to 23, but the horn would sound ( and the pause would go high )as soon as the count went from 1 to 0, so it was running for only 23 seconds.  ( imagine if I wanted a 2 second countdown - it would be 1 second )

I am now counting down in 10ths of a second, and displaying the last ten seconds as 9.9 etc, so the 0 doesn't happen until a second after the 1 has changed to 0.9 and it counts right down to 0.0 .

So now I start at the "proper" 24 secs.   It pauses and restarts from the fraction of a second fine too.

Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Pages: 1 2 [3]   Go Up
Jump to: