SEARCH W7R

Sunday, April 22, 2012

Voltage, Resistance, and Current

Voltage, Resistance, and Current are three fundamental components to electric circuits that our technologically savvy world has been built on. They are responsible for all of the technology we take for granted today and luckily are closely related with one simple equation, called Ohm's Law.

 I (amps)= V(volts) / R(ohms)    ~this is Ohm's Law


V=IR is alternative form of Ohm's Law.

- VOLTAGE -

    Voltage measured in volts, is an electromotive force (EMF) or potential difference in electrical energy. Electrons move incredibly fast and in incredibly random fashion, but when a potential difference is present from one area to another then an electric field has been established which will slowly drift the zillions of electrons across a wire or other medium. The voltage or potential difference is responsible for current moving in direct current circuits.
     When you buy batteries for your TV remote, cell phone, and flashlights you are usually looking for a specifically sized battery, but more importantly an accurate number of battery cells to create the voltage demanded by the component that will use them. For example, AA batteries have 1.5 volts. So, the potential difference across the terminals of the battery is 1.5 volts. Most circuits require more than 1.5 volts, that is why most appliances, toys, remotes, use 4 (6 volts), 2 (3 volts) and sometimes 6 (9 volts). In most circuits, the voltage source is constant like how resistance is a constant  opposing force to the flow of current.

Volts, the unit for measuring voltage is symbolized with a lower or uppercase: v = V = volts. Voltage is sometimes symbolized with a E in equations to avoid conflicting with the voltage unit symbol, V or v.

Equations Related To Voltage
V = I / R      ~Ohm's Law
voltage (v)= current (A)/ resistance (Ohm)

P = I x V
Power (Watts) = current (amperes) x voltage (volts)

Electric Potential vs Electrical Potential Energy!

- RESISTANCE -

These are different types and sizes of resistors. 

Resistance, measured in ohms, resists the flow of electrons as they travel from high to low electric potential regions of a circuit. Resistance is present in any and every object you can think of, but in the case of most metals, the resistance is very close to 0 ohms, thus a great conductor of electricity. Before the transistor (transforming resistor) was invented, resistor values were always constant, regardless of the current of voltage they were opposing. However, the transistor (transforming resistor) allows the resistance from its pins to change value depending on an input current. For more on transistors go to my post, "Transistors Should Be Easy!"



Resistors are electrical elements used to establish a higher value of resistance in a circuit. For example, you should never hook a 9V battery to an LED (light emitting diode) because it would explode. You need a resistor to limit the amount of current reaching the LED (light emitting diode). Resistors in series add up to create higher amounts of resistance on a specific part of a circuit.

More resistance = more ohms = less flow of electronics =  less amperes of current


Equation for Resistance
R = V/I
R - resistance (ohms: Ω)
V - voltage (volts: v)
I - current (amperes: A)

Resistance of a wire
R_wire  =  (ρ * l ) /A
A - cross sectional area of wire
l - length of wire
ρ - resistivity

Resistors in series
Rtotal = R1 + R2 + R3 + Rn

- CURRENT -

Current (I : amperes)
Current, or the flow of charge, is measured in Amperes (A), and is symbolized with a capital "I" in equations and formulas, alike. Current can be thought of as voltage/resistance in almost all respects. One Ampere is equivalent to a one coulomb/second. So you can also describe electric current in terms of coloumb per seconds.

The "I" stands for Intensity of electric current, because an ampere is about six quintillions of electons traveling through a point of conduction per second. The "I" also avoids conflict of current with C which stands for specific heat, and also similarly could imply Celsius.

Equations Related To Current
I = Q / t
Q - electric charge (coulombs: )
I - current (amperes)
t - time (seconds) 

Thursday, April 19, 2012

Top Rage Comic Compilation! #1

People seemed to have enjoyed the Troll Meme Compilation post I had posted a few months ago, so I thought it only makes sense to have a rage comic compilation post as well! In this post I also left a link to a site where you can create your own rage comics at the bottom of the post. Cheers to life and laughter!


Comment on this post and share your personal favorite rage comic with the W7R community and me. On W7R you do not need an account or username to comment.













Monday, April 09, 2012

How to Simplify your Java Code

Simplifying your programs code is important because it can decrease the size, speed, modularity, and flexibility of your program. Most of the time simplified code can be easier to read. For this post I will entertain two simple, but effective solutions to eliminate unnecessary (extra) code.

