Embedded programing

1.- Programs I used or tried to use

For this week I installed atmel studio 7, and used Arduino which I already had installed. I also had to install the AVRDude "program" in order to be able to upload my .hex to my Attiny.

 

For this week I had to program something on the board I made. Since I already kind of knew how to use arduino, I took up the challenge to use another program, recommended by our FAB Academy instructor. What I wanted to make since the beginning was a binary counter using my 7 LED lights.

2.- Programming

At the beginning I thought of using two arrays, one to log the number in binary, another one for the pins in Arduino format, which appeared in an image I found separate of the datasheet, since I did not want to read the whole thing (and I was not sure that was in there), the site I found the image on was this.  After knowing the pin number assignation for the Arduino I created an array with the pin numbers using. Since I did not know how to change the number into binary, i went around the web looking on how to do it, at the beginning I only looked at posts from stack overflow  (I got used to looking there when I had a question about programming when I was making basic exercises like the game of life, or a particle system with things from the book "The Nature of Code"). As I did not the specific thing in there I just googled it and eventually arrived at this post. the code I used from that post was the following:

 

           void displayBinary(byte numtoshow){

                       for (int i =0;i<4;i++)

                                         {

                                         if (bitRead(numToShow, i)==1)

                                                                                   {

                                                         digitalWrite(ledPin[i], HIGH);

                                                                                    }

                                          else

                                                                                   {

                                                           digitalWrite(ledPin[i], LOW);

                                                                                   }

 

 

 

 

                                            }

 

 

 

                                       }

 If I understand correctly, in the code they propose is they use a byte data type to store the number, and if the byte at position i is a 1, then the led at position i of the array is listed as HIGH. I thought this was really clever and I liked it, since I learned a bit more on how to use data types in Arduino. I used the way that code worked,  and applied it to my own array of 7 positions, 0 to 6. I then set up a byte variable, that every time a button was pushed, a number was added to it, and then I set up a safety catch, when the number was 128, it reset to 0, that way it never got past 127 that was the maximum you can count with 7 bits. I verified the program and then went to the location the .hex was saved, changed its name and moved it to my FAB Academy folder.

To uploaded I connected the pins in my programmer, to the pins in board, each to their own counterpart, the reset with the reset, the mosi with mosi, ground with ground, and so on and so forth.  Then opened  the command prompt of windows and went to my FAB Academy folder, then I typed the commands avrdude to see the list of commands to upload it, and then remembered that the instructor of out FAB Academy sent us a power point presentation with the steps to do it, so I went looking for it. So I typed the commands, plugged my programmer (that was already connected to my board) into my computer and hit enter.

Done all this I forgot a minor detail, and that was to put a delay between readings, that way I  basically created a Random Number Generator, which was not my purpose for this assignment.

After fixing this I fixed the intervals a couple of times and proceeded to upload it again.

 

I later tried to make a program on atmel studio, but could not find how to export it or upload it, and the tools on the program do not seem to work. You can download the compressed folder of the files I made for this assignment here.