Vaughn Johnson
Published

Project 02 - DIG3602C

Project 02 - DIG3602C Vaughn Johnson UCF-Spring 2023-DIG3602C-Davis Project 02

IntermediateShowcase (no instructions)24
Project 02 - DIG3602C

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Through Hole Resistor, 10 kohm
Through Hole Resistor, 10 kohm
×3
LED (generic)
LED (generic)
×3
PTS 645 Series Switch
C&K Switches PTS 645 Series Switch
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Picture

Schematic

Code

Arduino Sketches

C/C++
int SwitchState = 0;

void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
}

void loop() {
  SwitchState = digitalRead(2);

  // Run switch code.
  OnSwitch();
}
void OnSwitch() {
  // Handle led control through switch state.
  switch (SwitchState) {
    case 0:
      Serial.println(" ");
      Serial.println(" ");
      Serial.println("Switch is NOT pressed!");

      digitalWrite(3, HIGH);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);
      break;
    case 1:
      Serial.println(" ");
      Serial.println(" ");
      Serial.println("Switch IS pressed!");

      digitalWrite(3, LOW);
      digitalWrite(4, LOW);
      digitalWrite(5, HIGH);
      delay(250);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      delay(250);
      break;
  }
}

Credits

Vaughn Johnson
11 projects • 3 followers

Comments