In-depth Post #5

Unfortunately due to multiple inconveniences with time and cadets, my mentor and I were unable to meet, however we were able to communicate online to discuss whatever we had needed to. Two weeks ago, after I acquired all the basic parts for programming with electronics, my mentor gave me an assignment to make a program so that if I set up my bread board with a row of LED’s in an array, I can make them blink in sequence (left to right or right to left).

So since this my first official program using the Arduino controller, it is not the cleanest of programs, but I guess that is sort of expected. So the script I made is very simple but it is very long because it is repeating the same thing over again and again. There is probably way more efficient ways to do this but like I said this is my first program.

So it looks like this:

include<stdio.h>
  int led [8] = { 0, 2, 3, 4, 5, 6, 7, }
  void setup() {
    pinMode(led, OUTPUT);
  }
  void loop() {
    digitalWrite(led [0], HIGH);
    delay(1000);
    digitalWrite(led [0], LOW);
    delay(1000);
    digitalWrite(led [1], HIGH);
    delay(1000);
    digitalWrite(led [1], LOW);
    delay(1000);
    digitalWrite(led [2], HIGH);
    delay(1000);
    digitalWrite(led [2], LOW);
    delay(1000);
    digitalWrite(led [3], HIGH);
    delay(1000);
    digitalWrite(led [3], LOW);
    delay(1000);
    digitalWrite(led [4], HIGH);
    delay(1000);
    digitalWrite(led [4], LOW);
    delay(1000);
    digitalWrite(led [5], HIGH);
    delay(1000);
    digitalWrite(led [5], LOW);
    delay(1000);
    digitalWrite(led [6], HIGH);
    delay(1000);
    digitalWrite(led [6], LOW);
    delay(1000);
    digitalWrite(led [7], HIGH);
    delay(1000);
    digitalWrite(led [7], LOW);
    delay(1000);
  }
Anyways, to start, the #include stdio.h is an include statement and is typically found in any basic program. It is basically saying what kind of procedure or syntax it will have to follow. In this case it is the, “Standard Input Output” stdio.h. Next we have what we call an array. It basically is telling the computer that there are eight LED’s and variable we have given to each of the LED’s. The void setup is also a basic procedure. It is essentially saying which port on the chip the power will be coming from. So,  pinMode(led, OUTPUT);, this means that that the ports with the LED’s in them will be on output. We defined which ports those would be on the array earlier.
Now this is the main part of the program, everything else before was to setup for this segment of the program. The first thing you will see is the statement, void loop(). This really speaks for itself, it just means everything within the statement will be on a loop. Moving on, you will see the statement: digitalWrite(led [0], HIGH);. First the digitalWrite is the code way of saying do this, and it is telling the first LED, led[0] as stated in the array, to be on HIGH, which essentially means on. Then it says  delay(1000);, which is just a delay for 1000 milliseconds. And finally is tells the LED to turn off withe the  digitalWrite command and the LOW part of it which, similar to HIGH, it’s just telling it to turn off. Then there is another delay. You might realize that the rest of the script is the same thing, however the LED’s have been swapped, and this script works perfectly fine, it is just rather long due to the repeated segment.
Since I have successfully completed this program, my mentor and I will start to look into the main part of my project, the robot. We will hopefully decide what robot we should make and how it will be done, with what parts I need, how the script will look and etc.
Questions
1.  My mentor offers me hands on experience with the circuitry. Typically if I cannot figure out how to wire the breadboard to accommodate my program my mentor can show me how to do it, and also what I will need to do it with. This also applies to my scripts, but it can also be done online as we can just relay information back on forth via emailing.
2/3. He recommends books and can explain other types of languages like Java and how they relate to C. It is always interesting to me how those type of things work. I also think the understanding of these kind of things help reinforce you understanding of C and ultimately it affects your knowledge of how to make a more efficient program. For example, you can incorporate hexadecimal or binary into your program to do something you might want that you couldn’t do with just C.
4. Generally, we will first update ourselves with what we have been doing, then we work our way into the goal of meeting which is usually decided before hand through email. What we will be talking about is always different, it just depends on what needs to be done at the time.
5. I’d say the way we can manage to communicate with the language barrier. I already talked about this topic, but generally in situations like this, especially C, I will miss specific details due to the complexity of the language. At least a language like HTML would have easier.
6. Sort of based on the previous question, I think my mentor is learning to adapt to my lack of the Cantonese language and optimize his word choice to make sure I can keep up and work on finding all the right details. I think we can relate to each other well and learn from each others perspectives.

One thought on “In-depth Post #5”

  1. Please bring in some of the materials this week and teach me a short tutorial. How about video taping some of your work?
    QMtK

Leave a Reply

Your email address will not be published. Required fields are marked *