Cov txheej txheem:

Arduino Youtube Chaw Taws Teeb rau Kev Tsaug Zog (Leobot Electronics): 4 Cov Kauj Ruam
Arduino Youtube Chaw Taws Teeb rau Kev Tsaug Zog (Leobot Electronics): 4 Cov Kauj Ruam

Video: Arduino Youtube Chaw Taws Teeb rau Kev Tsaug Zog (Leobot Electronics): 4 Cov Kauj Ruam

Video: Arduino Youtube Chaw Taws Teeb rau Kev Tsaug Zog (Leobot Electronics): 4 Cov Kauj Ruam
Video: Qhia txuas xaim hluav taws xob daim: 02 2024, Kaum ib hlis
Anonim
Arduino Youtube Chaw Taws Teeb rau Tsaug Zog (Leobot Electronics)
Arduino Youtube Chaw Taws Teeb rau Tsaug Zog (Leobot Electronics)

Arduino Youtube Chaw Taws Teeb

Yog tias koj siv Youtube los muab cov yeeb yaj kiab lossis suab paj nruag rau koj saib thaum tsaug zog koj yeej yuav tau sawv los ntawm ib qho kev tshaj tawm lossis ntau qib sib txawv thaum pib ua yeeb yaj kiab tshiab. Needless hais, qhov no tuaj yeem ua rau khaus heev.

Yog li, kuv qhov kev daws teeb meem kuv ua pov thawj rau koj ntawm no los tsim rau koj tus kheej yog Arduino-based chaw taws teeb tswj kom cuam tshuam nrog Youtube ntawm qhov deb. Cov chaw taws teeb yuav tsum hloov pauv kuv lub PC lub suab nrov, hla kev tshaj tawm hauv Youtube thiab hla cov vis dis aus hauv Youtube.

Tsis tas li, suav nrog yog lub ntsuas qib suab los txiav txim siab nrov npaum li cas tus neeg hais lus yog, uas tuaj yeem siv tau los txo qis lub suab thaum pom lub suab nrov cuam tshuam xws li kev tshaj tawm.

Thaum kawg, Kuv tau ntxiv daim ntawv qhia hauv PC app los tso saib cov suab uas pom.

Kev daws teeb meem tuaj yeem ua kom zoo dua qub tab sis rau kuv nws ua tiav txoj haujlwm.

Kauj Ruam 1: Cov Cheeb Tsam Xav Tau

Tag nrho cov khoom siv no yog muab los ntawm Leobot Electronics (https://leobot.net)

1) Arduino UNO R3

leobot.net/viewproduct.aspx?id=530

2) 4 CHANNEL REMOTE (315MHZ) + RECEIVER MODULE (315MHZ)

leobot.net/viewproduct.aspx?id=521

3) MICROPHONE VOICE & SOUND DETECTION SENSOR MODULE (KY-037)

leobot.net/viewproduct.aspx?id=217

Software

1) Visual Studio

visualstudio.microsoft.com/

2) Arduino IDE

www.arduino.cc/en/main/software

Kauj ruam 2: Teeb Kho Vajtse

1) Txuas 4-Channel receiver module rau Arduino.

4-Channel Receiver Pin-> Arduino Uno Pin

GND-> GND

5V-> 5V

D0-> Digital 2

D1-> Digital 3

D2-> Digital 4

D3-> Digital 5

2) Txuas Microphone KY-037 module rau Arduino

Microphone KY-037 Pin-> Arduino Uno Pin

GND-> GND

+-> 3.3V

A0-> Analog 3

Kauj Ruam 3: Arduino Code

Txheej txheem cej luam

Cov laj thawj uas Arduino xav tau ua raws yog raws li hauv qab no:

A) Txheeb xyuas yog tias tus neeg txais txais lub cim qhia tus pin.

B) Nyob ntawm qhov chaw nres nkoj IO qhov teeb meem tau txais ntawm qhov lus txib yuav xa mus rau PC li cas.

C) Thaum ua tiav nrog txhua qhov kev tswj chaw taws teeb, txheeb xyuas lub suab nrog lub microphone thiab xa mus rau PC.

D) Txhua cov lus txib xa mus rau PC muaj hom ua ntej muaj tus ua cim tom qab ntawd tus nqi (yog tias xav tau tus nqi).

E) Muaj tsib lo lus txib xa los ntawm Arduino mus rau PC

a "U" - Volume Up

b. "D" - Volume Down

c. "S" - Hla Ntxiv

d. "V" - Hla Video

e. "A" - Lub suab tau tshawb pom ua raws los ntawm tus nqi

Arduino Txoj Cai:

Rub tawm Arduino Code ntawm no:

int hauv 1 = 2;

int hauv 2 = 3;

int hauv 3 = 4;

int hauv 4 = 5;

