Author Archives: alivulpe

Arduino 8 key piano

Hey friendos,

Today I’m gonna show you a tiny little thing I built during Jterm and only now got to post. This is a tutorial on how to make your very own very basic piano using Arduino. The diagram is a bit crowded but it’s really not that complicated to make. 

Image

 

You will need 8 resistors, 8 buttons, 20 wires, one piezo speaker. And your Arduino and bread board of course. 

The code for this is as follows:

int button_C = 2;
int button_D = 3;
int button_E = 4;
int button_F = 5;
int button_G = 6;
int button_A = 7;
int button_B = 8;
int button_Cup = 9;

int speaker = 13;

int buttonstate_C = 0;
int buttonstate_D = 0;
int buttonstate_E = 0;
int buttonstate_F = 0;
int buttonstate_G = 0;
int buttonstate_A = 0;
int buttonstate_B = 0;
int buttonstate_Cup = 0;

//NOTES         'c'  , 'd',  'e',  'f',  'g', 'a',  'b',  'C'
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 }; //freq
int Cur_tone = 0;

void setup()
{
  pinMode(button_C, INPUT);
  pinMode(button_D, INPUT);
  pinMode(button_E, INPUT);
  pinMode(button_F, INPUT);
  pinMode(button_G, INPUT);
  pinMode(button_A, INPUT);
  pinMode(button_B, INPUT);
  pinMode(button_Cup, INPUT);

  pinMode(speaker, OUTPUT);
}

void loop()
{
	buttonstate_C = digitalRead(button_C);
	buttonstate_D = digitalRead(button_D);
	buttonstate_E = digitalRead(button_E);
	buttonstate_F = digitalRead(button_F);
	buttonstate_G = digitalRead(button_G);
	buttonstate_A = digitalRead(button_A);
	buttonstate_B = digitalRead(button_B);
	buttonstate_Cup = digitalRead(button_Cup);

	if((buttonstate_C == HIGH) || (buttonstate_E == HIGH) || 
		(buttonstate_G == HIGH) || (buttonstate_D == HIGH) || 
		(buttonstate_F == HIGH) || (buttonstate_A == HIGH) || 
		(buttonstate_B == HIGH) || (buttonstate_Cup == HIGH) )
	{ 
		if (buttonstate_C == HIGH)
		{
			Cur_tone = tones[0];
		} 
		if (buttonstate_E == HIGH)
		{
			Cur_tone = tones[1];
		}
		if (buttonstate_G == HIGH)
		{
			Cur_tone = tones[2];
		}
		if (buttonstate_D == HIGH)
		{
			Cur_tone = tones[3];
		}
		if (buttonstate_F == HIGH)
		{
			Cur_tone = tones[4];
		}
		if (buttonstate_A == HIGH)
		{
			Cur_tone = tones[5];
		}
		if (buttonstate_B == HIGH)
		{
			Cur_tone = tones[6];
		}
		if (buttonstate_Cup == HIGH)
		{
			Cur_tone = tones[7];
		}

		digitalWrite(speaker, HIGH);
		delayMicroseconds(Cur_tone);
		digitalWrite(speaker, LOW);
		delayMicroseconds(Cur_tone);
	}
	else //in case no button is pressed , close the piezo
	{
		digitalWrite(speaker, LOW);
	}

}

(adapted from godspeech.wordpress.com)
Advertisements

Sound and pitch change with Arduino

Warning: this is a really really annoying little project. If you want to irritate everyone around you, then this project is for you.

My initial idea was to connect more than one pressure sensor to it and make it like a miniature piano. But I could only find one pressure sensor so I made do with it. 

Diagram:

Image

 

The code I used for this is really simple. I used the tone() function to code for what would normally be 5 lines of regular code.

int speakerPin = 12;
int pressurePin = 0;
 void setup()
{
}
 void loop()
{
  int reading = analogRead(pressurePin);
  int pitch = 200 + reading / 4;
  tone(speakerPin, pitch);
}
 
 
When you apply pressure to the sensor, the pitch of the note will change. It’s really annoying though so use with caution. 

Measuring temperature with Arduino

Hi guys!

Here’s a fun little thing you can do with your Arduino. If you don’t have a thermometer but would still like to know the temperature in your room, you can build one using the temperature sensor found in the basic kits for Arduino. 

Image

 

I had to turn the sensor around in this diagram so you could actually see where the wires go. For pin 1 (which when the sensor faces you with the flat side is the left most one, but in this it’s the right most one), you will attach your power line (in this case 5V). Pin 2 goes to an analog source (A1 in my case) and number 3 is your ground pin.

Arduino code:

int tempPin =1; //this is the analog pin you’re connected to

