Go Down

### Topic: blink without delay brain problem (Read 4171 times)previous topic - next topic

#### AWOL

#30
##### Apr 15, 2011, 10:25 am
@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: [Select]
`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`
"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.
I speak for myself, not Arduino.

#### Boffin1

#31
##### Apr 15, 2011, 10:48 am
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.
45 years of editing projects with a knife and soldering iron, then I found Arduino !

#### Boffin1

#32
##### Apr 15, 2011, 11:15 am
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...
45 years of editing projects with a knife and soldering iron, then I found Arduino !

#### AWOL

#33
##### Apr 15, 2011, 11:17 am
Code: [Select]
`tens = (secNibble10) ? digitTable [ secNibble10] : 0; `
is a shorthand way of writing
Code: [Select]
`if (secNibble10) // ie is secNibble10 non-zero?  tens = digitTable [ secNibble10]; else  tens = 0; `
"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.
I speak for myself, not Arduino.

#### Boffin1

#34
##### Apr 15, 2011, 11:46 am
Thanks, that makes sense now, so much to learn, so little time
45 years of editing projects with a knife and soldering iron, then I found Arduino !

#35
##### Apr 16, 2011, 02:46 am
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
Rob Gray aka the GRAYnomad www.robgray.com

#36
##### Apr 16, 2011, 02:54 am
I think there's a bug in this line

Code: [Select]
`    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: [Select]
`    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

Rob Gray aka the GRAYnomad www.robgray.com

#### Boffin1

#37
##### Apr 16, 2011, 03:49 am
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! )

45 years of editing projects with a knife and soldering iron, then I found Arduino !

#38
##### Apr 16, 2011, 04:22 am
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
Rob Gray aka the GRAYnomad www.robgray.com

#### Boffin1

#39
##### Apr 16, 2011, 04:29 am
right, I see now, I will give it a try, thanks
45 years of editing projects with a knife and soldering iron, then I found Arduino !

#### Boffin1

#40
##### Apr 17, 2011, 12:10 am
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.

45 years of editing projects with a knife and soldering iron, then I found Arduino !

Go Up