int ADCTouchRead(byte ADCChannel, int samples = 100)
{
long _value = 0;
for(int _counter = 0; _counter < samples; _counter ++)
{
pinMode(ADCChannel, INPUT_PULLUP);
ADMUX |= 0b11111;
ADCSRA |= (1<<ADSC); //start conversion
while(!(ADCSRA & (1<<ADIF))); //wait for conversion to finish
ADCSRA |= (1<<ADIF); //reset the flag
pinMode(ADCChannel, INPUT);
_value += mozziAnalogRead(ADCChannel);
}
return _value / samples;
}
/* Example changing the gain of a sinewave, using Mozzi sonification library. Demonstrates the use of a control variable to influence an audio signal. Circuit: Audio output on digital pin 9 on a Uno or similar, or DAC/A14 on Teensy 3.0/3.1, or check the README or http://sensorium.github.com/Mozzi/ Mozzi help/discussion/announcements: Tim Barrass 2012, CC by-nc-sa.*/
#include <MozziGuts.h>#include <Oscil.h> // oscillator template#include <tables/sin2048_int8.h> // sine table for oscillator
// use: Oscil <table_size, update_rate> oscilName (wavetable), look in .h file of table #included aboveOscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin(SIN2048_DATA);
// control variable, use the smallest data size you can for anything used in audiobyte gain = 255;
//ADC Touch setupint ref0, ref1; //reference values to remove offset
int ADCTouchRead(byte ADCChannel, int samples = 100){ long _value = 0; for(int _counter = 0; _counter < samples; _counter ++) { pinMode(ADCChannel, INPUT_PULLUP); ADMUX |= 0b11111; ADCSRA |= (1<<ADSC); //start conversion while(!(ADCSRA & (1<<ADIF))); //wait for conversion to finish ADCSRA |= (1<<ADIF); //reset the flag pinMode(ADCChannel, INPUT); _value += mozziAnalogRead(ADCChannel); } return _value / samples;}
void setup(){ startMozzi(); // start with default control rate of 64 aSin.setFreq(3320); // set the frequency ref0 = ADCTouchRead(A2, 500); //create reference values to ref1 = ADCTouchRead(A3, 500); //account for the capacitance of the pad}
void updateControl(){ // as byte, this will automatically roll around to 255 when it passes 0 if(gain > 3){ gain = gain - 3 ; }else{ gain = 0; } //*// pauseMozzi(); int value0 = ADCTouchRead(A2); //no second parameter int value1 = ADCTouchRead(A3); // --> 100 samples
value0 -= ref0; //remove offset value1 -= ref1; if(value0 > 40) { aSin.setFreq(3320); // set the frequency gain = 255; } if(value1 > 40) { aSin.setFreq(3760); gain = 255; }// unPauseMozzi(); //*/}
int updateAudio(){ return (aSin.next()* gain)>>8; // shift back to STANDARD audio range, like /256 but faster}
void loop(){ audioHook(); // required here}
> <mailto:mozzi-users+unsub...@googlegroups.com>.
> <mailto:mozzi-users+unsub...@googlegroups.com>.
> > <mailto:mozzi-users+unsub...@googlegroups.com <javascript:>>.
> > To post to this group, send email to mozzi...@googlegroups.com
> <javascript:>
> > <mailto:mozzi...@googlegroups.com <javascript:>>.
> > To view this discussion on the web, visit
> >
> https://groups.google.com/d/msgid/mozzi-users/88cb42e9-a99c-4d9f-91da-7e4c66decffb%40googlegroups.com
> <https://groups.google.com/d/msgid/mozzi-users/88cb42e9-a99c-4d9f-91da-7e4c66decffb%40googlegroups.com>
>
> >
> <https://groups.google.com/d/msgid/mozzi-users/88cb42e9-a99c-4d9f-91da-7e4c66decffb%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/mozzi-users/88cb42e9-a99c-4d9f-91da-7e4c66decffb%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
> > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Mozzi-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to mozzi-users...@googlegroups.com
> <mailto:mozzi-users+unsub...@googlegroups.com>.
To unsubscribe from this group and stop receiving emails from it, send an email to mozzi-users...@googlegroups.com.
To post to this group, send an email to mozzi...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/mozzi-users/54C2D18D.7040805%40gmail.com.
/* Example changing the gain of a sinewave, using Mozzi sonification library. Demonstrates the use of a control variable to influence an audio signal. Circuit: Audio output on digital pin 9 on a Uno or similar, or DAC/A14 on Teensy 3.0/3.1, or check the README or http://sensorium.github.com/Mozzi/ Mozzi help/discussion/announcements: Tim Barrass 2012, CC by-nc-sa.*/
#include <MozziGuts.h>#include <Oscil.h> // oscillator template#include <tables/sin2048_int8.h> // sine table for oscillator
// use: Oscil <table_size, update_rate> oscilName (wavetable), look in .h file of table #included aboveOscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin(SIN2048_DATA);
// control variable, use the smallest data size you can for anything used in audiobyte gain = 255;
//ADC Touch setupint sampleCount[3] = {0};int values[3] = {0};
void setup(){ startMozzi(); // start with default control rate of 64 aSin.setFreq(4200); // set the frequency}
void updateControl(){ // as byte, this will automatically roll around to 255 when it passes 0 if(gain > 3){ gain = gain - 3 ; }else{ gain = 0; } //* //begin ADCTouch pinMode(A4, INPUT_PULLUP); ADMUX |= 0b11111; ADCSRA |= (1<<ADSC); //start conversion ADCSRA |= (1<<ADIF); //reset the flag pinMode(A4, INPUT); values[0] = mozziAnalogRead(A4); sampleCount[0]++; //end ADCTouch if(sampleCount[0] == 64){//wait for 64 samples if(values[0] > 500) {//did we get a touch with all these samples ?// aSin.setFreq(3320); // set the frequency gain = 255;//amp it up } sampleCount[0] = 0;//reset count } //*/}
int updateAudio(){ return (aSin.next()* gain)>>8; // shift back to STANDARD audio range, like /256 but faster}
void loop(){ audioHook(); // required here}
> <javascript:> <javascript:>>.> > > <mailto:mozzi-users+unsub...@googlegroups.com
> > > To post to this group, send email to mozzi...@googlegroups.com
> > <javascript:>
> > > <mailto:mozzi...@googlegroups.com <javascript:>>.
> > > To view this discussion on the web, visit
> > >
> >
> https://groups.google.com/d/msgid/mozzi-users/88cb42e9-a99c-4d9f-91da-7e4c66decffb%40googlegroups.com
> <https://groups.google.com/d/msgid/mozzi-users/88cb42e9-a99c-4d9f-91da-7e4c66decffb%40googlegroups.com>
>
> >
> <https://groups.google.com/d/msgid/mozzi-users/88cb42e9-a99c-4d9f-91da-7e4c66decffb%40googlegroups.com
> <https://groups.google.com/d/msgid/mozzi-users/88cb42e9-a99c-4d9f-91da-7e4c66decffb%40googlegroups.com>>
>
> >
> > >
> >
> <https://groups.google.com/d/msgid/mozzi-users/88cb42e9-a99c-4d9f-91da-7e4c66decffb%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/mozzi-users/88cb42e9-a99c-4d9f-91da-7e4c66decffb%40googlegroups.com?utm_medium=email&utm_source=footer>
>
> >
> <https://groups.google.com/d/msgid/mozzi-users/88cb42e9-a99c-4d9f-91da-7e4c66decffb%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/mozzi-users/88cb42e9-a99c-4d9f-91da-7e4c66decffb%40googlegroups.com?utm_medium=email&utm_source=footer>>>.
>
> >
> > > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>
> > <https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>>.
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Mozzi-users" group.
> > To unsubscribe from this group and stop receiving emails from it,
> send
> > an email to mozzi-users...@googlegroups.com <javascript:>
> > <mailto:mozzi-users+unsub...@googlegroups.com <javascript:>>.
> > To post to this group, send email to mozzi...@googlegroups.com
> <javascript:>
> > <mailto:mozzi...@googlegroups.com <javascript:>>.
> > To view this discussion on the web, visit
> >
> https://groups.google.com/d/msgid/mozzi-users/9a4e618d-3d85-4402-a1df-1a868be9702e%40googlegroups.com
> <https://groups.google.com/d/msgid/mozzi-users/9a4e618d-3d85-4402-a1df-1a868be9702e%40googlegroups.com>
>
> >
> <https://groups.google.com/d/msgid/mozzi-users/9a4e618d-3d85-4402-a1df-1a868be9702e%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/mozzi-users/9a4e618d-3d85-4402-a1df-1a868be9702e%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
> > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Mozzi-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to mozzi-users...@googlegroups.com
> <mailto:mozzi-users+unsub...@googlegroups.com>.
To post to this group, send email to mozzi...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/mozzi-users/2d6a39d5-a893-4f66-a940-ceccc437642d%40googlegroups.com.