void setup()
{Serial.begin(9600); //serial port connection to the computer

}

void loop()
{

int tempRead = analogRead(tempPin); //voltage reading from sensor
Serial.println(tempRead); //puts out the reading in the serial monitor
int tempC = map(tempRead, 0, 1023, -50, 450); //your values will be from 0 to 1024 which you then convert to your degrees using the map function

//10mv correspond to 1 degreeC
Serial.print(“new temp: “);
Serial.println(tempC);

delay(200);
}

Fixing black and white drawings in Photoshop

Hey guys, here’s a quick tutorial on how I personally fix my drawings using photoshop. I hate that my portraits look real nice and crisp in real life, but once they get scanned, it’s like all the black got sucked out of them and I’m left with a greyed out mess that doesn’t look nearly as nice as the original. Luckily, you can use photoshop to tweak some things and make your drawings look more like you want them.

For this tutorial, I’m going to use this portrait I did of my friend Jon. 

Image

 

As you can see, the scanner did a weird job of the proportions, and the colors look off and patchy. What I first did was use the Rectangular Marquee Tool and made a selection of the part of the drawing I wanted to keep and pasted it into a new window (that way I got rid of the white margin that came out from the scanner going over the page). Next, I used the Free Transform option to rescale the image so it wasn’t so stretched out.

Image

 

Much better in terms of proportions! Next, let’s try to fix the color. In the original, the background was pitch black, but some of the color lifted in the scan. Next thing is to duplicate the layer (right click the current layer tab and select Duplicate layer). This way we can make adjustments and go back to the original if we don’t like it.

For black and white drawings, I like to go to Image> Adjustments> Black and White. This way when we mess around with the levels and curves we don’t get a weird green cast. But this still doesn’t bring the black back into the drawing.To bring it back, we can use the nifty Levels options. 

Image

 

 

Dragging the arrows around allows you to lighten and darker the tones of your pictures. I like to drag the left most one quite a bit in, which effectively darkens the background and shadows that otherwise wouldn’t be showing. 

Image

After tweaking the arrows for a while, this was my end result. More techniques could be used, like using the Burn tool to further darken some areas to make them blend better, like the shadows in the hair. But for now, this will do. 

Image

 

The finished product.

I hope you learned something new and hopefully this will be useful for you when you’re trying to fix your scans!

Image/face swaps

Honestly my most favorite thing to do in Photoshop is mess around with my friends and put their faces onto different bodies. Today, we’re going to put my friend Steven’s face onto Marilyn Monroe’s body. Why? Truly the real question would be Why not. 

Here’s the images we’ll be working with:

Image

Steven looking marvelous. Dashing.

Image

 

This image of Marilyn in the iconic pose.

First thing you’ll want to do is open both images in Photoshop. Keep in mind that this is just how I do it, but you can mess around with the tools and adjustments to your liking until you find something that works for you. 

I like to use the Lasso tool to make a rough selection around Steven’s face

Image

 

Then you’ll want to copy and paste your selection into the window containing your stock photo of Marilyn. I like to hold down CTRL+C (command+C on Mac) and then CTRL+V to paste it. You’ll want to right click the selection in the new window and select Free Transform. That way, you can easily move and adjust the selection.

 Image

 

Position the head roughly proportional to the body for now. We’ll get into detailed work soon. Now, you can put the previous tutorial on Layer Masks to work. Having your head layer selected, click on the Layer Mask button Image

 

Making sure you have the Layer mask thumbnail selected, go ahead and paint in black what you want to hide of the selection, so it’s not as rough, but without deleting the pixels in case you mess up and need to go back easily. When you’re happy with the way it looks, it’s time to get to better arranging the head on the body. I like to decrease the opacity of the head layer until I can see what the real head looks like underneath, but I can still see details of the new one. 

Image

 

This is the most terrifying thing I’ve ever seen. Better get to fixing it quickly. Using the Free Transform option I was talking about earlier, it’s time to resize the head so it’s not five times the size it should be. make sure you have your proportions locked.Image

 

If you right click your selection after hitting Free Transform, you will get multiple options of adjusting your layer. Use Rotate and Scale in order to better fit the photo. If you’re feeling brave, use the other options such as Distort or Warp to better suit your needs. 

Image

 

When you’re happy with how the head is positioned and you’re done laughing, time to clean around the edges. In my example, you can see that Steven’s hair is much darker than Marilyn’s, and I prefer his better. So what I’m going to do is color over Marilyn’s hair in the color of the background to hide it. After that what I like to do is see what Photoshop can do for me in terms of color matching. 

Image

 

After messing around with those settings, and also going into Levels a little bit, I ended up with my final result, which by no means is perfect, but it makes for a good gag photo to laugh at. 

