Last active
February 21, 2017 23:57
-
-
Save angelaperrone/c540150a0cad4cb207ad11b7d9543df7 to your computer and use it in GitHub Desktop.
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
//References | |
//Basic Example, Arduino IDE | |
//https://cdn-shop.adafruit.com/datasheets/DRV2605.pdf | |
//Tom Igoe switch state example | |
#include <Adafruit_DRV2605.h> | |
#include <Wire.h> | |
const int onOff = 5; | |
const int pausePlay = 6; | |
const int skipForward = 9; | |
const int skipBack = 10; | |
const int fastForward = 11; | |
const int randomSong = 12; | |
const int one = 49; | |
const int two = 50; | |
const int three = 51; | |
const int four = 52; | |
const int five = 53; | |
const int six = 54; | |
int lastOnOff = HIGH; //start/stop button | |
int lastPausePlay = HIGH; //pause/play button | |
int lastSkipForward = HIGH; //skip forward | |
int lastSkipBack = HIGH; //skip back | |
int lastFastForward = HIGH; //fast forward | |
int lastRandom = HIGH; //random song | |
Adafruit_DRV2605 drv; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(onOff, INPUT_PULLUP); | |
pinMode (pausePlay, INPUT_PULLUP); | |
pinMode(skipForward, INPUT_PULLUP); | |
pinMode(fastForward, INPUT_PULLUP); | |
pinMode(randomSong, INPUT_PULLUP); | |
drv.begin(); | |
drv.selectLibrary(1); | |
//I2C trigger sends "go" | |
//default internal trigger when sending GO | |
drv.setMode(DRV2605_MODE_INTTRIG); | |
} | |
//1 = UP | |
//0 = DOWN | |
void loop() { | |
int currentOnOffButton = digitalRead(onOff); | |
int currentPausePlayButton = digitalRead(pausePlay); | |
int currentSkipForwardButton = digitalRead(skipForward); | |
int currentSkipBackButton = digitalRead(skipBack); | |
int currentFastForwardButton = digitalRead(fastForward); | |
int currentRandomButton = digitalRead(randomSong); | |
//start/stop BUTTON | |
if (currentOnOffButton != lastOnOff) { | |
delay(10); | |
if (currentOnOffButton == LOW) { | |
drv.setWaveform(0, 47); //effect | |
drv.setWaveform(1, 0); // end wave form | |
//play the effect | |
drv.go(); | |
//wait a bit | |
Serial.write(49); | |
Serial.println(47); | |
delay(500); | |
} else { | |
drv.setWaveform(0, 111); //effect PLAY | |
drv.setWaveform(1, 0); // end wave form | |
//play the effect | |
drv.go(); | |
//wait a bit | |
Serial.write(49); | |
Serial.println(111); | |
delay(500); | |
} | |
} | |
lastOnOff = currentOnOffButton; | |
//Pause Play Button | |
if (currentPausePlayButton != lastPausePlay) { | |
delay(10); | |
if (currentPausePlayButton == LOW) { | |
drv.setWaveform (0, 98); //set wave form | |
drv.setWaveform (1, 0); //end wave form | |
drv.go(); | |
//wait a bit | |
Serial.write(50); | |
Serial.println(98); | |
delay(500); | |
} else { | |
drv.setWaveform(0, 47); //effect PLAY | |
drv.setWaveform(1, 0); //end wave form | |
drv.go(); | |
Serial.write(50); | |
Serial.println(47); | |
delay(500); | |
} | |
} | |
lastPausePlay = currentPausePlayButton; | |
//Skip Forward Button | |
if (currentSkipForwardButton != lastSkipForward) { | |
delay(10); | |
if (currentSkipForwardButton == LOW) { | |
drv.setWaveform(0, 86); | |
drv.setWaveform(1, 0); | |
drv.go(); | |
Serial.write(51); | |
delay(500); | |
} | |
} | |
lastSkipForward = currentSkipForwardButton; | |
//Skip Back Button | |
if (currentSkipBackButton != lastSkipBack) { | |
delay(10); | |
if (currentSkipBackButton == LOW) { | |
drv.setWaveform(0, 74); | |
drv.setWaveform (1, 0); | |
drv.go(); | |
Serial.write(52); | |
delay(500); | |
} | |
} | |
lastSkipBack = currentSkipBackButton; | |
//FAST FORWARD | |
if (currentFastForwardButton != lastFastForward) { | |
delay(10); | |
if (currentFastForwardButton == LOW) { | |
drv.setWaveform(0, 76); | |
drv.setWaveform(1, 0); | |
drv.go(); | |
Serial.write(53); | |
delay(500); | |
} | |
} | |
lastFastForward = currentFastForwardButton; | |
//Random | |
if (currentRandomButton != lastRandom) { | |
delay(10); | |
if (currentRandomButton == LOW) { | |
drv.setWaveform(0, 54); | |
drv.setWaveform(1, 0); | |
drv.go(); | |
Serial.write(54); | |
delay(500); | |
} | |
} | |
lastRandom = currentRandomButton; | |
// | |
// Serial.print("Random "); | |
// Serial.println (currentRandomButton); | |
// Serial.print("FF "); | |
// Serial.println (currentFastForwardButton); | |
// Serial.print("Digital Read "); | |
// Serial.println (currentOnOffButton); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment