PHY-S-12-DOCUMENTATION

View the Project on GitHub tahafarhan1/PHY-S-12-DOCUMENTATION

11 July 2019

05: Programmable Electronics 15th July

by

Using Microcontrollers

In this class, our assignment was to make a microcontroller that had a button as an input and had an output. I chose to use three LEDs as my output. One LED (the green one) was supposed to be on when the button was not pressed while the red lights blinked alternatively once the button was pressed. The red light turned off once the button was pressed. This circuit used a generic breadboard, 4 resistors (3 220 ohm and one 10k ohm), 3 LEDs(1 green and 2 reds), a button and some wires. I used a template from the Arduino Project Handbook but I changed the code from an if/else type of code to a for loop. The for loop replaces the if/else code with a set of true or false statements that make the code smaller and easier. Unfortunately, I forgot to save the for loop code so I only had a copy of the if/else code.

`int switchState = 0;

`void setup(){ for (int n = 2; n <=5; n++) { pinMode(n, OUTPUT); } } ` void loop(){ switchState = digitalRead(2); // this is a comment if (switchState == LOW) { // the button is not pressed digitalWrite(3, HIGH); // green LED digitalWrite(4, LOW); // red LED digitalWrite(5, LOW); // red LED } else { // the button is pressed digitalWrite(3, LOW); digitalWrite(4, LOW); digitalWrite(5, HIGH); delay(250); // wait for a 2 second // toggle the LEDs digitalWrite(4, HIGH); digitalWrite(5, LOW); delay(250); // wait for a half second } } // go back to the beginning of the loop

Circuit

tags: