post #3

IMG_2626

 

For this circuit, we had to create a analog code and a loop code. I used two resistors (330), two LEDs (one red one yellow), three wires, breadboard, and the redboard battery. The idea of this exercise was to create a fade in fade out effect. For the red LED, I coded in setup () and for the yellow LED I coded in loop (). This made the red LED increase in brightness, then decrease in brightness, and stop. However, the yellow LED kept this behavior going due to the loop. Attached is my code, my schematic, and a video of the circuit.

Code:

int red = 11; // LED 1
int yellow = 10; // LED 2

 

void setup() {
// put your setup code here, to run once:

analogWrite (red, 0);
delay(200); // wait
analogWrite (red, 75); // gets bright
delay(200); // wait
analogWrite (red, 175); //gets brighter
delay (200); // wait
analogWrite(red, 225); // gets brightest
delay (200); //wait

//then do the opposite thing

analogWrite (red, 225); //brightest
delay (200); //dims
analogWrite (red, 175); //brightness is lower
delay (200); //dims
analogWrite (red, 75); //brightness lowers
delay (200); //dims
analogWrite (red, 0); //nothing
delay (200); //end of red light

}

void loop() {
//loop is same idea as above but will keep loopin
analogWrite (yellow, 0);
delay(100);
analogWrite (yellow, 75);
delay(100);
analogWrite (yellow, 175);
delay(100);
analogWrite (yellow, 225);
delay (100);

//opposite thing

analogWrite (yellow, 225);
delay (100);
analogWrite (yellow, 175);
delay (100);
analogWrite (yellow, 75);
delay (100);
analogWrite (yellow, 0);
delay (100);

}

Leave a Reply

Your email address will not be published. Required fields are marked *