int potPin = A5; // 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);
}
turnOffLeds();
}
void loop() {
// put your main code here, to run repeatedly:
if (inDeadband()) {
Serial.print("Analog Reading: ");
Serial.print(analogRead(potPin));
Serial.println(" is in deadband");
blinkStatusLed();
} else {
int modeNum = analogRead(potPin) / 342; //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) {
const int potPin = A5; // Analog input pin for the potentiometer
const int ledPins[] = {3, 5, 6, 9, 10, 11}; // PWM pins for the LEDs
const int numLeds = 6; // Number of LEDs
int potValue = analogRead(potPin);
int brightness = map(potValue, 0, 1023, 0, 255);
for (int i = 0; i < numLeds; i++) {
analogWrite(ledPins[i], brightness);
// Optional delay to slow down the fade-up effect
delay(10);
}
}
if (modeNum == 1) {
blinkInPairs();
}
if (modeNum == 2) {
ArraysSequenceLEDsInAZigZagGoingUp();
}
}
}
bool inDeadband() {
if (analogRead(potPin) >= 325 && analogRead(potPin) <= 359 || analogRead(potPin) >= 667 && analogRead(potPin) <= 701) {
/*
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.
*/
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 blinkAllLeds() {
for (int ledNumber = 2; ledNumber <= 13; ledNumber++) {
digitalWrite(ledNumber, HIGH);
delay(175);
digitalWrite(ledNumber, LOW);
delay(175);
}
}
void blinkInPairs() {
for (int ledNumber = 2; ledNumber <= 13; ledNumber++) {
digitalWrite(ledNumber, HIGH);
digitalWrite(ledNumber + 7, HIGH);
delay(75);
digitalWrite(ledNumber, LOW);
digitalWrite(ledNumber + 7, LOW);
delay(75);
}
}
void ArraysSequenceLEDsInAZigZagGoingUp()
{
int LEDsInAZigZagGoingUp[14] = {
2, 9, 3, 10, 4, 11, 5, 12, 6, 13, 7, 14, 8, 15
};
for (int ledNumber = 2; ledNumber <= 13; ledNumber++)
{
for (int index = 0; index < 14; index++)
{
digitalWrite(LEDsInAZigZagGoingUp[index], HIGH);
delay(100);
digitalWrite(LEDsInAZigZagGoingUp[index], LOW);
delay(100);
}
}
}