I'm new to coding and Arduino and i got this code from a friend and when i went to verify it i got errors. What is wrong with this code?
#include <Tone.h>
Tone freq1;
Tone freq2;
const int ledPin = 6;
const int transistorGnd = 7;
const int repulsorSpeaker = 11;
const int speakerGnd = 10;
boolean readyToFire = true;
boolean beginCount = true;
boolean notDeactivated = true;
int repulsorStable = 10;
const int tilt_s1 = A2;
const int tilt_s2 = A1;
long previousMillis = 0; // will store last time LED was updated
long interval = 12000;
int thisPitch1;
int thisPitch2;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
freq1.begin(repulsorSpeaker);
freq2.begin(repulsorSpeaker);
pinMode(ledPin, OUTPUT);
pinMode(speakerGnd, OUTPUT);
digitalWrite(speakerGnd, LOW);
pinMode(transistorGnd, OUTPUT);
digitalWrite(transistorGnd, LOW);
pinMode(A3, OUTPUT);
digitalWrite(A3, LOW);
pinMode(tilt_s1, INPUT);
pinMode(tilt_s2, INPUT);
analogWrite(ledPin, repulsorStable);
}
void loop() {
// put your main code here, to run repeatedly:
int tilt = getTiltPosition(); // read the position of the tilt sensor
Serial.print("Ready: ");
Serial.print(readyToFire); // status of whether or not the hand has been reset to prone position
Serial.print(", Pos: ");
Serial.println(tilt); // position of tilt sensor
delay(10); // slight delay to get better readings of sensor
if (tilt == 1) { // if hand is in prone position
if (readyToFire == false) { // if blast has been fired
beginCount = true; // begin counting time since hand has been in prone position
}
readyToFire = true; // ability fire has been reset
if (beginCount == true) {
unsigned long previousMillis = millis(); // reset counter
beginCount = false; // counter will not be reset until it has reached
}
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
if (notDeactivated == true) {
deactivate();
notDeactivated = false;
}
do {
analogWrite(ledPin, 0);
tilt = getTiltPosition();
Serial.print("Pos: ");
Serial.println(tilt);
delay(10);
} while (tilt == 1);
}
} else if (tilt == 2 && readyToFire == true) {
readyToFire = false;
repulsorFire();
notDeactivated = true;
}
}
int getTiltPosition(){
int s1 = digitalRead(tilt_s1);
int s2 = digitalRead(tilt_s2);
return (s1 << 1) | s2; //bitwise math to combine the values
}
void repulsorFire() {
for (int i = 2; i < 252; i+=2) { // from 0 to 254
analogWrite(ledPin, i);
if(i > 125) {
delay(5);
}
delay(5); // cause slight linear delay between fade steps
thisPitch1 = 0;
thisPitch2 = map(i, 2, 252, 1200, 1700);
playDTMF(thisPitch1, thisPitch2, 30);
} // end for loop
for (int j = 50; j > 0; j--) {
for (int k = 0; k < 20; k+=2) {
analogWrite(ledPin, 12*k);
thisPitch1 = map(k, 20, 0, (k*14), (j*10));
thisPitch2 = map(k, 20, 0, (k*36), (j*30));
playDTMF(thisPitch1, thisPitch2, 30);
delay(1);
} // end for loop
analogWrite(ledPin, 12*j);
delay(1);
} // end for loop
analogWrite(ledPin, repulsorStable);
} // end repulsorFire function
void deactivate () {
for (int i = 200; i > 0; i-=2) { // from 200 to 0
analogWrite(ledPin, i/20);
if(i < 100) {
delay(10);
}
delay(5); // cause slight linear delay between fade steps
thisPitch1 = 0;
thisPitch2 = map(i, 200, 0, 1500, 1200);
playDTMF(thisPitch1, thisPitch2, 30);
} // end for loop
}
void playDTMF(int number1, int number2, long duration)
{
freq1.play(number1, duration);
freq2.play(number2, duration);
}