Digital Electronics Lab #2

Part 1: Powering Your Teensy From Your Breadboard

The following is an image of my breadboard after I properly wired up my breadboard, and plugged it into my laptop:

Part 2: Wire Up an LED, And Use It As a Digital Output

The following is a video of my blue LED blinking at a rate of 2000 milliseconds, instead of the 1000 milliseconds that the code originally used:

Part 3: Wire up a button and use it as a digital input

The following is a video of my blue LED blinking when a button is pushed:

The following is a video of the blue LED blinking when a switch is flipped:

Part 4: The Serial Monitor

The following is a video of the serial monitor, as the LED is turned on and off. When the LED is on, it will say “blue led is on!,” and when it is off it will say “blue led is off!”

Part 5: Using a potentiometer as an analog input

The following is a video of the serial monitor responding to the value changes I am making in the potentiometer.

Part 6: See if you can get something going with all this

The following is a video of the final circuit. It has two buttons, one potentiometer, four LEDs and one switch. When active, the first button will make the LEDs flash synchronously together, at a pace determined by the position of the potentiometer. When active, the second button, will make the LEDs flash asynchronously in order, at a pace determined by the position of the potentiometer. The switch changes the direction of the lights: whether they will flash from left to right or right to left. I couldn’t quite get the random lights to work, but this what I have for now!

Here is my code:

int blueLed = 7;                      // make variable for each of the components on the breadboard
int greenLed = 8;
int whiteLed = 9;
int yellowLed = 10;
int buttonPin = 33;
int buttonPin2 = 34;
int potValue = 0;
int slideSwitch = 32;

void setup() {

  pinMode(blueLed, OUTPUT);          // set pinMode for the digital inputs
  pinMode(greenLed, OUTPUT);
  pinMode(whiteLed, OUTPUT);
  pinMode(yellowLed, OUTPUT);
  pinMode(buttonPin, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(slideSwitch, INPUT);
}

void loop() {
  potValue = analogRead(A16);
  if (digitalRead(buttonPin) == HIGH) {           // button #1
    digitalWrite(blueLed, HIGH);                  // all of the LEDs turn on
    digitalWrite(greenLed, HIGH);
    digitalWrite(whiteLed, HIGH);
    digitalWrite(yellowLed, HIGH);
    delay(potValue);                              // all of the LEDs remain on for a duration determined by the pot
    digitalWrite(blueLed, LOW);                   // all of the LEDs turn off
    digitalWrite(greenLed, LOW);
    digitalWrite(whiteLed, LOW);
    digitalWrite(yellowLed, LOW);
    delay(potValue);                              //all of the LEDs remain off for a duration determined by the pot
  }

  if (digitalRead(buttonPin2) == HIGH) {          // button #2
    if (digitalRead(slideSwitch) == HIGH) {       // the slide switch is turned to the left
      digitalWrite(blueLed, HIGH);                // the first LED turns on, the rest are off
      digitalWrite(greenLed, LOW);
      digitalWrite(whiteLed, LOW);
      digitalWrite(yellowLed, LOW);
      delay(potValue);                            // the LEDs remain like this for a value determined by the pot
      digitalWrite(blueLed, LOW);                 // the second LED turns on, the rest are off
      digitalWrite(greenLed, HIGH);
      digitalWrite(whiteLed, LOW);
      digitalWrite(yellowLed, LOW);
      delay(potValue);                            // the LEDs remain like this for a value determined by the pot
      digitalWrite(blueLed, LOW);                 // the third LED turns on, the rest are off
      digitalWrite(greenLed, LOW);
      digitalWrite(whiteLed, HIGH);
      digitalWrite(yellowLed, LOW);
      delay(potValue);                            // the LEDs remain like this for a value determined by the pot
      digitalWrite(blueLed, LOW);                 // the fourth LED turns on, the rest are off
      digitalWrite(greenLed, LOW);
      digitalWrite(whiteLed, LOW);
      digitalWrite(yellowLed, HIGH);
      delay(potValue);                           // the LEDs remain like this for a value determined by the pot
      digitalWrite(blueLed, LOW);                // all of the LEDs turn off
      digitalWrite(greenLed, LOW);
      digitalWrite(whiteLed, LOW);
      digitalWrite(yellowLed, LOW);
      delay(potValue);                           // the LEDs remain like this for a value determined by the pot
    }
    if (digitalRead(slideSwitch) == LOW) {       // the slide switch is turned to the right
      digitalWrite(blueLed, LOW);                // the fourth LED turns on, the rest are off
      digitalWrite(greenLed, LOW);
      digitalWrite(whiteLed, LOW);
      digitalWrite(yellowLed, HIGH);
      delay(potValue);                           // the LEDs remain like this for a value determined by the pot
      digitalWrite(blueLed, LOW);                // the third LED turns on, the rest are off
      digitalWrite(greenLed, LOW);
      digitalWrite(whiteLed, HIGH);
      digitalWrite(yellowLed, LOW);
      delay(potValue);                           // the LEDs remain like this for a value determined by the pot
      digitalWrite(blueLed, LOW);                // the second LED turns on, the rest are off
      digitalWrite(greenLed, HIGH);
      digitalWrite(whiteLed, LOW);
      digitalWrite(yellowLed, LOW);
      delay(potValue);                           // the LEDs remain like this for a value determined by the pot
      digitalWrite(blueLed, HIGH);               // the first LED turns on, the rest are off
      digitalWrite(greenLed, LOW);
      digitalWrite(whiteLed, LOW);
      digitalWrite(yellowLed, LOW);
      delay(potValue);                           // the LEDs remain like this for a value determined by the pot
      digitalWrite(blueLed, LOW);                // all of the LEDs turn off
      digitalWrite(greenLed, LOW);
      digitalWrite(whiteLed, LOW);
      digitalWrite(yellowLed, LOW);
      delay(potValue);                          // the LEDs remain like this for a value determined by the pot
    }
  }

}


Leave a comment

Design a site like this with WordPress.com
Get started