...

Assignment

’ I began by making a breadboard diagram in Fritzing followed by a schematic diagram in circuit-diagram.org. The diagrams portray two LEDs connected to Arduino pins 9 and 10 as outputs and a button connected to Arduino port 2 as an input.

I succumbed to looking at the code solutions first. But I ran through all the tutorials. I might need an explanation on thresholds and how to use the trigger variable. Also the nesting of statement was a bit perplexing.'

Images

Detail image

Detail image

Detail image

Detail image

Code

You can add code inside the code fences. The letter c after the three backticks means that the syntax highlighting will use the programming language c as the rules on how different parts of the text should be highlighted.

//decalare variables
//variables corresponding LEDs to ports 9, 10 on Arduino?
int ledPin1 = 10;
int ledPin2 = 9;
//variable assigning button to port 2 on Arduino?
int btnPin = 2;
//setting the value of the button to 0?
int btnState = 0;
//variable to check if state of button has changed?
int prevBtnState = 0;
//how many times button is pressed?
int counter = 0;

void setup() {
  // put your setup code here, to run once:
//setting pins 9, 10 as output?
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
//setting pin 2 as input?
  pinMode(btnPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  // check the button
  btnState = digitalRead(btnPin);

  // check if the state is different from the previous loop
//nesting if statement…when and why?
  if (btnState != prevBtnState) {
    if (btnState == HIGH) {
      // add one to the counter
      counter++;
      // check if the counter is too large
//counter corresponds to three states or LED on/off combinations that can exist within the setup?
      if(counter>2){
        counter = 0;
      }
//Showing the counter value
      Serial.println(counter);
    }
  }
  // store the current button state for the next loop
  prevBtnState = btnState;

//switch…case statement…new to me
  switch (counter) {
//both LEDs are off
    case 0:
      digitalWrite(ledPin1, LOW);
      digitalWrite(ledPin2, LOW);
      break;
//First LED is on
    case 1:
      digitalWrite(ledPin1, HIGH);
      digitalWrite(ledPin2, LOW);
      break;
//both LEDs are on
    case 2:
      digitalWrite(ledPin1, HIGH);
      digitalWrite(ledPin2, HIGH);
      break;
  }

  // delay helps to prevent noise from the input signal
 delay(10);
}

Video

Vimeo or YouTube

If you want to include a video from Vimeo or YouTube, you can use these shortcodes. The numbers/characters is the ID of the video.

{{<vimeo id="84880475" class="video">}}

If you are reading the .md file, the line below is the actual way you use it your page. If you are reading the website, you should see a video player below this.

{{<youtube dQw4w9WgXcQ>}}

If you are reading the .md file, the line below is the actual way you use it your page. If you are reading the website, you should see a video player below this.

Video file in the repository

You can add video files also directly to your site. The recommended way to do this is to use the hugo-video component that we have installed on the site.

Keep in mind a couple of rules:

  • The video needs to be in a folder called video inside the folder where your index.md file is.
  • Your video file needs to be very small so that it fits into the GitLab repository. Maximum size is 50MB, but ideally it should be even much smaller (under 10 MB). You can use the free tool HandBrake to convert your video to a smaller size.
  • Use .mp4 as the file format

Once you have your file ready and placed correctly, you can use the following code snippet to display your video:

<video controls width=100%>
  <source src ="./video/example-video.mp4" type="video/mp4">
  Your browser does not support the video tag.
</video>

Just update the filename to be correct. Here is the result: