Changed setAngle to cos^2 and sin^2
authorThomas Pietrzak <thomas.pietrzak@gmail.com>
Tue, 26 Apr 2022 12:36:58 +0000 (14:36 +0200)
committerThomas Pietrzak <thomas.pietrzak@gmail.com>
Tue, 26 Apr 2022 12:36:58 +0000 (14:36 +0200)
Arduino/TactonPlayer/TactonPlayerPreciseNew.cpp
Arduino/wristbandTactons/wristbandTactons.ino

index 6b6f32e76c3aeee12c6b8d544071d61ad801bcb1..198515d04c4587f15be08c28b1de379e8b3d1d74 100644 (file)
@@ -3,9 +3,9 @@
 \r
 TactonPlayerPreciseNew::TactonPlayerPreciseNew(byte nbtactors, byte *pins, byte pwmPin)\r
 :TactonPlayer(nbtactors, pins), _pwmPin(pwmPin)\r
-{
+{\r
        pinMode(_pwmPin, OUTPUT);\r
-       digitalWrite(_pwmPin, LOW);
+       digitalWrite(_pwmPin, LOW);\r
        init();\r
 }\r
 \r
@@ -70,28 +70,31 @@ void TactonPlayerPreciseNew::setAmplitudes(byte nbtactors, byte *amplitudes)
 \r
 void TactonPlayerPreciseNew::setAngle(unsigned int angle)\r
 {\r
+       unsigned int x = cos(angle * M_PI / 180.0);\r
+       unsigned int y = sin(angle * M_PI / 180.0);\r
+       \r
        //vertical\r
        if (angle < 180)\r
        {\r
-               analogWrite(_pins[TACTOR_UP], 255 * sin(angle * M_PI / 180.0));\r
+               analogWrite(_pins[TACTOR_UP], 255 * y * y);\r
                analogWrite(_pins[TACTOR_DOWN], 0);\r
        }\r
        else\r
        {\r
-               analogWrite(_pins[TACTOR_DOWN], - 255 * sin(angle * M_PI / 180.0));\r
+               analogWrite(_pins[TACTOR_DOWN], - 255 * y * y);\r
                analogWrite(_pins[TACTOR_UP], 0);\r
        }\r
 \r
        //horizontal\r
        if (angle < 90 || angle > 270)\r
        {\r
-               analogWrite(_pins[TACTOR_RIGHT], 255 * cos(angle * M_PI / 180.0));\r
+               analogWrite(_pins[TACTOR_RIGHT], 255 * x * x);\r
                analogWrite(_pins[TACTOR_LEFT], 0);\r
        }\r
        else\r
        {\r
                analogWrite(_pins[TACTOR_RIGHT], 0);\r
-               analogWrite(_pins[TACTOR_LEFT], - 255 * cos(angle * M_PI / 180.0));\r
+               analogWrite(_pins[TACTOR_LEFT], - 255 * x * x);\r
        }\r
 }\r
 \r
@@ -109,23 +112,23 @@ void TactonPlayerPreciseNew::stop()
        \r
 //Play a Tacton for a specified duration, frequency and amplitude\r
 void TactonPlayerPreciseNew::beep(byte pattern, unsigned long duration, unsigned int frequency, byte amplitude)\r
-{      
-       //set the pattern
-       for (int i = 0 ; i < _nbtactors ; i++)
-       {
+{      \r
+       //set the pattern\r
+       for (int i = 0 ; i < _nbtactors ; i++)\r
+       {\r
                if (pattern & (1 << i))\r
                        analogWrite(_pins[i], amplitude);\r
                else\r
-                       digitalWrite(_pins[i], LOW);
-       }
+                       digitalWrite(_pins[i], LOW);\r
+       }\r
        \r
        //set the frequency and activate the output\r
        setFrequency(frequency);\r
        \r
-       // /!\ multiply by 64 when the prescalar is applied to timer0
+       // /!\ multiply by 64 when the prescalar is applied to timer0\r
        delay(64*duration);\r
        \r
-       //Stop the PWM
+       //Stop the PWM\r
        TCCR1A = 0;\r
 \r
        //set duty cycle to 0\r
index a0e4df7956f4a75f9a0779e4f2ef0404dc3ebc85..5a126a7579b16109a6771256530accf208d03a9a 100644 (file)
@@ -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();
 }
-\r