From: Thomas Pietrzak Date: Tue, 26 Apr 2022 12:36:58 +0000 (+0200) Subject: Changed setAngle to cos^2 and sin^2 X-Git-Url: https://git.thomaspietrzak.com/?a=commitdiff_plain;h=90a67101bc3025cca12ed7b64081f6f237288048;p=tactonlibrary.git Changed setAngle to cos^2 and sin^2 --- diff --git a/Arduino/TactonPlayer/TactonPlayerPreciseNew.cpp b/Arduino/TactonPlayer/TactonPlayerPreciseNew.cpp index 6b6f32e..198515d 100644 --- a/Arduino/TactonPlayer/TactonPlayerPreciseNew.cpp +++ b/Arduino/TactonPlayer/TactonPlayerPreciseNew.cpp @@ -3,9 +3,9 @@ TactonPlayerPreciseNew::TactonPlayerPreciseNew(byte nbtactors, byte *pins, byte pwmPin) :TactonPlayer(nbtactors, pins), _pwmPin(pwmPin) -{ +{ pinMode(_pwmPin, OUTPUT); - digitalWrite(_pwmPin, LOW); + digitalWrite(_pwmPin, LOW); init(); } @@ -70,28 +70,31 @@ void TactonPlayerPreciseNew::setAmplitudes(byte nbtactors, byte *amplitudes) void TactonPlayerPreciseNew::setAngle(unsigned int angle) { + unsigned int x = cos(angle * M_PI / 180.0); + unsigned int y = sin(angle * M_PI / 180.0); + //vertical if (angle < 180) { - analogWrite(_pins[TACTOR_UP], 255 * sin(angle * M_PI / 180.0)); + analogWrite(_pins[TACTOR_UP], 255 * y * y); analogWrite(_pins[TACTOR_DOWN], 0); } else { - analogWrite(_pins[TACTOR_DOWN], - 255 * sin(angle * M_PI / 180.0)); + analogWrite(_pins[TACTOR_DOWN], - 255 * y * y); analogWrite(_pins[TACTOR_UP], 0); } //horizontal if (angle < 90 || angle > 270) { - analogWrite(_pins[TACTOR_RIGHT], 255 * cos(angle * M_PI / 180.0)); + analogWrite(_pins[TACTOR_RIGHT], 255 * x * x); analogWrite(_pins[TACTOR_LEFT], 0); } else { analogWrite(_pins[TACTOR_RIGHT], 0); - analogWrite(_pins[TACTOR_LEFT], - 255 * cos(angle * M_PI / 180.0)); + analogWrite(_pins[TACTOR_LEFT], - 255 * x * x); } } @@ -109,23 +112,23 @@ void TactonPlayerPreciseNew::stop() //Play a Tacton for a specified duration, frequency and amplitude void TactonPlayerPreciseNew::beep(byte pattern, unsigned long duration, unsigned int frequency, byte amplitude) -{ - //set the pattern - for (int i = 0 ; i < _nbtactors ; i++) - { +{ + //set the pattern + for (int i = 0 ; i < _nbtactors ; i++) + { if (pattern & (1 << i)) analogWrite(_pins[i], amplitude); else - digitalWrite(_pins[i], LOW); - } + digitalWrite(_pins[i], LOW); + } //set the frequency and activate the output setFrequency(frequency); - // /!\ multiply by 64 when the prescalar is applied to timer0 + // /!\ multiply by 64 when the prescalar is applied to timer0 delay(64*duration); - //Stop the PWM + //Stop the PWM TCCR1A = 0; //set duty cycle to 0 diff --git a/Arduino/wristbandTactons/wristbandTactons.ino b/Arduino/wristbandTactons/wristbandTactons.ino index a0e4df7..5a126a7 100644 --- a/Arduino/wristbandTactons/wristbandTactons.ino +++ b/Arduino/wristbandTactons/wristbandTactons.ino @@ -17,7 +17,10 @@ boolean active = false; void setup() { - Serial.begin(57600); + //Speed is halved: due to timers modifications? + // => Connect with 57600 bauds + Serial.begin(115200, SERIAL_8N1); + Serial.write("Tactile wristband"); // player.init(); /* player.debug1(); player.debug2(); @@ -207,7 +210,7 @@ void loop() break; //Ask for feedback case 'I': - Serial.write("I'm still alive"); + Serial.write("Tactile wristband"); command = 0; break; //unknown command: do nothing @@ -220,4 +223,3 @@ void loop() if (active) manager.checkPlay(); } -