16/10/17 Processing Self-Portrait and Rectangle Assignment

SELF PORTRAIT

For the first part of this assignment, I adapted the ‘random circle’ sketch we made in class to create my self portrait. I altered the size and colour of the background, and decreased the circle size. The code randomises the circle colour, and will draw circles whenever the mouse is pressed.

Portrait painting CODE:

FIVE RECTANGLES

I found a processing article about rectangles that showed how you could alter the curvature of the rectangles corners. Adding an additional parameter allows you to vary the radius of the curvature for all corners, whilst adding four more parameters allows you define the curvature for each corner.

I also incorporated a rotation of the background so that the five rectangles also play in circles across the screen (see below videos and code).

 

Five Rectangles CODE:

 

11/10/17 Motors! Lickity Lick

I have this one friend who is always licking people — this project is for you, Shrew.

I originally wanted to use a DC motor with a piece of card attached to it so that when it spun, it would hit the back of the tongue and cause it to wriggle. But the motor wasn’t strong enough and would stall when it came within slight contact with the cardboard. I ended up creating a really simple circuit with a servo instead.

SCHEMATIC:

CODE:

 

9/10/17 Whimsical Project — Murderous Roomba! and Laine’s project

I found a Roomba in the junk shelf, and was inspired by the Instagram post below:

Halloween is coming up, so creating a murderous roomba seemed the appropriate approach for my whimsical project.

I inserted a bend sensor under the nose of the roomba so that when it runs into things, the bend sensor changes resistance and acts as a switch. When the bend sensor is activated, it makes three servo motors flick to 180 degrees, and then alternate between 180 and 90 degrees until the bend sensor is deactivated/ there is nothing in the roomba’s path. When the path is clear, the servos retract back to 0 degrees. I strapped broken pieces of acrylic to these servos so that they look like knives that pop up and wriggle whenever the roomba encounters an obstacle. The wiring for the bend sensor runs along the roomba’s underside to the Arduino, breadboard, and 9V battery pack which is stored in the roomba’s back compartment.

 

CODE:

SCHEMATIC:

 

Laine’s Project:

Laine’s project was a foam mouth with buttons for teeth — if you pressed the ‘achy’ tooth then the mouth would close on your hand. The ‘achy’ tooth would change each round, kind of like whack-a-mole. I found this project rather adorable and enjoyed the surprise whenever the mouth would close. However sometimes the ‘achy’ tooth wouldn’t change and the same button would cause the mouth to close. Overall I really enjoyed her project!

HW#8 2/10/17 Light Instrument

Using 4 LDR’s each connected to a speaker, I created a musical instrument that responds to light intensity. You ‘play’ the light instrument by sliding perforated panels over openings in a box, altering the amount of light received by the LDR’s within said box.

Each breadboard has an LDR and speaker. These breadboards are then inserted within the cardboard box with cardboard dividers in-between them so that they each only receive light from the opening controlled by the sliding panels. 

 

^^ demonstrating how the LDR’s respond to variations in light, and the associated sound this produces.

^^ Inserting the breadboards and their panels into the cardboard box.

^^ the completed light instrument with sliding panel controls.

HW #7 Simple Instrument — Lemon in a Cup

 

I decided to use the flex sensor for my instrument, which simple involves dropping a lemon (or any inanimate/ animate object) into a plastic cup. It’s like a wholesome version of beer pong involving fruit! The circuit is button activated. When on dropping the lemon into the cup, it bends the flex sensor causing an audible response from the buzzer. The flex sensor is mapped to the buzzer, so it will play notes that correspond to the degree of bend. I plan on elaborating on this project by adding more cups, and having each cup play a different tune when an object is dropped into it.

CODE:

 

HW #6 — Servo, button, buzzer and flex sensor

This circuit consists of a piezo buzzer whose tone is altered via a flex sensor, a servo motor, and a push button which activates/ deactivates the entire circuit. I mapped the sensorValue of the flexSensor to the tones of the buzzer so that for the different resistances that the flexSensor experiences when you bend it, a different tone will sound on the buzzer. This loop and the servo motor will only activate when the button is on. When the button is off, I use the noTone ( ) command to turn off the buzzer, and stop the movement of the servo by setting it to a single position (myservo.write(0);). The next step with this circuit will be to have the servo motor also move in response to the flexSensor.

 

— CODE —

 

HW#5 Servo and LDR

In this circuit, the servo changes speed depending upon the light intensity (sensorValue of the LDR). The servo will change its angle by increments of +/- 1 if sensorValue < 500, and will shift to increments of +/- 5 if sensorValue >500. See below schematic, demonstration video, and code for details.

 

 

