Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pitches.h"
- #include <SPI.h>
- #include <SD.h>
- #include <TMRpcm.h>
- const int buttonPin1 = A2; //serie 1 (eerste 5 knoppen)
- const int buttonPin2 = A3; //serie 2 (tweede 5 knoppen)
- File myFile;
- const int chipSelect = 4; //pin number sd card
- TMRpcm tmrpcm; //WAV afspeel object uit TMRpcm library
- const int pinSpeaker = 9;
- const int delayTijd = 100; //delaytime
- void setup() {
- //initilize buttons
- pinMode(buttonPin1, INPUT_PULLUP);
- pinMode(buttonPin2, INPUT_PULLUP);
- Serial.begin(9600);
- pinMode(SS, OUTPUT);
- //initialize SD card connection
- if (!SD.begin(chipSelect)) {
- Serial.println("initialization SD card failed!");
- return;
- }
- Serial.println("initialization SD card done.");
- }
- void loop() {
- delay(delayTijd);
- // read the state of the switch into a local variable:
- int readingPin1 = analogRead(buttonPin1);
- //delay(20);
- int readingPin2 = analogRead(buttonPin2);
- //print analog values
- Serial.println(readingPin1);
- Serial.println(readingPin2);
- //KNOP 1
- if ((readingPin1 >= 956)&&(readingPin1 <= 957)){
- Serial.println("knop 1");
- playwav();
- }
- //KNOP 2
- else if ((readingPin1 >= 602)&&(readingPin1 <= 604)){
- Serial.println(" knop 2");
- playwav();
- }
- //KNOP 3
- else if ((readingPin2 >= 968)&&(readingPin2 <= 970)){
- Serial.println(" knop 3");
- playwav();
- }
- //KNOP 4
- else if ((readingPin1 >= 329)&&(readingPin1 <= 330)){
- Serial.println(" knop 4");
- playwav();
- }
- //KNOP 5
- else if ((readingPin2 >= 849)&&(readingPin2 <= 853)){
- Serial.println(" knop 5");
- playwav();
- }
- //KNOP 6
- else if ((readingPin2 >= 897)&&(readingPin2 <= 899)){
- Serial.println(" knop 6");
- playwav();
- }
- //KNOP 7
- else if ((readingPin2 >= 715)&&(readingPin2 <= 717)){
- Serial.println(" knop 7");
- playwav();
- }
- //KNOP 8
- else if ((readingPin1 >= 523)&&(readingPin1 <= 526)){
- Serial.println(" knop 8");
- playwav();
- }
- //KNOP 9
- else if ((readingPin1 >= 980)&&(readingPin1 <= 982)){
- Serial.println(" knop 9");
- playwav();
- }
- //KNOP 10
- else if ((readingPin2 >= 933)&&(readingPin2 <= 936)){
- Serial.println(" knop 10");
- playwav();
- };
- }
- //Plays a .WAV file from the SD card
- void playWav(char* filename) {
- if (tmrpcm.isPlaying() != 1) {
- tmrpcm.speakerPin = pinSpeaker;
- pinMode(10, OUTPUT);
- digitalWrite(10, HIGH);
- pinMode(pinSpeaker,OUTPUT);
- Serial.println("Reading WAV from SD CARD = ok");
- Serial.println("Playing WAV:");
- tmrpcm.setVolume(6);
- Serial.println(filename);
- tmrpcm.play(filename);
- while (tmrpcm.isPlaying() == 1) {
- delay(50);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement