Exercise 2 - Blink

     This part was fairly simple all I had to do was plug in the Arduino, install the IDE, and download the repository. The only change I had to make to the code was to change the spelling of the offTime variable to match throughout the program.

     The program works by setting pin 13 to OUTPUT mode then changing the output between on (HIGH) and off (LOW). The delay function is used to add spacing between the outputs.

     To change the rate the LED was blinking I changed the onTime and offTime variables which are just the amount of time the delay function should wait, measured in milliseconds.

      For the third part I used the bread board since I would need two output pins and both would ned the GND pin. To add the second pin I added a second pin number variable and made sure to set it up in OUTPUT mode in the setup function. Getting them to alternate being off and on was just an extra two lines to control the second LED in the loop. The biggest difference I could tell from the previous parts is that the LEDs were much dimmer with a resistor in the circuit .

     Starting the three LED section I decided to use a different colored wire for each pin so I could keep track of which was the red, green, and blue LED. I also figured out that a 10k resistor instead of a 220 which is why they were so dim. For this one since the loop was getting kind of long I wrote a separate function that takes in a pin and turns it on then turns it off after the onTime has passed. This made it easy to sequence the LEDs so they blinked in order going up and down the line.

     For the Morse code I changed the onTime and offTime to onShort, onLong, offShort, offLong, and offLonger then used the on variables for short and long flashes respectively and the off variables for the pauses for the delay between signals, letters, and words respectively. This worked pretty well for short messages but if I wanted to make a longer message or make it easy to change the message I would want a function that can translate a string to signals instead of having to do it manually.

     For the avoiding delay() part I assumed that the solution would be to compare the time the LED was turned off/on to the current time to see how much passed because I had to do a similar thing for a discord bot I made. I eventually found this tutorial  (Blink Without Delay) and modified my previous code to use that method and checking the time against the various delay variables.

     



Comments