Image

 

I hope you had fun learning how to mess around in Photoshop some more! There’s many other things you can do to make this better, but for the sake of keeping this tutorial short, I’ve kept it pretty basic. Enjoy!

Photoshop Healing tools

Have you ever taken a really nice picture, only to discover in post processing that there were some dust specks on the lens? Or maybe there’s a whole object you’d like to be somewhere else. Whatever your issue, the quickest way of fixing is probably the Healing tool, instead of manually doing it with the brush tools. 

Image

 

Take this picture for example. Beautiful sky. Real nice. But, there’s some grey-ish specks all over the place. And a creepy looking Spongebob smiley face. 

In Photoshop, on the left vertical tool box menu, you will see a symbol of a bandaid. If you click the bandaid, a menu box will appear, with your options: the spot healing tool, the healing brush, the patch tool, the content aware move tool, and the red eye tool. In this tutorial I will be showing you how to use the Spot healing brush tool and the Content aware move tool. The latter is a new option for CS6 and it’s totally cool. 

Image

Using the Spot Healing Brush Tool is very easy. All you do is select the tool, and paint over the area you want to fix. Make sure the brush size is a little larger than the area you want to fix, but not too much. 

Image

 

Repeat this step for all the spots you have in your picture!

Content aware move tool comes in handy when you have something that you really want to be situated somewhere else in the photo. This is best achieved if the object you’re moving can suffer a bit of distortion (which tends to happen with the Content aware move tool.) and if you’re moving it to a similar background. 

Image

Let’s look at creepy Spongebob again. To move him around, all you have to do is select the Content aware move tool and start drawing your selection around him. As with the spot healing tool, make sure to leave yourself a little bit of a margin for easier blending. 

Image

 

 

Click it and drag it to wherever you want it to be positioned now.

Image

 

As you can see, the blending isn’t totally perfect and there’s distortion on the object. You can further fix the blending with the spot healing tool if you want. Again, this move tool is best used for things that can handle a bit of distortion. However, it’s a pretty neat tool to have when you think about the fact that before you had to use a whole lot of tools to get a similar result. Now it’s as easy as draw, drag and voila!

I hope you learned a new thing today and have fun using the Healing tools!

Introduction to Layer masks in Photoshop CS6

As a Photoshop user, and even as a straight-up beginner, you’ll probably come across a time where you need to manipulate an image, working with transparency but not removing the pixels. If you’ve been too scared to work with Layer Masks before thinking they were too tricky, well, they really aren’t! What you need to know is the difference between black and white.

What Layer Masks do is they control the transparency of an image. But you might say that you can already do that by using the Opacity option on the selected layer. Well yeah, but that only lets you increase or decrease transparency of the entire layer. What if you want to have just one part fade out and into a gradient for example? Or what if you want to blend two images together without an awkward line in the middle?

First, let’s open two images in PS.Image

After opening the images, they will be in separate windows. We will need them in the same window.

In order to bring one in the same window as the other, select the Move Tool, and simply drag one over the other.

Image

Both images are in the same window. As you can see, the second one is on a different layer, on top of the first.

(You may need to adjust the background layer so that they don’t overlap too much. In order to make adjustments to the Background layer, it must first be unlocked. In order to do that, it has to be made into a layer. Simply double click the Background layer tab.)

Now that you have both images in the same window, you might think that you could just use the Eraser tool on a very soft setting in order to delete the line merging them together. Well, you could, but what if you later decide that you want to show more of the image? The only way to go back from here is to do it all over again, and that’s too tedious. Instead, let’s use a Layer Mask.

Screen Shot 2014-01-07 at 1.38.06 PM

To create a Layer Mask, select the layer you want to apply the mask to (in this case, I selected the top layer), and click on the Layer Mask button. You won’t see any changes to your image, but instead you will see a layer mask thumbnail attached to your layer. You will see that it is filled in white. This is because in Layer Masks, white is transparent, black is opaque and grey controls the transparency levels.

In order to merge the two pictures together, we won’t be using the Eraser Tool, but the Paintbrush tool! Simply select your paintbrush tool, and set the foreground color to Black (remember, this will hide the pixels you don’t want showing). Make sure you have your Layer Mask thumbnail selected (not just the layer! You’ll only end up with a black streak on your picture), and paint over the area you want to hide!

Image

As you can see, the Layer Mask isn’t fully white anymore. That’s because you’ve hidden some pixels. If you want to show more of the image, you can just go over it with white instead.

Image

After messing around with it a bit more, this was the finished result. Probably not the best stock images to use, but you get the idea!

I hope you’ve learned something new today and have fun using non-destructive Layer Masks!