void teeb tsa () {

Serial.begin (9600);

pinMode (A3, INPUT);

pinMode (hauv 1, INPUT);

pinMode (hauv 2, INPUT);

pinMode (hauv 3, INPUT);

pinMode (hauv 4, INPUT);

}

void voj () {

yog (digitalRead (hauv 1))

{

Serial.println ("u");

ncua (100);

}

yog (digitalRead (hauv 2))

{

Serial.println ("d");

ncua (100);

}

yog (digitalRead (hauv 3))

{

Serial.println ("s");

ncua (100);

}

yog (digitalRead (hauv 4))

{

Serial.println ("v");

ncua (100);

}

int readVal = analogRead (A3);

Serial.println (Txoj hlua ("a")+ Txoj hlua (readVal));

ncua (50);

}

Kauj Ruam 4: PC App Code (C#. NET)

PC App Code (C#. NET)
PC App Code (C#. NET)

Lub app yuav mloog dua qhov chaw nres nkoj COM (USB) thiab ua raws li qhov tau txais cov lus txib. Txoj hauv kev yooj yim tshaj plaws los tig lub suab nrov hauv PC yog siv Interrop cov kev pabcuam los hais ncaj qha rau Windows OS. Peb kuj siv Interrop cov kev pabcuam txav tus nas mus rau txoj haujlwm tshwj xeeb ntawm lub vijtsam thiab nyem. Txhawm rau tso cai rau cov ntxaij vab tshaus sib txawv & saib qhov ntau thiab tsawg, peb tso cai rau tus neeg siv kom qhia txoj haujlwm ntawm hla hla thiab hla khawm cov vis dis aus.

Peb siv tus qauv.net daim ntawv los tso saib cov lus txib uas peb tau txais.

Qhov rai Code:

Rub tawm qhov project tag nrho ntawm no:

leobot.net/audioadjust.zip

siv System;

siv System. Collections. Generic;

siv System. ComponentModel;

siv System. Data;

siv System. Drawing;

siv System. Linq;

siv System. Text;

siv System. Windows. Forms;

siv System. Runtime. InteropServices;

siv System. IO. Ports;

siv System. Threading;

namespace AudioAdjust

{

public partial class Form1: Daim ntawv

{

[DllImport ("User32. Dll")]

pej xeem zoo li qub sab nrauv ntev SetCursorPos (int x, int y);

[DllImport ("User32. Dll")]

pej xeem zoo li qub extern bool ClientToScreen (IntPtr hWnd, ref POINT point);

[DllImport ("user32.dll", CharSet = CharSet. Auto, CallingConvention = CallingConvention. StdCall)]

pej xeem zoo li qub extern void mouse_event (uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);

// Kev ua nas

private const int MOUSEEVENTF_LEFTDOWN = 0x02;

private const int MOUSEEVENTF_LEFTUP = 0x04;

private const int MOUSEEVENTF_RIGHTDOWN = 0x08;

private const int MOUSEEVENTF_RIGHTUP = 0x10;

[DllImport ("user32.dll")]

sab nrauv sab nrauv tsis muaj nuj nqis keybd_event (byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);

Random aRand = tshiab Random ();

pej xeem int LastLevel = 0;

pej xeem int MaxLevel = 255;

zoo li qub SerialPort _serialPort;

int adX = 1281;

koj adY = 706;

int vidX = 250;

koj = 780;

bool enableAudioChange = tsis tseeb;

pej xeem daim ntawv 1 ()

{

InitializeComponent ();

}

ntiag tug void Form1_Load (tus xa khoom, EventArgs e)

{

hlua cov npe = System. IO. Ports. SerialPort. GetPortNames ();

comboBoxPort. Items. AddRange (npe);

comboBoxPort. SelectedIndex = 0;

}

int currentPoint = 0;

ntiag tug khoob khoob khawm1_Click (tus xa khoom, EventArgs e)

{

_serialPort = tshiab SerialPort ();

_serialPort. DataReceived += tshiab SerialDataReceivedEventHandler (_serialPort_DataReceived);

_serialPort. PortName = comboBoxPort. SelectedItem. ToString (); // Teem koj lub rooj tsavxwm COM

_serialPort. BaudRate = 9600;

yog (_serialPort. IsOpen) _serialPort. Close ();

lwm tus

{

_serialPort. Open ();

}

// keybd_event ((byte) Keys. VolumeDown, 0, 0, 0); // txo ntim

}

void _serialPort_DataReceived (tus xa khoom, SerialDataReceivedEventArgs e)

{

sim

{

hlua fullval = _serialPort. ReadLine ();

hlua com = fullval [0]. ToString ();

hloov (com)

{

cas "a":

{

{

// suab theem

hlua val = fullval. Replace ("a", "");

int valInt = int. Parse (val);

NtxivData (valInt);

}

tawg;

}

cas "u":

{

// suab up

keybd_event ((byte) Keys. VolumeUp, 0, 0, 0); // txo ntim

tawg;

}

cas "d":

{

// suab down

keybd_event ((byte) Keys. VolumeDown, 0, 0, 0); // txo ntim

tawg;

}

cas "s":

{

// skipAd

MoveCursorSkipAd ();

Xov. Sleep (10);

DoMouseClick ();

tawg;

}

cas "v":

{

// skipAd

MoveCursorSkipVideo ();

Xov. Sleep (10);

DoMouseClick ();

tawg;

}

}

}

ntes

{

}

// pov tshiab NotImplementedException ();

}

ntiag tug void MoveCursorSkipAd ()

{

Cursor. Position = Point tshiab (1140, 725);

Cursor. Position = Point tshiab (adX, adY);

}

ntiag tug tsis muaj dab tsi MoveCursorSkipVideo ()

{

Cursor. Position = Point tshiab (1140, 725);

Cursor. Position = Point tshiab (vidX, vidY);

}

pej xeem tsis muaj dabtsis DoMouseClick ()

{

// Hu rau qhov ua haujlwm txawv teb nrog tus cursor txoj haujlwm tam sim no

uint X = (uint) Cursor. Position. X;

uint Y = (uint) Cursor. Position. Y;

mouse_event (MOUSEEVENTF_LEFTDOWN, X, Y, 0, 0);

mouse_event (MOUSEEVENTF_LEFTUP, X, Y, 0, 0);

}

tsis muaj dab tsi AddData (qib theem)

{

yog (enableAudioChange)

{

yog (qib> = MaxLevel)

{

keybd_event ((byte) Keys. VolumeDown, 0, 0, 0); // txo ntim

keybd_event ((byte) Keys. VolumeDown, 0, 0, 0); // txo ntim

keybd_event ((byte) Keys. VolumeDown, 0, 0, 0); // txo ntim

}

lwm tus

{

yog (qib <MaxLevel - 0)

{

keybd_event ((byte) Keys. VolumeUp, 0, 0, 0); // txo ntim

}

}

}

SetChart (qib);

currentPoint ++;

}

delegate tsis muaj dabtsis SetTextCallback (int val);

ntiag tug tsis muaj dab tsi SetChart (int val)

{

// InvokeRequired xav tau los sib piv xov ID ntawm

// hu xov tooj rau xov ID ntawm kev tsim xov.

// Yog tias cov xov no txawv, nws rov muaj tseeb.

yog (this.chart1InvokeRequired)

{

SetTextCallback d = SetTextCallback tshiab (SetChart);

thisInvoke (d, khoom tshiab {val});

}

lwm tus

{

chart1. Series [0]. Points. AddXY (0, nqi);

yog (currentPoint> = 10)

{

chart1. Series [0]. Points. RemoveAt (0);

}

}

}

private void textBoxLevel_TextChanged (tus xa khoom, EventArgs e)

{

sim

{

MaxLevel = int. Parse (textBoxLevel. Text);

}

ntes

{

textBoxLevel. Text = MaxLevel + "";

}

}

ntiag tug khoob khoob khawmTestSkip_Click (tus xa khoom, EventArgs e)

{

MoveCursorSkipAd ();

Xov. Sleep (10);

DoMouseClick ();

}

private void textBoxXpos_TextChanged (tus xa khoom, EventArgs e)

{

sim

{

adX = int. Parse (textBoxXpos. Text);

}

ntes

{

textBoxXpos. Text = adX + "";

}

}

private void textBoxYpos_TextChanged (tus xa khoom, EventArgs e)

{

sim

{

adY = int. Parse (textBoxYpos. Text);

}

ntes

{

textBoxYpos. Text = adY + "";

}

}

ntiag tug khoob khoob khawmSkipVideo_Click (tus xa khoom, EventArgs e)

{

MoveCursorSkipVideo ();

Xov. Sleep (10);

DoMouseClick ();

}

private void textBoxXposVid_TextChanged (tus xa khoom, EventArgs e)

{

sim

{

vidX = int. Parse (textBoxXposVid. Text);

}

ntes

{

textBoxXposVid. Text = vidX + "";

}

}

private void textBoxYposVid_TextChanged (tus xa khoom, EventArgs e)

{

sim

{

vidY = int. Parse (textBoxYposVid. Text);

}

ntes

{

textBoxYposVid. Text = vidY + "";

}

}

ntiag tug void checkBoxEnable_CheckedChanged (tus xa khoom, EventArgs e)

{

enableAudioChange = checkBoxEnable. Checked;

}

}

[StructLayout (LayoutKind. Sequential)]

pej xeem teeb POINT

{

pej xeem int x;

pej xeem int y;

}

}

Pom zoo: