Skip to content

Instantly share code, notes, and snippets.

@buildcircuit
Created March 11, 2013 07:42
Show Gist options
  • Save buildcircuit/5132589 to your computer and use it in GitHub Desktop.
Save buildcircuit/5132589 to your computer and use it in GitHub Desktop.
EXPERIMENT 2- ARDUINO AND WTV020SD-16P MODULE
// WWW.BUILDCIRCUIT.COM//
//SELECTOR BTN = pin 6
//TRIGGER = pin 7
//RESET = PIN 2
//CLOCK = PIN 3
//DATA = PIN 4
//BUSY = PIN 5
#include <Wtv020sd16p.h>
int resetPin = 2; // The pin number of the reset pin.
int clockPin = 3; // The pin number of the clock pin.
int dataPin = 4; // The pin number of the data pin.
int busyPin = 5; // The pin number of the busy pin.
const int buttonPin = 6; // the pin that the SELECTOR pushbutton is attached to
const int triggerPin = 7; // the pin that the TRIGGER is attached to
// Variables will change:
int buttonPushCounter = 0; // counter for the number of SELECTOR button presses
int buttonState = 0; // current state of the SELECTOR button
int lastButtonState = 0; // previous state of the button
int triggerState = 0; // current state of the Trigger
int lastTriggerState = 0; // previous state of the Triger
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
Wtv020sd16p wtv020sd16p(resetPin,clockPin,dataPin,busyPin);
void setup() {
//Initializes the module.
wtv020sd16p.reset();
// initialize the SELECTOR and Trigger button pins as a inputs:
pinMode(buttonPin, INPUT);
pinMode(triggerPin, INPUT);
Serial.begin(9600); //Start serial interface (for debugging)
wtv020sd16p.asyncPlayVoice(0);
}
void loop() {
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
triggerState = digitalRead(triggerPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState && millis() - time > debounce) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
// if the current state is HIGH then the button
// went from off to on:
time = millis();
Serial.println("Selector Button Pushed");
// plays words
wtv020sd16p.asyncPlayVoice(5);
if (buttonPushCounter < 3)
{
buttonPushCounter++;
Serial.print("Selector Button State: ");
Serial.println(buttonPushCounter);
}
else buttonPushCounter = 1;
}
else {
}
}
// compare the triggerState to its previous state
if (triggerState != lastTriggerState) {
// if the state has changed, do something
if (triggerState == HIGH) {
Serial.println("Trigger Pushed");
Serial.print("Selector Button State: ");
Serial.println(buttonPushCounter);
SelectorPosition();
}
else {
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
lastTriggerState = triggerState;
}
void SelectorPosition(){
switch (buttonPushCounter) {
case 1:
Serial.println("song1");
wtv020sd16p.asyncPlayVoice(0);
wtv020sd16p.stopVoice();
break;
case 2:
Serial.println("Song2");
wtv020sd16p.asyncPlayVoice(1);
wtv020sd16p.stopVoice();
break;
case 3:
Serial.println("Song3");
wtv020sd16p.asyncPlayVoice(2);
delay(1000);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment