IPC Class 3 Labs

Lab 1: Digital Input and Output

Here you can see that when the button is off, the yellow LED is on. But when I press the button, or it’s “on”, the red LED turns on.

This shows how I’ve connected a digital input circuit and a digital output circuit to a microcontroller.

The code is written to expect the button as an “input”, and change the “output” or behaviors of the LEDs depending on the state of that input.

giphy red and yellow leds.gif

Lab 2: Analog Input

When I turn the knob of the potentiometer, the LED’s brightness turns up or down, and those readings are sent to the serial monitor.

I did this by connecting a variable resistor to a microcontroller and reading it as an analog input. This means that the program is understanding that I’ve changed the conditions of the physical world (me turning the knob of the potentiometer) and converted them to changing variables (turning a LED’s brightness up and down, and printing the numerical change to the serial monitor).

The code:

There are global variables written for the analog value of the potentiometer, brightness of the LED, and the pin number of the LED.  The serial monitor is set up and the LED is declared as an output. Then we read the value of the potentiometer, turn that into another value that can control the brightness of the LED, and print that value of brightness to the serial monitor.

Questions: Why don’t we have to set the potentiometer as an input in the setup function? Why don’t we have to declare a global variable for the pin number of the potentiometer?

giphy potentiometer and led

Below you can see the value of brightness changing in the serial monitor. The numbers are between 0 and 255 because of how we translated the range of the potentiometer to something the computer could remember/process and send to the LED.  We did this by dividing the range of the potentiometer by 4, which fits into a BYTE…  which can only fit 8 BITS… which can only include up to 255 values. I don’t know why we divide by 4, or really fully understand base two or binary notation!

giphy serial monitor of potentiometer and led