I want to have two separate audio channel playing at the same time (stereo headphones). Not for music, but for a binaural brain machine.
The device will pulse an audio signal into each speaker, as well as pulse two LEDs at the same frequency. The inspiration for this device came from a MAKE zine article, where the author used two timers on an AVR chip to pulse the speakers and a do while loop to pulse the LEDs.
Any ideas on how I can run two separate audio channels as well as 2 LEDs at once? (synced up)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I haven't seen the article you mention, but this code here (or something similar) should do the trick:
#define Time1 100
#define Pin1 PORTB.0
Dim TimeLoop1 As Word
'Add any more ports/timers here
TimeLoop1 = 0
Do
'Wait some amount of time, then increment timers
Wait 1 ms
TimeLoop1 += 1
'Toggle Pin1 if Time1 has elapsed since it was last toggled
if TimeLoop1 > Time1 Then
if Pin1 = On Then
Pin1 = Off
Else
Pin1 = On
End If
TimeLoop1 = 0
end if
'Any more time checking goes here
Loop
For extra ports, add an extra counter variable (ie. TimeLoop2) and duplicate the other code sections with new variable/constant names.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I want to have two separate audio channel playing at the same time (stereo headphones). Not for music, but for a binaural brain machine.
The device will pulse an audio signal into each speaker, as well as pulse two LEDs at the same frequency. The inspiration for this device came from a MAKE zine article, where the author used two timers on an AVR chip to pulse the speakers and a do while loop to pulse the LEDs.
Any ideas on how I can run two separate audio channels as well as 2 LEDs at once? (synced up)
I haven't seen the article you mention, but this code here (or something similar) should do the trick:
#define Time1 100
#define Pin1 PORTB.0
Dim TimeLoop1 As Word
'Add any more ports/timers here
TimeLoop1 = 0
Do
'Wait some amount of time, then increment timers
Wait 1 ms
TimeLoop1 += 1
'Toggle Pin1 if Time1 has elapsed since it was last toggled
if TimeLoop1 > Time1 Then
if Pin1 = On Then
Pin1 = Off
Else
Pin1 = On
End If
TimeLoop1 = 0
end if
'Any more time checking goes here
Loop
For extra ports, add an extra counter variable (ie. TimeLoop2) and duplicate the other code sections with new variable/constant names.