forked from zjwhitehead/eppg-controller
-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
95 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef INC_SP140_VIBRATION_H_ | ||
#define INC_SP140_VIBRATION_H_ | ||
|
||
#include <Arduino.h> | ||
|
||
// Initialize the vibration motor | ||
bool initVibeMotor(); | ||
|
||
// Notify with vibration | ||
void pulseVibeMotor(); | ||
|
||
// Run a vibration sequence | ||
bool runVibePattern(const unsigned int sequence[], int siz); | ||
#endif // INC_SP140_VIBRATION_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "sp140/vibration.h" | ||
#include "sp140/structs.h" | ||
#include <Adafruit_DRV2605.h> | ||
|
||
Adafruit_DRV2605 vibeMotor; | ||
|
||
bool vibeMotorInitialized = false; | ||
|
||
bool initVibeMotor() { | ||
if (!vibeMotor.begin(&Wire1)) { return false; } | ||
vibeMotor.selectLibrary(3); | ||
vibeMotor.setMode(DRV2605_MODE_INTTRIG); | ||
vibeMotorInitialized = true; | ||
|
||
pulseVibeMotor(); // initial boot vibration | ||
return true; | ||
} | ||
|
||
void pulseVibeMotor() { | ||
const unsigned int pulsePattern[] = { 14, 1, 14 }; | ||
runVibePattern(pulsePattern, 3); | ||
} | ||
|
||
bool runVibePattern(const unsigned int pattern[], int patternSize) { | ||
if (!vibeMotorInitialized) { return false; } | ||
|
||
for (int i = 0; i < patternSize; i++) { | ||
vibeMotor.setWaveform(i, pattern[i]); | ||
} | ||
// add one extra empty cycle to ensure the motor is off at the end | ||
vibeMotor.setWaveform(patternSize, 0); | ||
vibeMotor.go(); | ||
return true; | ||
} |