Those who know me know that I live and breath Spin. I write Spin programs most of the day, most days of the week. I like it.
That said... a few customers with C experience are wanting some of my starter programs in C. I'm making progress, but have a couple areas where I take advantage of Spin and am not sure how to crowbar it in to C.
For example. This bit of code appears in my embedded "background" object, hence gets called every millisecond.
BPM long 60
Charge long N_G3, T_8TH, N_C4, T_8TH, N_E4, T_8TH
long N_G4, T_8TH * 3 / 2, N_E4, T_8TH, N_G4, T_DHALF
long -1, -1
OneNote long 0, 0, -1, -1 ' for tone_on
pri play_music | nfreq
if (p_music =< 0) ' manual stop invoked?
io.freq_out(0, SPKR, 0)
if (--nmillis > 0) ' is note playing now?
nfreq := long[p_music] ' get note
p_music += 4 ' advance to timing
if (nfreq < 0) ' if end
longfill(@p_music, 0, 2)
nmillis := long[p_music] * 60 / BPM ' adjust timing for bpm
p_music += 4
io.freq_out(0, SPKR, nfreq) ' start the note
I made the musical note and timing constants #defines and put them into their own .h file. That seems to be okay. The trick is the music. In my Spin program you can pass a pointer to an array of musical notes/times (the "Charge!" ditty is built in) and have it play. I'm not sure how to structure this in C.
Sorry for the beginner question. I appreciate the assist.
It's Jon or JonnyMac -- please do not call me Jonny.