From: Thomas Pietrzak Date: Fri, 30 Mar 2012 15:46:52 +0000 (+0000) Subject: Fix tacton player X-Git-Url: https://git.thomaspietrzak.com/?a=commitdiff_plain;h=5e0475640c430786d57ca4f20f16cde4beb5b443;p=tactonlibrary.git Fix tacton player git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@72 47cf9a05-e0a8-4ed5-9e9b-101a649bc004 --- diff --git a/Arduino/TactonPlayer/TactonPlayerPreciseNew.cpp b/Arduino/TactonPlayer/TactonPlayerPreciseNew.cpp index cdfa842..850e8c2 100644 --- a/Arduino/TactonPlayer/TactonPlayerPreciseNew.cpp +++ b/Arduino/TactonPlayer/TactonPlayerPreciseNew.cpp @@ -4,17 +4,20 @@ TactonPlayerPreciseNew::TactonPlayerPreciseNew(byte nbtactors, byte *pins, byte pwmPin) :TactonPlayer(nbtactors, pins), _pwmPin(pwmPin) { - pinMode(_pwmPin, OUTPUT); + pinMode(_pwmPin, OUTPUT); + digitalWrite(_pwmPin, LOW); init(); } void TactonPlayerPreciseNew::init() const { //init PWM timer - TIMSK1 = 0; - TCNT1 = 0; - TCCR1A = 0; // CTC mode - TCCR1B = (1 << WGM12) | (1 << CS10); +// TCNT1 = 0; + //CTC mode + TCCR1A = (1 << COM1A0) | (1 << COM1B0); + TCCR1B = (1 << WGM12); + //set duty cycle to 0; + OCR1A = 0; } void TactonPlayerPreciseNew::setFrequency(unsigned int frequency) @@ -29,16 +32,21 @@ void TactonPlayerPreciseNew::setFrequency(unsigned int frequency) ocr = F_CPU / _frequency / 64 / 2 - 1; prescalarbits = (1 << CS11) | (1 << CS10); } - /* + Serial.print("_frequency="); Serial.print(_frequency, DEC); Serial.print(" prescalar="); Serial.print(prescalarbits, BIN); Serial.print(" ocr="); - Serial.println(ocr, DEC);*/ + Serial.println(ocr, HEX); + //set pre-scaler TCCR1B |= prescalarbits; + //set duty cycle OCR1A = ocr; + Serial.print(" OCR1A="); + Serial.println(OCR1A, HEX); + //OCR1B = ocr; /* _ccper256cv = F_CPU / 512 / _frequency; _currentcvi = 0;*/ @@ -49,33 +57,56 @@ void TactonPlayerPreciseNew::setFrequency(unsigned int frequency) Serial.println(_ccper256cv, DEC);*/ } - void TactonPlayerPreciseNew::beep(byte pattern, unsigned long duration, unsigned int frequency, byte amplitude) { + sei(); init(); - setFrequency(frequency); - setAmplitude(amplitude); - setDuration(duration); - setPattern(pattern); +// setAmplitude(amplitude); +// setDuration(duration); +// setPattern(pattern); //set the pattern for (int i = 0 ; i < _nbtactors ; i++) { - if (_pattern & (1 << i)) - { - analogWrite(_pins[i], _amplitude); - } + if (pattern & (1 << i)) + analogWrite(_pins[i], amplitude); + else + digitalWrite(_pins[i], LOW); } - - //_active = true; - + + //set the frequency and activate the output + setFrequency(frequency); +// analogWrite(9, 1); + /* + Serial.print("Start pattern"); + Serial.println(pattern, HEX); + */ //Start the PWM - TIMSK1 = (1 << OCIE1A); - - delay(duration); +// TCCR1A |= 1 << COM1A1; +// TIMSK1 = (1 << OCIE1A); +// Serial.print("Wait"); +// Serial.println(duration, DEC); + delay(duration); + +/* Serial.println("TCCR1"); + Serial.println(TCCR1A, BIN); + Serial.println(TCCR1B, BIN); + */ //Stop the PWM - TIMSK1 &= ~(1 << OCIE1A); +// TIMSK1 &= ~(1 << OCIE1A); +// TCCR1A &= ~(1 << COM1A1); + + TCCR1A = 0; + + //set duty cycle to 0 + OCR1A = 0; + OCR1B = 0; + //clear the pattern + for (int i = 0 ; i < _nbtactors ; i++) + digitalWrite(_pins[i], LOW); + +// Serial.println("Stop"); // TIMSK2 = (1 << OCIE2A) | (1 << TOIE2); // TIMSK2 = (1 << TOIE2);