Servo/LDR demonstration

 

 

HW #4 — Fading, Serial.println, and Blink without Delay

FADING

Although both codes create the same effect, the main difference I could distinguish between the fade tutorial and Arduino’s fade program was the use of ‘logical or’ as opposed to two for ( ) loop commands. The tutorial uses ‘logical or’ to create the parameters for which the LED should fade, and then defines the degree by which this fade will occur by the variable ‘fadeAmount:’

 brightness = brightness + fadeAmount;    //increase the brightness by 5 points

if (brightness <= 0 || brightness >= 255) {   
    fadeAmount = fadeAmount}      //if the ‘brightness’ is less than or equal to 0, OR greater than or equal to 225, the fadeAmount is inverted, so that in the next loop the LED will fade out by increments of -5, or fade in by increments of +5.

On the other hand, the fading program in the Arduino software sets up two for ( ) commands. The first initialises fadeValue as 0 once, and then tests if the fadeValue less than or equal to 255 — as long as this statement is true, the fadeValue will be increased by 5 points, otherwise the loop will end. Once that for ( ) loop ends, the second for ( ) command initialises fadeValue to 255 once, then tests whether the fadeValue is greater than or equal to 0 — if this is true, the fadeValue will decrease by 5 points, otherwise the loop will end and the initial for ( ) loop will take over again. 

SERIAL.PRINTLN ( )

Below is the code using Serial.println ( ) to display the values for LOW, HIGH, A0, and LED_BUILTIN. IN order to only print the values once, I created the code in void setup ( ).

As you can see in the below screenshot of the serial monitor, the values actually printed twice, and two of my variables share the same line — I am unsure why this is happening.

BlinkWithoutDelay

This code blinks without delay, so that other programs can run without the delays imbedded in a typical ‘blink’ code slowing down the entire sequence.

This is achieved by using millis ( ) to return the number of milliseconds since the board started running its current sketch. Millis ( ) is given the variables previousMillis (previous blink of LED) and currentMillis (current blink of LED). If the difference between these two values is greater than the interval of time you want between blinks, then it is time to blink the LED. PreviousMillis is set to currentMillis, effectively saving the last time the LED blinked:

if (currentMillis – previousMillis >= interval) {

previousMillis = currentMillis;

Then, the LED state is changed:

if (ledState == LOW) { ledState = HIGH; }

else { ledState = LOW; }  

digitalWrite(ledPin, ledState); }

Serial.println ( ) is used to print the value of previousMillis, currentMillis, and ledState when the if ( ) statement is correct and the LED is being ‘blinked.’

 

In Class Question — serial.print

HW#3 LED fade with analogWrite

Using analogWrite( x ) and delay ( 100 ), I created a ‘fade’ for two LEDs — red and yellow. I varied x (over a range of 10-250) to create different brightnesses for the LED, and spread these out with delay in order to create the ‘fade.’ Initially I ran both LEDs in loop ( ) (see below video).

both LEDs in loop

I then moved the code for the yellow LED to setup ( ), which resulted in the code only running once, as opposed to ‘looping’ along with the red LED.

Yellow LED in setup

I did set up a serial.print for the output after defining the LEDs as said outputs, but the serial monitor only displayed 0. I am still unsure why this is the case, and hope to resolve this issue in our next class.

CODE:

int red = 3;
int yellow = 5;

int outputValue = 0;

 

void setup() {
pinMode(yellow, OUTPUT);
pinMode(red, OUTPUT);

Serial.begin(9600);

analogWrite(yellow, 250);
delay(100);
analogWrite(yellow, 200);
delay(100);
analogWrite(yellow, 150);
delay(100);
analogWrite(yellow, 100);
delay(100);
analogWrite(yellow, 50);
delay(100);
analogWrite(yellow, 10);
delay(100);

analogWrite(yellow, 50);
delay(100);
analogWrite(yellow, 100);
delay(100);
analogWrite(yellow, 150);
delay(100);
analogWrite(yellow, 200);
delay(100);
analogWrite(yellow, 250);
delay(100);
}

void loop() {

Serial.print(“\t output = “);
Serial.println(outputValue);
delay(1);

analogWrite(red, 250);
delay(100);
analogWrite(red, 200);
delay(100);
analogWrite(red, 150);
delay(100);
analogWrite(red, 100);
delay(100);
analogWrite(red, 50);
delay(100);
analogWrite(red, 10);
delay(100);

analogWrite(red, 50);
delay(100);
analogWrite(red, 100);
delay(100);
analogWrite(red, 150);
delay(100);
analogWrite(red, 200);
delay(100);
analogWrite(red, 250);
delay(100);

 

}