🗓 Week 8

Embeded Programming

This week, we went over the history and foundations of a computer from the very beginning. We started discussing the difference between analog and digital forms of machines and the cause of this transition, which was based on scalability and accuracy over time. We continued comparing differences between specific functions of components; the microcontrollers v. microprocessors and operative systems v. firmware, in order to understand how to make efficient choices when designing our own electronics.

Reviewing the depth of these programs and libraries, I was reminded of the complexities behind each seemingly simple function we use on a computer. But understanding the basics of how the computer works or how to program a microprocessor, will give me the platform to start a simple project.

Some key things to consider when working with microprocessors:
  • decisions are immediate
  • keep things simple and clear: machines are stupid!
  • always spend time on creating a flow chart with clear steps
  • always the same answers to same questions
  • when something goes wrong it’s human error or machine failure
Assignment: I coded an LED light to turn on and off depending on the light the phototransistor sensor was detecting. This assignment is an extension of my input/output task, where I designed, milled, soldered, and coded my own PCB. I made a simple arduino code based off of examples. In the first part of the code, I define the constants: the pins and the analog threshold (for the sensor function). In the following section, I set up the light sensor to output mode and add a serial begin code which will print the values of what the sensor is detecting (light). After the setup, I define what the code will be doing on a loop: reading the value of the sensor and printing it, and if the value is greater than the anaglog threshold (500) defined in the first part of the code, set the LED pin to high or on, if the value is lesser than the analog threshold, set the LED to low or off.

The arduino code below:
const int LIGHT_SENSOR_PIN = A7; // Arduino pin connected to light sensor's pin
const int LED_PIN = 5; // Arduino pin connected to LED's pin
const int ANALOG_THRESHOLD = 500;

int analogValue;

void setup() {
pinMode(LED_PIN, OUTPUT); // set arduino pin to output mode
Serial.begin(9600);
}

void loop() {
analogValue = analogRead(LIGHT_SENSOR_PIN); // read the input on analog pin
Serial.println(analogValue);

if(analogValue < ANALOG_THRESHOLD)
digitalWrite(LED_PIN, HIGH); // turn on LED
else
digitalWrite(LED_PIN, LOW); // turn off LED

delay(100);
}