Motorized Cops

This week playing off of what we’ve learned so far in class, I put together this on my Arduino:


I wanted to be able to experiment with doing multiple processes at once. Since my toy motor and button were still attached, I just added LEDs and connected them to the button, showing one on with the motor and one off with the motor. I really wanted to have one blinking while the motor was off, but every time I tried, it wasn’t liking that…

I also put little beads on top of the LEDs to try and diffuse the light. Putting a tape flag on the motor makes it known the motor is running and can have a fun sound.

Here’s the sketch:

const int switchPin = 2;
const int motorPin = 9;
int switchState = 0;


void setup() {
  pinMode(motorPin,OUTPUT); //motor pin
  pinMode(switchPin,INPUT);  //switch pin
  pinMode(13, OUTPUT);      
  pinMode(5, OUTPUT);
    

}

void loop() {
  switchState = digitalRead(switchPin);
  
  if (switchState == HIGH) {
    digitalWrite(motorPin, HIGH);
  }
  else {
    digitalWrite(motorPin,LOW);
  }
  
  if (switchState == HIGH) {
    digitalWrite(5, HIGH);
  }
  else {
    digitalWrite(5, LOW);
  }
  
  if (switchState == LOW) {
    digitalWrite(13, HIGH);
  }
  else {
    digitalWrite(13, LOW);
  }
  
}