Comments on: Assignment 2: State Machines, switch/case, for() loops https://courses.ideate.cmu.edu/60-223/f2017/assignment-2-state-machines-switchcase-for-loops/ 60-223 Fall 2017 Tue, 07 Nov 2017 00:08:48 +0000 hourly 1 https://wordpress.org/?v=4.8.24 By: noell@andrew.cmu.edu https://courses.ideate.cmu.edu/60-223/f2017/assignment-2-state-machines-switchcase-for-loops/#comment-140 Mon, 25 Sep 2017 21:54:20 +0000 https://courses.ideate.cmu.edu/60-223/f2017/?p=138#comment-140 I want to change the LEDs’ behavior (speed or color alteration) based off of potentiometer reading
I used the serial Monitor to read the min and max analog values for the potentiometer- they range from 90 to about 950
We can map the potentiometer readings onto an integer var value (connected to labels 1 through 4) that the switch case loop will read to decide how LEDs behave.
My Arduino and I have a rocky relationship. We are trying to communicate and our therapist recommended a flowchart for me to organize my thoughts before talking to it. What do I want it to do? How will it do it?

Int var = map (potReading, potMax, potMin, 1, 4)
Proposed Plan:
Case 1:
Range 1- consistent red
Case 2:
Range 2- consistent blue
Case 3:
Range 3- red and blue slow alteration
Case 4:
Range 4- red and blue fast alteration
https://www.arduino.cc/en/Tutorial/SwitchCase was used to be familiarized with the format of code. I initially found that there were not 4 distinct cases being shown, case 1 and 2 just seemed like they stayed on all the time. I adjusted my code so the potentiometer value range was smaller, starting from 200 (arbitrary number greater than 90). I still can’t get the potentiometer to read correctly every time though.

Code, pictures, video and documentation (full) are in the drive:
https://drive.google.com/drive/folders/0B6vucT1cFrpgMTBkLUFkZXFPWWs?usp=sharing

]]>
By: yihanz@andrew.cmu.edu https://courses.ideate.cmu.edu/60-223/f2017/assignment-2-state-machines-switchcase-for-loops/#comment-139 Wed, 20 Sep 2017 13:19:33 +0000 https://courses.ideate.cmu.edu/60-223/f2017/?p=138#comment-139 My project is based on the idea of a physical/digital calendar. By pushing a button, that means a new day for this machine. The leds can try to tell people the different information: which day is it in this week, is today a solar term. The highest angle of the sun for the day throught the servo (based on the location in pittsburgh).
Swiching into a different mode, the leds will switch from day mode to night mode. In night mode, the leds will tell different information about the moon, is it a full moon? How full will the moon be tonight.

In this project, I had lots of syntax problems, besides that the servo didn’t work for the first several tries. Besides that, the delay in the program was a bit too long for the first time and sometimes it doesn’t register the button push. However, in one mode, the button register too fast, creating other problems.

https://drive.google.com/a/andrew.cmu.edu/file/d/0ByluH07JIf_MT1JpUkRDcUw2ems/view?usp=sharing

]]>
By: J Eric Townsend https://courses.ideate.cmu.edu/60-223/f2017/assignment-2-state-machines-switchcase-for-loops/#comment-138 Tue, 19 Sep 2017 23:20:27 +0000 https://courses.ideate.cmu.edu/60-223/f2017/?p=138#comment-138 this is a test reply

]]>
By: ceckrich@andrew.cmu.edu https://courses.ideate.cmu.edu/60-223/f2017/assignment-2-state-machines-switchcase-for-loops/#comment-137 Tue, 19 Sep 2017 06:06:49 +0000 https://courses.ideate.cmu.edu/60-223/f2017/?p=138#comment-137 For this assignment I made a very straightforward counting mechanism. I used the framework from my last assignment, simply switching the IR distance sensor out for a tactile switch. I counted the number of times I pressed this switch, and the displayed that on the line of LEDs. After they were all lit, the counter reset. I then added several other patterns using for loops to generate the flashing repetition of the LEDS.

