Everything works fine, however, when running the sketch the delays between the tones aren,t 1000ms
If someone knows why this happens, please let me know. Thanks.
Peppel:
Everything works fine, however, when running the sketch the delays between the tones aren,t 1000ms
If someone knows why this happens, please let me know. Thanks.
So how long is the delay instead of the expected 1000ms?
I can never get my head around that notation. Can you express the RHS as a binary value?
I'm wondering if bits are mangled in PORTB that should not be mangled.
...R
Toggles bit zero in PORTB, i.e. PORTB = PORTB ^ 0x01;
Shouldn't mangle any other bits.
Common idiom, worth mastering.
PS: But it is not an atomic operation, so if not executed with interrupts inhibited (as it is here by virtue of being in an ISR), it could cause unintended results.
PORTB is the register that stores pin outputs.
The LSB of PORTB is PORTB0 (pin 5)
PORTB = 00000000
(1 << PORTB0) = 00000001
PORTB XOR (1 << PORTB0) = 00000001
It's just using a XOR mask to toggle pin 5, it has nothing to do with
timing or delays.
This is much easier to understand and PORTB = PORTB ^ 0b00000001; is even better.
And I guess the toggled bit is what is creating the tone.
So what is interfering with delay() ?
Can you add a little code to toggle the on board LED after every delay and ( A ) check the time against the flashing LED and ( B ) comment out the calls to myTone() and myNoTone() and see does that restore the delay() to its proper duration?
Can you add a little code to toggle the on board LED after every delay and ( A ) check the time against the flashing LED and ( B ) comment out the calls to myTone() and myNoTone() and see does that restore the delay() to its proper duration?
I connected a LED to pin 6 of the attiny (PB1) and tried the following sketch: