Bomby Falldown

Bomby Falldown.

Advertisements

Laptop internal webcam to USB webcam

On a hurry ? Jump to pinout
Yesterday I bought a used HP pavilion dv6 webcam/mic module. I already knew that this webcam is usb. The board has a webcam and 2 mics with 6 pin out.
dv6 webcam/mic moduleThe problem was I didn’t know the correct pin out so you have to try. I searched and searched and searched, but all the pinouts I found didn’t work for me.

The 6 pins should be V+, GND, D+, D-, and left/right mic. The ground pin is shared with the mic lines. So, you have to know which pins are the V+, GND, and the D+/- to connect them to corresponding usb pins.
You should Know that the usb have 4 pins with colors Red (V+), Balck(GND), White(D-), Green(D+). I got this Wikipedia

usb usb_figure

I own a pavilion dv5 laptop which have a similar camera, the connected jack has wires colored with (from left to right) Black, Red, Orange, Yellow, Green and Blue. I had no twisted pairs, if you found a twisted pair you’re lucky :D. Twisted pairs are mostly the D+/D-.
A very important thing to take into consideration that the colors doesn’t follow any standards, as you’ll see that the Black wire is the D- O.o.

One thing that really helped me to find out the correct pinout that you may try; on Windows if you got the notification that the usb inserted is malfunctioned, that means that the connection is mostly correct but the data lines are corrupted. Try to swap the V+ and D+ lines. This did the job for me.

Pin Layout

Here’s the layout that worked for me (from left to right)

  1. Black ⇒ D+ [USB Green]  
  2. Red D- [USB White] 
  3. Orange ⇒ V+ [USB Red]
  4. Yellow
  5. Green
  6. Blue ⇒ GND [USB Black]

finally here’s a lsusb command output after the camera is recognized 😀 😀
usblist_

UVa 10931 – Parity

#include <iostream>

using namespace std ;

int countBits(int i){
   i = i - ((i >> 1) & 0x55555555);
   i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
   return (((i + (i >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
}

int main (){
   int n,j;
   char s[33] ;
   cin>>n;
   while (n){
       j=0;
       while (n>>j)
           s[j++] = ((n>>j)&1)+'0';


       cout<<"The parity of ";
       while (j--)
           cout.put(s[j]);

       cout<<" is "<<countBits(n)<<" (mod 2)."<<endl;
       cin>>n;
   }
   return 0;
}

UVa 10812 – Beat the Spread!

#include <iostream>

using namespace std;

int main(){
   int sum,dif,tc;
   cin>>tc;
   while (tc--){
       cin>>sum>>dif;

       if (dif>sum || ((sum^dif)&1)) // one odd and other even
           cout<<"impossible"<<endl;

       else {
           dif = (sum+dif)/2;
           cout<<dif<<" "<<sum-dif<<endl;
       }

   }
   return 0;
}

UVa 10773 – Back to Intermediate Math

#include <iostream>
#include <string>
#include <cmath>
#include <stdio.h>

using namespace std;

int main (){

	int n,t=0;
	double d,u,v,ans;
	cin>>n;

	std::cout.setf(std::ios::fixed);
	std::cout.precision(3);

	while (t++<n){
		cin>>d>>v>>u;
		ans = u*u - v*v ;
		if (ans<0.001||u<0.001||v<0.001)
           //cases that make the eqn of ans contains a NaN || d=0
			cout<<"Case "<< t <<": can't determine"<<endl;

		else {
			ans = d/sqrt(ans) -  d/u;
           //d/sqrt(u*u - v*v) = stearing with -ve angle so that the flow takes the boat to the destination
			cout<<"Case "<< t <<": "<< ans << endl;
		}
	}

	return 0;
}

UVa 11466 – Largest Prime Divisor

#include <iostream>
using namespace std;

int main() {
	long long n,ans,i;
	int counter;
	cin>>n;
	while (n!=0){

		if (n<0)
			n=-n;

		ans = -1;
		counter = 0;
		//print -1 for numbers that has 1 prime divisors as primes, pow of primes (4,8,9)
		for ( i = 2; i*i <= n && n!=1; i++) {
			while (n%i == 0){
				n/=i;
				ans = i;
			}
			if (ans == i)counter++;
		}


		if (n!=1 && ans!=-1)
			ans = n;
		else if (counter==1)
			ans = -1;

		cout<<ans<<endl;

		cin>>n;
	}

}

UVa 11661 – Burger Time?

#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main(){
	int n,min,lastD,lastR;
	string s;

	while (cin>>n){
		if(n==0 )
			break;

		cin>>s;
		min = 1<<25;

		lastD = lastR = -1;
		for(int i = 0 ; i<n ; i++){
			if(s[i]=='.')
				continue;
			else if (s[i]=='Z'){
				min = 0;
				break;
			}
			else if (s[i]=='D'){
				lastD = i;
				if (i-lastR<min && lastR!= -1)
					min = i-lastR;
			}
			else {
				lastR = i;
				if (i-lastD<min && lastD!=-1)
					min = i-lastD;
			}

		}
		cout<<min<<endl;
	}
	return 0;
}