\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
\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
\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