I had quite a bit of trouble getting the counter to work with a for loop, and ended up using a workaround with several if statements to do the counting of the button presses. The switch cases were relatively straightforward after I figured that out.

If I were to add something to this, I would make each of the switch cases display something more interesting than simply a counter or a random pattern. Perhaps I could set each case to display the count in binary, doing so using a sequence instead of hard coding it like I did here.

link to zip: https://drive.google.com/open?id=0B_rqoxuDYou6ZlJCeHFHWHNjdnc

]]>
By: rnarayan@andrew.cmu.edu https://courses.ideate.cmu.edu/60-223/f2017/assignment-2-state-machines-switchcase-for-loops/#comment-136 Tue, 19 Sep 2017 04:17:04 +0000 https://courses.ideate.cmu.edu/60-223/f2017/?p=138#comment-136 For my project, I implemented an “occupied bathroom switch” for both female and male restrooms. A lever switch turns on and off the LED sign depending on whether or not the door is closed. Another switch determines whether or not to display the female sign or the male sign.
I used a small 8×8 matrix to display the information.

I had the most trouble getting the switches to give me reliable information. I had to set my lever switches’s pin mode to INPUT_PULLUP to get it to give me the values that I wanted. There is some flickering on the LED screen due to the lever switch that persists but that is hard to control because I’m using a lever switch as an on off button. I tried using a momentary switch instead but it made less sense to me so I switched back to a lever switch

Link to code and documentation: https://drive.google.com/drive/folders/0B3_nRvY5FHyHQ0lldkQ5QUVKdjg?usp=sharing

]]>
By: etbrenna@andrew.cmu.edu https://courses.ideate.cmu.edu/60-223/f2017/assignment-2-state-machines-switchcase-for-loops/#comment-135 Tue, 19 Sep 2017 03:59:59 +0000 https://courses.ideate.cmu.edu/60-223/f2017/?p=138#comment-135 My idea was to create a traveling light game, based on the position of switches. I wanted the light to be able to react and change speed based on how many switches were blocking the light’s path.

The google drive contains my process, project and reflection.
https://drive.google.com/drive/u/3/folders/0BxP5AAHGNXBAbmR2dG5tRnVJWG8

]]>
By: madelynl@andrew.cmu.edu https://courses.ideate.cmu.edu/60-223/f2017/assignment-2-state-machines-switchcase-for-loops/#comment-134 Tue, 19 Sep 2017 03:56:38 +0000 https://courses.ideate.cmu.edu/60-223/f2017/?p=138#comment-134 For this assignment, I built off of the previous assignment. My idea was to create an interactive light display that replicates a ripple effect that directly corresponds to the motion of the user. It works in a way that requires the user to wave their hand over the light display, and the speed at which they move their hand will be reflected by the speed of the ripple effect in the LED display. I incorporated different modes of the display to fix the issues that I encountered before. In the modified version there is now a calibration mode that assesses the environment and the amount of light that the display is exposed to. Using this information the display can then store the highest average exposure value and use it as a reference for detecting the shadow of the moving hand. This is particularly important in darker environments where the difference in exposure is smaller and the maximum brightness is considerably low. Once the display goes through the calibration mode, it can then accurately detect the shadow and run the ripple mode.
https://drive.google.com/open?id=0B62ArY8nFitqMXRFUGxfcFU4Nmc

]]>
By: gbalakr1@andrew.cmu.edu https://courses.ideate.cmu.edu/60-223/f2017/assignment-2-state-machines-switchcase-for-loops/#comment-133 Tue, 19 Sep 2017 03:45:07 +0000 https://courses.ideate.cmu.edu/60-223/f2017/?p=138#comment-133 In my opinion, it is possible to find ways to describe any system as a state machine. That’s what makes them so interesting to me. When given this project, one of my first ideas was to create a simple device that can detect when a person is being followed at night. The motivation for this was because of the way I feel when people close to walk places alone late at night.
To do this, I decided to use the following components: Switch, Resistors, Photoresistors, PIR(Passive Infrared) Sensor, LED Matrix on an Adafruit LED Backpack, and a vibration motor. The concept of this project was to design a potentially wearable device that would warn someone of when they are followed. The photoresistor is placed on the face of the watch near the lED matrix. The PIR sensor can be worn as an addition to a person’s backpack. This device has 4 major operating states. There is a switch, when turned off the system is idle. That is, the device is not in the active mode for safety. It displays a graphic of an open switch on the LED matrix indicating that the device is not engaged. The second state occurs when the switch is turned on and the photoresistor detects that there is still light out. In this state, the LED matrix displays a smiley face indicating that all is good. However, when the photoresistor reads a value below the threshold, it switches into the third state. In this state, the LED matrix displays an eye indicating that the system is engaged and the PIR sensor is working. The 4th state is when the PIR sensor detects an object and this fires of the alarm. In this state there is a flashing screen and the vibration motor goes off.

