int potPin = A0; // TODO: Replace this value with the pin number associated with the SIG pin on the potentiometer
int NUM_MODES = 3;
int MAX_POT_VAL = 1023; // TODO: Replace this value with the maximum value reading from the potentiometer
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
for (int pinNumber = 2; pinNumber <= 13; pinNumber++) {
pinMode(pinNumber, OUTPUT);
}
}
void loop() {
// put your main code here, to run repeatedly:
turnOffLeds();
if (inDeadband()) {
Serial.print("Analog Reading: ");
Serial.print(analogRead(potPin));
Serial.println(" is in deadband");
blinkStatusLed();
} else {
int modeNum = analogRead(potPin)/341.3; //TODO: Replace this with the correct mode number based on the potentiometer reading
Serial.print("Analog Reading: ");
Serial.print(analogRead(potPin));
Serial.print(" is equal to Mode: ");
Serial.println(modeNum);
if (modeNum == 0) {
modezero(1);
}
if (modeNum == 1) {
modeone (1);
}
if (modeNum == 2){
modetwo (1);
}
}
}
bool inDeadband() {
//In this function you will determine if your potentiometer reading is within a deadband range. You will
//be using analogRead as well as if statements.
//You should return true if you ARE in deadband and false otherwise.
//if the reading is between 270 and 320 return true .
if (analogRead(potPin)> 280 && analogRead(potPin) <315 ) {
return true;
}
else if (analogRead(potPin) > 700 && analogRead(potPin) < 735 ){
return true;
}
else {
return false;
}
}
void turnOffLeds() {
for (int ledNumber = 2; ledNumber <= 13; ledNumber++) {
digitalWrite(ledNumber, LOW);
}
}
void turnOnLeds() {
for (int ledNumber = 2; ledNumber <= 13; ledNumber++) {
digitalWrite(ledNumber, HIGH);
}
}
void blinkStatusLed() {
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
delay(100);
}
void modezero(int repeatCount) {
int turnontentaclesArray [14] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15};
for(int count = 0; count < repeatCount; count ++){
for(int index = 0; index <= 13; index++){
digitalWrite (turnontentaclesArray [index],HIGH);
delay(100);
digitalWrite(turnontentaclesArray [index], LOW);
delay (100);
}
}
}
void modeone (int repeatCount){
int turnonlargestandsmallestArray [14] = {2,15,3,14,4,13,5,12,6,11,7,10,8,9};
for(int count = 0; count < repeatCount; count ++){
for(int index = 0; index <= 13; index++){
digitalWrite (turnonlargestandsmallestArray [index],HIGH);
delay(100);
digitalWrite(turnonlargestandsmallestArray [index], LOW);
delay (100);
}
}
}
void modetwo (int repeatCount) {
int tentaclesrandomorderArray [14] = {10,14,11,9,13,7,8,12,15,2,3,4,5,6};
for(int count = 0; count < repeatCount; count ++){
for(int index = 0; index <= 13; index++){
digitalWrite (tentaclesrandomorderArray [index],HIGH);
delay(100);
digitalWrite(tentaclesrandomorderArray [index], LOW);
delay (100);
}
}
}