In previous weeks, we made an ISP programmer and an echo board; now we are tasked with making the board do something. I'm spending much of the week just familiarizing myself with C. Brian gave the Harvard section a great introductory talk.
I'm using my ISP programmer, IDC ISP cable, and hello board from the previous weeks. I decided to use Sublime as an IDE, as I like the syntax styling and the simplicity of the environment (I looked at Arduino too as an IDE).
First, I wrote a program to just turn on the LED when the program is run - I wanted to make sure that my board was working, and that I could get some kind of program going. I started from Neil's echo board code (which we used previously) and modified it. I looked at the Attiny45 data sheet to figure out what port pins I needed to use to reference the LED and the button (PA7 and PA3).
For my first program, I added the following to the echo board code:
I ran the code and the LED lit up - success!
I then wanted to make it so the LED would light up when the button was pressed. I wrote this:
But when I ran it, nothing happened. The LED remained lit, and unresponsive to the button. I checked my board with the voltmeter, and all the connections seemed fine. Brian looked it over and wondered if perhaps there was an issue with the pull-up resistor (which is on my board for the button); he said it was better practice to just program pull-ups in the Attiny, and that I should try removing the resistor with a heat gun in case that was part of the problem.
But the program still failed to run, even after this fix. At this point Brian realized that I'd made an error: I was running a bit test, but I actually needed to be running a pin test, because I'd set up the program in terms of pins.
Once I changed the bit test to a pin test, the program ran and worked!
I was confused about the relationship between bits and pins; Brian talked me through Boolean logic with binary numbers.
I asked him why we had the option to write the same program in either bits or pins; he said that either would work, so as an exercise we ran the program again, but rewritten in terms of bits instead of pins. And that worked, too.
Next I want to figure out timers and interrupts, especially since I might be working with motors during outputs week.