}*/\r
}\r
\r
-
\ No newline at end of file
+void TactonManager::buzz(unsigned int nbf, byte *desc)\r
+{\r
+ byte *amplitudes = (byte *)malloc(nbf * sizeof(byte));\r
+ if (amplitudes == NULL) \r
+ return;\r
+ \r
+ for (unsigned int i = 0 ; i < nbf ; i++)\r
+ amplitudes[i] = desc[i + 1];\r
+\r
+ _player->buzz(desc[0], nbf, amplitudes);\r
+ free(amplitudes);\r
+}\r
+\r
+void TactonManager::stop()\r
+{\r
+ _player->stop();\r
+}\r
void addPlay(byte index, unsigned long timestamp);\r
void checkPlay();\r
void setOffset(unsigned long timestamp);\r
+ \r
+ void buzz(unsigned int nbf, byte *desc);\r
+ void stop();\r
+\r
\r
void clear();\r
\r
{\r
public:\r
TactonPlayer(byte nbtactors, byte *pins);\r
- \r
+\r
+ //Same frequency for all the vibrators, different amplitude.\r
+ //Vibrates until stop\r
+ void buzz(unsigned int frequency, byte nbtactors, byte amplitudes[]);\r
+\r
+ //Stop any vibration\r
+ void stop();\r
+\r
//8bits pattern => max 8 tactors, change type if using more\r
virtual void beep(byte pattern, unsigned long duration, unsigned int frequency, byte amplitude) = 0;\r
/* \r
Serial.println(_ccper256cv, DEC);*/\r
}\r
\r
+//Start a vibration of a given frequency, with different amplitudes for each vibrator\r
+void TactonPlayerPreciseNew::buzz(unsigned int frequency, byte nbtactors, byte *amplitudes)\r
+{\r
+ if (nbtactors != _nbtactors)\r
+ return;\r
+ \r
+ sei();\r
+ init();\r
+ \r
+ //set the amplitudes\r
+ for (int i = 0 ; i < _nbtactors ; i++)\r
+ analogWrite(_pins[i], amplitudes[i]);\r
+}\r
+\r
+//Stop any vibration\r
+void TactonPlayerPreciseNew::stop()\r
+{\r
+ TCCR1A = 0;\r
+ //set duty cycle to 0\r
+ OCR1A = 0;\r
+ OCR1B = 0;\r
+ //clear the pattern\r
+ for (int i = 0 ; i < _nbtactors ; i++)\r
+ digitalWrite(_pins[i], LOW);\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
{\r
sei();\r
{\r
public:\r
TactonPlayerPreciseNew(byte nbtactors, byte *pins, byte pwmPin);\r
- \r
+ \r
+ //Same frequency for all the vibrators, different amplitude.\r
+ //Vibrates until stop\r
+ void TactonPlayerPreciseNew::buzz(unsigned int frequency, byte nbtactors, byte *amplitudes);\r
+\r
+ //Stop any vibration\r
+ void stop();\r
+ \r
//8bits pattern => max 8 tactors, change type if using more\r
void beep(byte pattern, unsigned long duration, unsigned int frequency, byte amplitude);\r
\r
#include <TactonPlayerPreciseNew.h>
#include <Tacton.h>
byte pins[] = {
- 3, 11, 5, 6};
+ 6, 5, 11, 3};
byte pwmPin = 9;
TactonPlayerPreciseNew player(4, pins, 9);
command = 0;
}
break;
+ //sets a frequency for all the vibrators and an amplitude for each one
+ // BnFa1a2...an
+ // n = nb tactors
+ // F = frequency
+ // A1, A2, ..., an : amplitudes
+ case 'B':
+ if (nbf == 0 && Serial.available() >= 2)
+ nbf = (((unsigned int) Serial.read()) << 8) | ((unsigned int) Serial.read());
+ if (nbf > 0)
+ {
+ //DO NOT OVERFLOW max(nbf): 60
+ while (posbuf < nbf + 1 && Serial.available() > 0)
+ {
+ buffer[posbuf] = Serial.read();
+ posbuf++;
+ }
+ if (posbuf >= nbf + 1)
+ {
+ manager.buzz(nbf, buffer);
+ posbuf = 0;
+ command = 0;
+ nbf = 0;
+ }
+ }
+ break;
+ //stop any vibration
+ case 'A':
+ manager.stop();
+ break;
//unknown command: do nothing
default:
command = 0;