Wasteful Code Snippet #1: (BAD)
    private int mailBox1=2;
    private int mailBox2=5;
    private int mailBox3=1;
    private int mailBox4=3;
    private int mailBox5=4;


Solution #1A: (GOOD)
    private int mailBox1=2,
        mailBox2=5,
        mailBox3=1,
        mailBox4=3,
        mailBox5=4;
Explanation #1A I have eliminated the repeated code "private int". This works because private int is a declaration of a variable type which can be shared by using commas.

Solution #1B: (GREAT)
private int[] mailBoxes = new int[]{2,5,1,3,4};
//mailBoxes[0] is mailBox1, mailBoxes[1] is mailBox2, ect.

Explanation #1B I eliminated not only the extra declarations, but have also decrease the number of variables references in my program. There originally were 5 references, and now there is one, mailBoxes, which points to an array of integers. An array is simply a list of some data (normally all of equivalent type).


Wasteful Code Snippet Type #2: (BAD)

 boolean answer = userAnswer(); 
 if(answer==true){
  //then does something here
 }

Solution #2A: (GOOD)

 boolean answer = userAnswer(); 
 if(answer){
  //then does something here
 }

Explanation #2A Booleans are already conditional values, therefore do not need any comparison operator to verify their state in the if construct. Afterall, they are either true or false.

Solution #2B: (GREAT)

 if(userAnswer()){
  //then does something here
 }
Explanation #2B Elimination of a variable declaration can save memory, and a small instance of time in addition to making the code easier to read.

Modulus Division by Hand

Believe it or not you already have the ability to do modulus division. In fact you do it every day.

Remember in elementary school where division either worked "perfectly" or had a remainder? In middle school and highschool you toss the remainder and find answers in terms of decimals and fractions instead of remainders. The poor remainder has one last opportunity to impress you, in it's simplification of modulus division.

How To Do It:
-Set up a long division problem with the top and all.
-Insert your divisor, dividend like old times
-Solve the problem with remainder r.

dividend % divisor = remainder
Modulus division answer = remainder


Modulus division is a way of computers to check for specific multiples of  a number. Such as an algorithm to determine whether a number is even. We do this subconciously all the time,

IF some number divided by 2 = 0
THEN it's even. 

Sunday, April 08, 2012

20 Java Math.random() Uses

