Posts

Showing posts from September, 2019

Project 1 - Switches and Analogs

My post will be a little light on fritzing pictures because somethings wrong with my installation. As a summary I attached a joystick (2 analog inputs) to control the brightness of two LEDs separately. The two LEDs are above a light sensor (1 more analog input) that detects the changes in brightness and uses that to turn either a red or a green LED on. For the digital inputs I used two buttons to control which one of a 4x4 grid of LEDs was on. Getting the analog circuit to work was mostly an exercise in sensor calibrating and value mapping. To get the Joystick to output a value from 0-255 instead of ~500 to 1023 in one direction and  0 to ~500 in the other took some creative math. I ended up taking the value of the joystick in the setup method and subtracting that then taking the absolute value and now the joystick increases the brightness no matter which direction you use it on. Getting the light sensor to detect the change from 2 LEDs was more of a pain. I had to take the value in

Sensors & I/O

Image
     For the first part I spent some time getting set up with Fritzing and the Arduino IDE then got setup with the basic button example that was provided. The example worked great out of the box so it was pretty easy to modify it to use different inputs and outputs by changing the variables and the ports the wires were plugged into. I chose 4 as the button input and 12 as the new output and I also moved the LED to the breadboard with a resistor.      The second part was more of a programming challenge I wanted to try for double click toggling the state of the LED and a long hold turning it on for as long as the button was held after the button was released. I used the same circuit layout as part on for this section.      The double click was the harder one but I ended up with a click counter and a click delay variable. Each time the buttons state changed it compared the time the last state change was with the current time to decide if it should count as a click and then increment t

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 t