In doing this project, I was stuck for a long time because no matter what I did the photoresistor and PIR sensor were always reading high values. I tried different values of resistors for “pull-down” and nothing was seeming to work. On getting a second pair of eyes on the circuit, I found that the lead that was meant to be connected to ground was actually connected to a different pin. This was a big lesson: when something is not working, check the simplest parts of the circuit. It is easy to not connect leads in the pin you were not intending to. I also learnt that it is important to tune sensors like the PIR sensor and photoresistor to the surroundings you expect to be working in. For example, a PIR sensor will work differently in the dark as it will in daylight.

If I were to work on this further, I would want to really fine tune my sensor parameters. I would also prototype the actual wearable and see if it is a feasible design. I would also want to make the code more robust and make sure it works for all cases. I want to create some sort of input, maybe a potentiometer, for the photoresistor threshold such that the person can pick when they want this device turned on.

Link to drive (pictures and code): https://drive.google.com/file/d/0Bz7Or4Zn580Cb0VHNVdYNzJ5cWc/view?usp=sharing
Link to YouTube: https://youtu.be/EC0nI5keNt0

]]>
By: soojins@andrew.cmu.edu https://courses.ideate.cmu.edu/60-223/f2017/assignment-2-state-machines-switchcase-for-loops/#comment-131 Tue, 19 Sep 2017 03:30:45 +0000 https://courses.ideate.cmu.edu/60-223/f2017/?p=138#comment-131 For this assignment, I controlled different patterns of lighting of 5 colored LEDs, -red, yellow, green, blue and white- using a button and a potentiometer. With the use of switch cases and for() loops, the button will work as the switch that chooses which light to be brightened up for the amount of times it has been pressed so far. So for instance, when pressed once, the red LED will light up and blink for once; when pressed the second time, the red LED light will turn off and instead, the yellow LED will light up and blink twice, and so on. The potentiometer would be the controller of the brightness of the LED currently lit.

Drive Link: https://drive.google.com/drive/folders/0B70fyRiHk85qWUtYcjNxUFlTYk0

]]>
By: stnorman@andrew.cmu.edu https://courses.ideate.cmu.edu/60-223/f2017/assignment-2-state-machines-switchcase-for-loops/#comment-130 Tue, 19 Sep 2017 02:54:38 +0000 https://courses.ideate.cmu.edu/60-223/f2017/?p=138#comment-130 For this project I utilized my previous configuration and implemented for () loops, switch/case, and a state machine to meet the requirements of this project. My previous code was all about 5 inputs that would turn on a light if pressed in the right order as well as an analog reading from the photo resistor. I proceeded to remove one of the 5 buttons as well as the photo resistor and work from the left over 4 inputs A-D. Since I am new to Arduino coding I did a very simple configuration in which each of the 4 buttons would make the LED behave differently. InputA would make the LED flash rapidly, InputB would make the LED pulse slower, InputC would make the LED fade from off to on, and InputC would make the LED fade to off. I practiced by trying to figure out the statement to fade on and once figured out reversed that to have it fade off and then copy pasted that into my for()loop. The rest of the commands were pretty simple.

youtube video link- https://youtu.be/lUm5E2ytEoQ
link to code- https://drive.google.com/drive/folders/0B_JEXda9ZXwvem9yRks3LUlrcXM?usp=sharing

]]>