I am trying to make a csgo bomb prop for me and my friends to use while we play airsoft. I am trying to add audio in for when the bomb is armed(planted.wav), disarmed(ctwin.wav), and when the timer runs out(twin.wav). Here is my code:
#include "pitches.h"
#include <LiquidCrystal.h> //include LCD library (standard library)
#include <Keypad.h> //include keypad library - first you must install library (library link in the video description)
#include "SD.h" //Lib to read SD card
#include <pcmConfig.h>
#include <pcmRF.h>
#include <TMRpcm.h>
#include "SPI.h" //SPI lib for SD card
#define SD_ChipSelectPin 11 //Chip select is pin number 11
TMRpcm tmrpcm; //create an object for use in this sketch
char password[8] = "7355608"; //create a password
int pozisyon = 0; //keypad position
int time=19; // countdown time
const byte rows = 4; //number of the keypad's rows and columns
const byte cols = 4;
int speakerpin=8;
int freq=2000;
int dur=120;
int codepos=0;
int interval=1000;
int previousMillis = 0;
char keyMap [rows] [cols] = { //define the cymbols on the buttons of the keypad
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins [rows] = {7, 6, 5, 4}; //pins of the keypad
byte colPins [cols] = {3, 2, 1};
Keypad myKeypad = Keypad( makeKeymap(keyMap), rowPins, colPins, rows, cols);
LiquidCrystal lcd (A0, A1, A2, A3, A4, A5); // pins of the LCD. (RS, E, D4, D5, D6, D7)
void setup(){
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("*******");
lcd.setCursor(0, 0);
Serial.begin(9600);
tmrpcm.speakerPin=8;
if(!SD.begin(SD_ChipSelectPin)){
Serial.println("SD fails");
return;
}
tmrpcm.setVolume(7);
//play();
}
void planted(){
tmrpcm.stopPlayback();
tmrpcm.play("planted.wav");
}
void ctwin(){
tmrpcm.stopPlayback();
tmrpcm.play("ctwin.wav");
}
void countdown(int timesincestart){
lcd.clear();
lcd.print("*******");
lcd.setCursor(0, 1);
lcd.print("BOMB ARMED");
int count=time;
planted();
while(count>0){
char whichKey;
whichKey=keyget();
if(whichKey == '*' || whichKey == '#'){
pozisyon=0;
}
if(whichKey == password [pozisyon]){
pozisyon ++;
}
if(pozisyon == 7){
lcd.clear();
lcd.print(" BOMB DISARMED");
lcd.setCursor(0, 1);
lcd.print(" CT'S WIN");
ctwin();
while(1);
}
lcd.setCursor(0, 1);
int timeleft=time-(millis()/1000-timesincestart);
lcd.print("BOMB ARMED ");
lcd.print(timeleft);
if (timeleft==9){
lcd.setCursor(12,1);
lcd.print(" ");
}
if (timeleft==25){
interval=800;
}
if (timeleft==15){
interval=700;
}
if (timeleft==10){
interval=600;
}
if (timeleft==6){
interval=400;
}
if (timeleft==3){
interval=250;
}
int currentMillis=millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
tone(speakerpin,freq,dur);
}
if (timeleft<=0){
lcd.setCursor(0, 0);
lcd.print("TERRORISTS WIN ");
lcd.setCursor(0, 1);
lcd.print("BOMB DETONATED ");
twin();
while(1);
}
}
return;
}
void twin(){
tmrpcm.stopPlayback();
tmrpcm.play("twin.wav");
}
char keyget(){
char whichKey = myKeypad.getKey(); //define which key is pressed with getKey
if (whichKey >='0' && whichKey<='9'){
codepos++;
}
if(whichKey == '*' || whichKey == '#'){
pozisyon=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" ENTRY RESET!");
delay(100);
lcd.clear();
lcd.print("*******");
codepos=0;
lcd.setCursor(0, 0);
}
if (codepos>=7){
lcd.clear();
lcd.print("*******");
codepos=0;
lcd.setCursor(0, 0);
}
lcd.setCursor(codepos-1, 0);
if (whichKey != NO_KEY){
if (whichKey == '1'){
tone(speakerpin,freq,dur);
lcd.print(1);
}
if (whichKey == '2'){
tone(speakerpin,freq*1.25,dur);
lcd.print(2);
}
if (whichKey == '3'){
tone(speakerpin,freq*1.5,dur);
lcd.print(3);
}
if (whichKey == '4'){
tone(speakerpin,freq*1.75,dur);
lcd.print(4);
}
if (whichKey == '5'){
tone(speakerpin,freq*2,dur);
lcd.print(5);
}
if (whichKey == '6'){
tone(speakerpin,freq*2.25,dur);
lcd.print(6);
}
if (whichKey == '7'){
tone(speakerpin,freq*2.5,dur);
lcd.print(7);
}
if (whichKey == '8'){
tone(speakerpin,freq*2.75,dur);
lcd.print(8);
}
if (whichKey == '9'){
tone(speakerpin,freq*3,dur);
lcd.print(9);
}
if (whichKey == '0'){
tone(speakerpin,freq*3.25,dur);
lcd.print(0);
}
}
return whichKey;
}
void loop(){
char whichKey;
whichKey=keyget();
if(whichKey == '*' || whichKey == '#'){
pozisyon=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" ENTRY RESET!");
delay(100);
lcd.clear();
lcd.print("*******");
codepos=0;
lcd.setCursor(0, 0);
}
if(whichKey == password [pozisyon]){
pozisyon ++;
}
if(pozisyon == strlen(password)){
pozisyon=0;
int timesincestart=(millis())/1000;
countdown(timesincestart);
}
delay(100);
}
And I get this error:
C:\Users\tobyw\Desktop\Arduino\csgo\csgo.ino: In function 'void planted()':
C:\Users\tobyw\Desktop\Arduino\csgo\csgo.ino:67:28: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
tmrpcm.play("planted.wav");
^
C:\Users\tobyw\Desktop\Arduino\csgo\csgo.ino: In function 'void ctwin()':
C:\Users\tobyw\Desktop\Arduino\csgo\csgo.ino:73:26: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
tmrpcm.play("ctwin.wav");
^
C:\Users\tobyw\Desktop\Arduino\csgo\csgo.ino: In function 'void twin()':
C:\Users\tobyw\Desktop\Arduino\csgo\csgo.ino:162:25: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
tmrpcm.play("twin.wav");
^