int potPin = A5; // TODO 1.1: Replace this value with the pin number associated with the SIG pin on the potentiometer. Hint: Include the "A"...
int statusPin = 2; //TODO 3.1: Choose which LED pin you want to be the status LED
int NUM_MODES = 3;
int MAX_POT_VAL = 1023; // TODO 1.3: Replace this value with the maximum value reading from the potentiometer
int whites[4] = {5, 8, 11, 13};
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();
int potReading = analogRead(A5); //TODO 1.2: read the analog value from potPin. Hint: Google "how to read an analog pin arduino"
Serial.print("Potentiometer Reading: ");
Serial.print(potReading);
if (inDeadband()) {
blinkStatusLed();
}
else {
int modeNum = (potReading-1) / 341; //TODO 2.1: Fix this line to calculate the mode number (Hint: math operators are *, /, +, -, and %)
Serial.print(" you are in Mode: ");
Serial.println(modeNum);
if (modeNum ==0) {
turnOnLeds();
}
if (modeNum == 1) {
blinkall();
}
if (modeNum == 2){
blinkwhites();
}
//TODO 4.1: add more if statements here to process different modes
//TODO 4.2: Rearrange and change the color of your LEDs to match your LS design
//TODO 4.4: Call at least two custom functions you created last unit.
}
}
bool inDeadband() {
int potReading = analogRead(potPin); // Changed from digitalRead to analogRead
// Assuming your mode ranges are 341 units each (1023/3 ≈ 341)
// Adding 10% deadband between modes
if ((potReading > 307 && potReading < 375) || // Deadband between mode 0 and 1
(potReading > 648 && potReading < 716)) { // Deadband between mode 1 and 2
Serial.println(" you are in deadband");
return true;
}
else {
return false;
}
}
// ===========================================
// HELPER FUNCTIONS
// ===========================================
// These functions below perform specific, reusable tasks
// to simplify the main program logic.
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(statusPin, HIGH);
delay(100);
digitalWrite(statusPin, LOW);
delay(100);
}
//TODO 4.3: Implement at least two custom functions from last unit. Add them below.
void blinkall() {
for(int i = 2; i <= 13; i++){
digitalWrite(i,HIGH);
delay(100);
digitalWrite(i,LOW);
}
}
//blinks all leds at once
void blinkwhites() {
for (int i = 0; i < 4; i++) {
digitalWrite(whites[i],HIGH);
delay(500);
digitalWrite(whites[i], LOW);
}
}
//blinks all white leds