In this post, I have coded 20 Math.random manipulations in Java for you to access such as recieving a random card out of a deck of 64, selecting a random color (aprx. million colors), and some more simple applications like generating a percent (0% to 100%). Enjoy!
  1. Positive Integers (1 to 10)

    int result1 = (int)(Math.random()*10)+1; 
    
  2. Negative Integers (-1 to -10)

    int result2 = (int)((Math.random()*(-10))-1);
    
  3. Positive Integers (1 to 100)

    int result3 = (int)(Math.random()*100)+1; 
    
  4. Percent Values (0.00% to 100.00%)

    double result4 = (Math.random()*100); 
    
  5. One or Zero / Bit Value

    int result5 = ((int)(Math.random()*2));  
    
  6. Positive Odd Integers (1,3,5,7,9)

    int result6 = ((int)(Math.random()*9)+1); 
     while(result6%2!=1){ 
      result6 = ((int)(Math.random()*9)+1); 
     }  
    
  7. Positive Even Integers (2,4,6,8,10)

    int result = ((int)(Math.random()*10)+1); 
     while(result%2!=0){ 
      result = ((int)(Math.random()*10)+1); 
     } 
     
    
  8. Positive Multiples of Three (3,6,9,12,15,18, ... 54,57,60)

    int result = ((int)(Math.random()*10+1))*3; 
    
  9. Positive Multiples Of Four (4,8,12,16,20... 52,56,60)

    int result = (((int)(Math.random()*10))+1)*4; 
    System.out.println("mult of 4: "+result); 
    
  10. Perfect Squares (1,4,16,25,36,49,64,81,100,121)

    int result = (int)Math.pow(((int)(Math.random()*11)+1),2); 
    System.out.println("random perfect square: "+result); 
    
  11. Prime Numbers (1,3,5,7,11,13,17,19,23)

    int[] primes= {2,3,5,7,11,13,17,19,23}; 
    int randPrime = primes[(int)(Math.random()*primes.length)]; 
    System.out.println("random prime: "+randPrime); 
    
  12. Specific Set of Integers

    int[] possibleInts = {911,18,1,923,817,200}; 
    int result = possibleInts[(int)(Math.random()*possibleInts.length)]; 
    
  13. Specific Set of Strings

    String[] strings = 
    {"mango","pineapple", "orange", "apple", "banana", "kiwi"};
    String result = strings[(int)(Math.random()*strings.length)];
    
  14. Multiples of N (some integer N)

    public int randomMultipleOf(int N, int greatestFactor){ 
    return ((int)((Math.random()*greatestFactor)+1))*N; 
    //highest return value = N*greatestFactor 
    //in this example below it would be 7*9 = 63 maximum return value 
    randomMultipleOf(7,9); 
    
  15. Random year of the last 100 years

    int currentYear=2012;
    int result = currentYear + ((int)(Math.random()*100)+1); 
    
  16. Random Color (RGB)

    public Color randomColor(){ 
      return new Color((int)(Math.random()*256), (int)(Math.random()*256),(int)(Math.random()*256)); 
     } 
    
  17. Perfect Cubes

    public int randomPerfectCube(int minRoot, int maxRoot){ 
      return ((int)(Math.random()*maxRoot)+minRoot); 
     } 
    
  18. Random Card of a Standard Card Deck

    public String randomCard() { 
      int randSuit = (int)(Math.random()*4); 
      int randNumber =  (int)(Math.random()*14); 
      String suit, name; 
      if(randSuit==0) { 
       suit="Spades"; 
      } else if(randSuit==1) { 
       suit="Diamonds"; 
      } else if(randSuit==2) { 
       suit="Clubs"; 
      } else { 
       suit="Hearts"; 
      } 
      if((randNumber0)) { 
       name=randNumber+""; 
      } else if(randNumber==0) { 
       name="Ace"; 
      } else if(randNumber==11) { 
       name="Jack"; 
      } else if(randNumber==12) { 
       name="Queen"; 
      } else { 
       name="King"; 
      } 
      return name + " of  " + suit; 
    } 
    
  19. Letters of the English Alphabet

    public char randomLetter(){ 
       String letters = "abcdefghijklmnopqrstuvwxyz"; 
       return letters.charAt((int)(Math.random()*letters.length())); 
    } 
    
  20. Letter from a specific String parameter

    public char randomCharOf(String s) { 
         return s.charAt((int)(Math.random()*s.length())); 
     } 
    

Contacting Brian:
If there are any errors at all or if you want to suggest or request another manipulation email me at w7rdotblogspot@gmail.com or simply comment on this post.

Java Basics: The While Loop

The while loop is the simplest of the loop syntax available to you as a Java programmer. The general idea is if a condition is true, then repeat til it is false. The only additional detail to make the idea complete is that the condition is checked before and after every loop.

Source


Specific Examples!
1. Condition is Never True Case
int count = 10;
while(false){
   count--;
   System.out.println("Inside the loop");
   //this area (inside the semi colons) will never be executed
}
System.out.println("After the while loop");
System.out.println("count: "+count);

2. Condition is Always True (Infinite Loop)

int count=0;
while(true){
   count++;
   System.out.println("Inside the loop. Looped "+count+" times.");
   //executed infinitely many times WARNING: could harm computer if not terminated
}
System.out.println("After the while loop");

3. Counting Up To A Certain Number
int topNumber=900;
int lowNumber=0;
while(lowNumber<topNumber){
   lowNumber++;
}
System.out.println("final value for lowNumber is "+lowNumber);

4. Count Down To A Certain Number

int topNumber=900;
int lowNumber=0;
while(lowNumber<topNumber){
   topNumber--;
}
System.out.println("final value for lowNumber is "+lowNumber);

Friday, April 06, 2012

Printable Computer Purchasing Guide - Save Hundreds!

PRINT THIS OUT AND BRING IT TO THE COMPUTER STORE WITH YOU
The information provided will help you understand what the computer you are buying really is. I provided several questions to ask the salesman at the computer store to make sure you are buying what you want and need for a low price. Going to the store without this would be passing up a minimum of $100. Salesman work on commission which motivates them to sell you products the most expensive selections and devices whether or not you actually needed it.
1. Hard Drives
    -More GB (Gigabytes) is better because it provides more space!
    -TB (Terabytes) are 1000 GB
    -Most people have 100 to 500 GB on their desktop's hard drive
    -Many people currently buying desktop computers select sizes 500GB to 1000GB today
    -Your computer's storage space

2. RAM (Random Access Memory)
    -Responsible for most of a computers speed
    -A superior addition to a laptop (get a lot!)
   -Programs require more and more RAM year by year (tech is growing)


3. Laptop
    -Costs more than desktop
    -Portable
    -Not very flexible with hardware like a desktop can be
    -Generally less space on hard drive
    -built-in keyboard, mouse, and monitor
    -Do not buy a used laptop (no warranty and parts are small)

4. Support
     -Will the company offer you a warranty?
    -Is there 24 hour help?
    -Is the company a well known brand that you can rely on?

5. Accessories
   -Is a monitor included?
   -Is a mouse included?
   -Is a keyboard included?
   -Battery Life?
   -All computer companies exaggerate their laptop battery life. What ever it promises, think half.

6. CPU (Central Processing unit)
    -Main Speed Unit
    -Does calculations
    -speed is measured in gigahertz (GHz)
    -more GHz, faster computer

7. Graphics Card
    -Buy the expensive ones for good graphics on HD movies and video games

8. Operating System
    -Windows 7, Mac OS X, Linux?
    -Mac is most user friendly and easy to understand, but Windows is the perfect balance between real computing, and friendly bunnies. I wouldn't get Linux without knowing about how it works and its positives and negatives.

9. Drives
    -How many USB drives?
    -Can it use SD cards without an adapter?
    -Can it use memory card sticks?
    -Can you easily access and change or add a hard drive?
    -How many audio jacks does the computer have?

Watch this video for extra aid in selecting a computer: http://www.videojug.com/interview/computer-buying-basics

 This list can help you purchase the best computer for you for a low price!
-Brian

The Do-While Loop (Java)

Of the questions I receive about loops, most are about the do-while loop. So, let me show you how the do-while loop works and when you would want to use it.

The Java syntax for a do-while loop is


do{

  /** code..
    * statement 1
    * statement 2
    **/

} while (condition);


The Do-While Cycle

1. Execute body of code 1 time from top to bottom.
2. check condition.
3. if condition is true, then go back to step 1
else exit the loop and execute lines of code that come after the loop.

THE GUMBALL MACHINE
How many times would the following do-while loop iterate?
double money=2.00;
do {
    //same as: money = money -0.25
    money-=0.25;
} while (money>=0.25);

Why would we ever want to use it instead of using a for loop, or while loop? In situations where if the condition is initially false, because in ordinary for and while loops the code would not be executed if the condition was initially false. Email me if you need additional help or have questions -w7rdotblogspot@gmail.com

Thursday, April 05, 2012

Accurate Value of E or PI Instantly



All you do to get the values for these mathematical constants is copy and past the whole line that starts with "javascript:" into a browsers URL bar and press enter.

 The word javascript and colon MUST BE included. If you have turned off the setting for javascript execution on webpages then you will have to change the setting before achieving a successful run.

For The Value PI (3.14.....)

javascript: alert("pi = "Math.PI);

For the Value of E (2.174....)

javascript: alert("e = "+Math.E);




Tuesday, April 03, 2012

HTML: How To Create Images

IMAGES WITH HTML

Images appear on websites because your internet browser reads HTML that contains an <img> tag with an attribute, src, which describes the location of the picture (the link address).

The code would look something like...
<img src="File Location" />

"File Location" is the URL (Universal Resource Locator) for an image. Short and sweet, if you want an image on your site from Google Images you should right click the image and select "copy link address" or "copy image URL" and paste the link address inside the double quotation marks. 

<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/c/c1/Computer-aj_aj_ashton_01.svg/250px-Computer-aj_aj_ashton_01.svg.png" />

The image tag does not have a closing tag, but instead, a forward slash / in the tag before the closing angle bracket, >.


The Code: Piece by Piece Explanation

1. <     ~open angle bracket
2. img     ~image tag
3. src     ~the source attribute of image
4. ="image URL"    ~ assigning value "image URL" to the source attribute
5. />       ~end tag 

Practice Makes Perfect!

Try practicing with the image below! Just right click it and select "Copy image URL" and use it with the syntax for an image! <img src="image URL"/>


For more about Images in HTML: Click Here!

Monday, April 02, 2012

HTML: Creating Links


Creating Links with HTML

Let's begin with an example of a link coded in HTML. *open in a new window to avoid leaving this page!   Open me in a new window! 
 The link above sent you to my youtube page.

Here is the HTML code I used to create the link.

 <a href="http://www.youtube.com/user/w7rdotblogspot/videos">Open me in a new window!</a>


There are 4 basic parts to this code
  1. The tags <a> and </a>       ~These are anchor tags.
  2. The attribute href       ~This is an attribute of the anchor tag.
  3. The site URL      ~Location for the site the link will take the user to
  4. Pain text       ~What the user sees on the webpage
Try running the following sample HTML text (Online HTML Compiler)
<html>
<head>
</head>
<body>
Google is a good site. Isn't it?
<a href="http://google.com"> >>Google<< </a>
</body>
</html>

Sunday, April 01, 2012

Incandescent, Compact Fluorescent, and LED Light Bulb Comparison


Incandescent Light Bulb Diagram
This image source
Incandescent bulb
This image source


1. The Incandescent Light Bulb

Incandescent bulbs are the same type of light bulb built (not invented) by Thomas Edison back in 1879 (Did you know Thomas Edison Did Not Invent The Light Bulb). The incandescent light bulb has many different shapes, as do all of the common light sources of this article, but incandescent bulbs tend to be glass like clear, round, and have a fine piece of wire bent into zigzags in the center. The zigzag piece is called a filament. When the filament is heated by electrical current it emits light and heat. Incandescent bulbs are still in use today, but are the least energy efficient of the three bulbs we will compare.




Various types of CFL light bulbs

 2. The Compact Fluorescent Light Bulb (CFL)

This is the lightbulb that has been gradually replacing traditional incandescent bulbs in recent years. The CFL bulb is spiral shaped (most often) and is considered eco-friendly by the majority of people. These bulbs have been recorded to save 80% more power than incandescent bulbs. But, a big problem with CFL bulbs is that they contain about 5 mg of mercury per bulb. Enough exposure to broken CFL bulbs could present serious health problems such as brain cancer.
On the upside, CFL bulbs can save you money on your power bill. On the downside, CFL bulbs need to be used with more care than the standard incandescent bulb.




LED bulbs
Source

3. The LED Light Bulb (LED = Light Emitting Diode)

LED stands for Light emitting diode and is an important component for modern day electronics and environmentally friendly standards on the rise. Most appliances and devices that have lights built in with them show that they are powered (turned on) with a bright red or green LED. LEDs are not limited to the colors red and green, and are powered by D.C. (direct current) electricity. The LED type light bulb is a collection of the relatively small (5mm / 0.05cm diameter), LEDs. LED-type light bulbs are the most effecient at converting electrical energy to radiant (light) energy. However, the thermal energy lost in incandescent bulbs served a greater purpose that was long misunderstood.




So,
  the big question is...

WHICH IS THE REAL "LIGHT" BULB?

Incandescent: aprx. 90% thermal energy and 10% radiant (light) energy
CFL: aprx. 60% thermal energy and 40% radiant (light) energy
LED: aprx. 10% thermal energy and 90% radiant (light) energy


Clearly the LED is the most efficient at converting electical current into radiant (light) energy as oppsed to the incandescent that is more a "thermal" bulb than it is a light bulb. In between the two is the CFL (compact fluorescent light bulb).





Snow on LED traffic lights = big problem
The Problem with LEDs in Traffic Lights
Street lights are on all day and all night directing traffic, regardless of the season. In winter the incandescent bulbs work well, so why would not the LED type do the same in addition to saving energy and money. Well, in winter it snows, and street lights get covered in snow, leaving street lights unrecognizable. Incandescent bulbs melt the snow off due to its 90% thermal energy conversion, but LEDs do not have enough thermal energy to do so. Since, that initial problem, streetlights in some areas in the United States have little hat like over hangs to keep snow from blocking LED street lights. 

Another problem involving the decrease in thermal energy from light bulbs is that houses will need to power their homes with more AC (air control) and heat to reach desirable temperatures in the winter and fall, in which would crank up an ugly energy bill.