Skip to content

Commit

Permalink
Add ability to set realtime value
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonmcdonald committed Aug 13, 2015
1 parent 63f16be commit abeb0c9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Adafruit_DRV2605.cpp
Expand Up @@ -85,6 +85,9 @@ void Adafruit_DRV2605::setMode(uint8_t mode) {
writeRegister8(DRV2605_REG_MODE, mode);
}

void Adafruit_DRV2605::setRealtimeValue(uint8_t rtp) {
writeRegister8(DRV2605_REG_RTPIN, rtp);
}

/********************************************************************/

Expand Down
1 change: 1 addition & 0 deletions Adafruit_DRV2605.h
Expand Up @@ -81,6 +81,7 @@ class Adafruit_DRV2605 {
void selectLibrary(uint8_t lib);
void go(void);
void setMode(uint8_t mode);
void setRealtimeValue(uint8_t rtp);
// Select ERM (Eccentric Rotating Mass) or LRA (Linear Resonant Actuator) vibration motor
// The default is ERM, which is more common
void useERM();
Expand Down
39 changes: 39 additions & 0 deletions examples/realtime/realtime.ino
@@ -0,0 +1,39 @@
#include <Wire.h>
#include "Adafruit_DRV2605.h"

Adafruit_DRV2605 drv;

void setup() {
Serial.begin(9600);
Serial.println("DRV test");
drv.begin();

// Set Real-Time Playback mode
drv.setMode(DRV2605_MODE_REALTIME);
}

uint8_t rtp_index = 0;
uint8_t rtp[] = {
0x30, 100, 0x32, 100,
0x34, 100, 0x36, 100,
0x38, 100, 0x3A, 100,
0x00, 100,
0x40, 200, 0x00, 100,
0x40, 200, 0x00, 100,
0x40, 200, 0x00, 100
};

void loop() {

if (rtp_index < sizeof(rtp)/sizeof(rtp[0])) {
drv.setRealtimeValue(rtp[rtp_index]);
rtp_index++;
delay(rtp[rtp_index]);
rtp_index++;
} else {
drv.setRealtimeValue(0x00);
delay(1000);
rtp_index = 0;
}

}

0 comments on commit abeb0c9

Please sign in to comment.