Cov txheej txheem:

Mini Control Pad rau Photoshop (Arduino): 6 Kauj Ruam
Mini Control Pad rau Photoshop (Arduino): 6 Kauj Ruam

Video: Mini Control Pad rau Photoshop (Arduino): 6 Kauj Ruam

Video: Mini Control Pad rau Photoshop (Arduino): 6 Kauj Ruam
Video: Ducky Bhai Trolls Urfi Javed 2024, Kaum ib hlis
Anonim
Mini Control Pad rau Photoshop (Arduino)
Mini Control Pad rau Photoshop (Arduino)

Nov yog kuv yuav qhia koj yuav ua li cas thiaj ua tau cuab yeej me me los pab koj ua haujlwm hauv Photoshop sai dua!

Cov twj siv tshwj xeeb tau tsim rau PS tsis yog qhov tshiab, tab sis lawv tsis ua raws qhov kuv xav tau. Raws li tus neeg pleev xim, kuv lub sijhawm ntau hauv Photoshop tau siv kho qhov teeb tsa txhuam, thiab kuv xav tias cov nyees khawm luv yooj yim tsis muab rau kuv tswj kom phim kuv cov haujlwm. Yog li kuv txiav txim siab los ua kuv tus kheej cov keyboard, ib qho uas me me, tsis cuam tshuam dab tsi, thiab muaj cov xov tooj los muab qhov kev sib cuam tshuam zoo sib xws uas kuv ib txwm xav tau.

Txoj hauv kev nws ua haujlwm yog yooj yim: txhawm rau ua kom lub microcontroller cuam tshuam nrog Photoshop, peb ua kom zoo dua ntawm qhov luv luv. Nrog lub rooj tsavxwm uas lub khoos phis tawj tuaj yeem nyeem ua cov keyboard/nas, txhua yam peb yuav tsum ua yog siv qee txoj kab yooj yim ntawm cov cai los qhia rau lub khoos phis tawj nyeem txhua qhov kev nkag ua ke ua ke ntawm cov lej nias. Tam sim no lub khawm rov qab tsuas yog lub pob nyem tawm!

Cia peb pib! Rau qhov haujlwm no koj yuav xav tau:

  • 1 Sparkfun ProMicro (lossis Arduino Leonardo, tsis pom zoo)
  • 1 micro-USB adapter
  • 6 lub pob nyem (lossis tus lej koj nyiam)
  • 10k Ohm resistors (1 rau txhua lub khawm)
  • 1 potentiometer
  • 1 teb encoder
  • xov hlau, daim txiag ntoo, perfboard, cov laug, lub taub hau, thiab lwm yam.

Koj tuaj yeem siv Arduino Leonardo rau txoj haujlwm no, tab sis ProMicro yog lwm txoj hauv kev pheej yig dua uas siv tib lub atmega32u4 nti zoo ib yam, muaj tus pin ntau dua thiab los hauv daim ntawv me dua, ua kom zoo tshaj rau cov keyboard.

Txhawm rau ua haujlwm ProMicro hauv Arduino IDE koj yuav xav tau teeb tsa qee yam ua ntej. Koj tuaj yeem nyeem ntxiv txog nws hauv SparkFun phau ntawv qhia:

Yog tias koj lub khoos phis tawj muaj teeb meem nrhiav lub cuab yeej, xyuas kom lub micro-USB uas koj siv tsis yog lub zog nkaus xwb thiab txhawb nqa cov ntaub ntawv xa mus.

Nov yog kuv thawj qhov haujlwm Arduino, thiab haum rau cov pib tshiab.

Kauj Ruam 1: Prototyping Control Pad

Prototyping Control Pad
Prototyping Control Pad

Kuv pom zoo koj sim koj txoj haujlwm ntawm lub khob cij ua ntej ua ntej koj pib soldering.

Ntawm no koj tuaj yeem pom kuv schematic.

Cov nyees khawm 1 thiab 2 yuav rov ua dua thiab rov ua dua, 3 txog 5 yog rau Txhuam Txhuam, Cuab Yeej thiab Lasso cov cuab yeej, khawm 6 yog khawm ceev. Tus encoder thiab potmeter tswj Qhov Loj thiab Opacity feem.

Nco ntsoov tias kuv sab laug tes thiab tsim cov txheej txheem hauv txoj kev uas yooj yim tshaj plaws rau kuv siv. Pom lub sijhawm koj siv koj daim ntawv tais ua lub sijhawm los xav txog lub luag haujlwm uas koj xav kom koj tus tswj kom muaj, dab tsi ua haujlwm zoo tshaj rau koj thiab thaum kawg yog tias koj xav tau cov khoom ntxiv los ua nws.

Kauj ruam 2: Laub Khawm

Laub Khawm
Laub Khawm

Cov nyees khawm yog qhov yooj yim tshaj plaws los siv. Cia peb saib cov cai:

#suav nrog

const cov nyees khawm = {2, 3, 4, 5, 6, 7, 8, 9}; // array ntawm txhua lub khawm pins char ctrlKey = KEY_LEFT_GUI; // siv qhov kev xaiv no rau Windows thiab Linux: // char ctrlKey = KEY_LEFT_CTRL; char shiftKey = KEY_LEFT_SHIFT; char altKey = KEY_LEFT_ALT; tsis muaj teeb tsa teeb tsa () {// muab koj cov cai teeb tsa ntawm no, kom khiav ib zaug: Serial.begin (9600); Keyboard.begin (); // Nyees khawm - voj los ntawm cov kab thiab tshawb rau nias rau (int i = nyees khawm [0]; kuv <(sizeof (nyees khawm)/sizeof (nyees khawm [0]))+khawm [0]; ++ kuv) { pinMode (kuv, INPUT); }} boolean readButton (int tus pin) {// kos thiab debounce cov nyees khawm yog (digitalRead (tus pin) == HIGH) {ncua sijhawm (10); yog (digitalRead (tus pin) == HIGH) {rov muaj tseeb; }} rov tsis tseeb; } void doAction (int tus pin) {// ua haujlwm hloov pauv (tus pin) {// ---- Shortcuts ---- // Undo case 4: Keyboard.press (ctrlKey); Keyboard.print ('z'); Serial.print ("tswv yim"); Serial.println (tus pin); ncua (200); Keyboard.releaseAll (); tawg; // Rov ua rooj plaub 5: Keyboard.press (ctrlKey); Keyboard.print ('y'); Serial.print ("tswv yim"); Serial.println (tus pin); ncua (200); Keyboard.releaseAll (); tawg; // Txhuam cov ntaub ntawv 6: Keyboard.press ('b'); Serial.print ("tswv yim"); Serial.println (tus pin); ncua (200); Keyboard.releaseAll (); tawg; // Cov ntaub ntawv lwv 7: Keyboard.press ('e'); Serial.print ("tswv yim"); Serial.println (tus pin); ncua (200); Keyboard.releaseAll (); tawg; // Lasso rooj plaub 8: Keyboard.press ('l'); Serial.print ("tswv yim"); Serial.println (tus pin); ncua (200); Keyboard.releaseAll (); tawg; // Txuag rooj plaub 9: Keyboard.press (ctrlKey); Keyboard.print ('tus'); Serial.print ("tswv yim"); Serial.println (tus pin); ncua (200); Keyboard.releaseAll (); tawg; default: Keyboard.releaseAll (); tawg; }}

void voj () {

// muab koj cov cai tseem ceeb ntawm no, kom rov ua dua:

rau (int i = nyees khawm [0]; kuv <sizeof (nyees khawm)/sizeof (nyees khawm [0])+khawm [0]; ++ i) {yog (readButton (i)) {doAction (i); }} // Pib dua qhov hloov kho Keyboard.releaseAll ();

}

Lawv ncaj ncaj. Txhawm rau kom lub khoos phis tawj lees paub lub pob nyem ua qhov tseem ceeb nias peb yooj yim siv Keyboard.press () ua haujlwm. Yog li txhawm rau qhib qhov Undo shortcut (ctrl+z), peb yooj yim siv Keyboard.press (ctrlKey) thiab tom qab ntawd Keyboard.press ('z'). Nco ntsoov koj yuav tsum suav nrog Keyboard.h, thiab pib ua cov keyboard kom nkag tau rau cov haujlwm no.

Cov pins nkag tau muab khaws cia rau hauv ib qho array, yog li koj tuaj yeem yooj yim voj los ntawm txhua ntawm lawv hauv lub voj () ua haujlwm. Ib txoj hauv kev yooj yim rau kev nkag mus thiab teeb tsa qhov ntev hauv c ++ los ntawm kev faib qhov loj ntawm tag nrho cov pawg los ntawm cov ntsiab lus array, ntxiv rau ib ntu. Peb voj los ntawm txhua lub nyees khawm txhawm rau txheeb xyuas yog tias ib tus tau raug nias.

Txhawm rau khaws txhua yam kev teeb tsa, Kuv khaws txhua yam ntawm kuv lub pob qhov ua hauv cov lus hloov pauv ntawm txoj haujlwm uas siv tus lej tus lej raws li kev sib cav.

Yog tias koj xav kom koj cov nyees khawm ua ntau yam sib txawv, lossis xav ntxiv cov nyees khawm ntxiv, yooj yim hloov cov ntsiab lus ntawm kev ua haujlwm ua haujlwm!

Vim tias cov nyees khawm lub cev ua haujlwm li cas, peb yuav tsum tau tshaj tawm lawv. Qhov no yog txhawm rau tiv thaiv qhov program kom nyeem txhua yam tsis xav tau tshwm sim los ntawm lub caij nplooj ntoo hlav ntawm lub khawm. Muaj ntau txoj hauv kev los ua qhov no, tab sis kuv ntxiv qhov yooj yim nyeemButton () ua haujlwm uas saib xyuas qhov ntawd.

Tsuas yog xaim koj cov nyees khawm nrog qee qhov 10k resistors, thiab koj yuav tsum yog kub!

Kauj Ruam 3: Tus Potentiometer

Lub Potentiometer
Lub Potentiometer

Tam sim no mus rau lub potmeter:

#suav nrog

int dial0 = 0; tsis muaj teeb tsa teeb tsa () {// muab koj cov cai teeb tsa ntawm no, kom khiav ib zaug: Serial.begin (9600); Keyboard.begin (); // Dial dial0 = analogRead (0); dial0 = daim ntawv qhia (dial0, 0, 1023, 1, 20); } void dialAction (int dial, int newVal, int lastVal) {hloov (hu) {// Cov ntaub ntawv tsis pom kev 0: ncua (200); yog (newVal! = lastVal) {int decim = ((newVal*5)/10); int chav = ((newVal *5)% 10); yog (newVal == 20) {Keyboard.write (48+0); Keyboard.write (48+0); Serial.println ("hu xov tooj 1"); } lwm {decim = txwv (decim, 0, 9); unit = txwv (chav, 0, 9); Serial.println (tshiabVal*2); Keyboard.write (48+decim); Keyboard.write (48+chav nyob); }} dial0 = newVal; tawg; default: tawg; }} // ------------------ MAIN LOOP ------------------------- void loop () {// muab koj cov cai tseem ceeb ntawm no, kom rov ua dua: // Opacity // ncua (500); int val0 = analogRead (0); val0 = daim ntawv qhia (val0, 0, 1023, 1, 20); //Serial.print ("dial0:"); //Serial.println(val0); yog (val0! = dial0) {// Ua ib yam dab tsi dialAction (0, val0, dial0); }}

Lub potmeter ua raws tib lub tswv yim, tab sis nws yog me ntsis dag.

Ua ntej peb saib seb peb xav kom nws ua haujlwm li cas: Photoshop muaj qee qhov yooj yim siv los hloov txhuam txhuam tsis pom kev. Yog tias koj nias ib tus lej lej, qhov tsis pom kev yuav sib npaug tus lej*10. Tab sis yog tias koj nias ob tus lej, nws yuav nyeem tus lej thib ob ua ib chav, muab kev tswj hwm kom raug rau koj.

Yog li peb xav kom peb lub tshuab ntsuas hluav taws xob ua daim ntawv qhia nws qhov kev hloov mus rau ib feem pua, tab sis peb tsis xav ua nws txhua lub sijhawm vim qhov ntawd yuav ua dag. Peb tsuas yog xav hloov qhov opacity thaum lub potmeter tau tig. Yog li peb khaws tus nqi ntxiv uas peb piv rau analogRead () tus nqi thiab tsuas yog khiav cov ntawv sau thaum muaj qhov sib txawv.

Lwm qhov teeb meem peb yuav nkag mus rau yog yuav ua li cas peb tig analogRead qhov rov qab los int raws li cov tswv yim. Raws li tsis muaj txoj hauv kev yooj yim tig ib qho int rau hauv txoj hlua, peb yuav tau siv tus kheej nws tus kheej. Txawm li cas los xij, yog tias koj yooj yim sau Keyboard.press (int) koj yuav pom tias lub tswv yim yuav tsis yog qhov koj xav tau, thiab hloov lwm tus yuam sij yuav raug nias.

Qhov no vim tias koj cov keyboard cov lej yog txhua tus cim ua tus lej, txhua tus yuam sij muaj nws tus lej ntsuas. Txhawm rau siv tus lej lej kom raug, koj yuav tsum saib lawv cov lej hauv ASCII cov lus:

Raws li koj tuaj yeem pom, cov lej lej pib ntawm qhov ntsuas 48. Yog li txhawm rau nias tus yuam sij raug, txhua yam peb yuav tsum tau ua yog ntxiv tus lej tus lej rau 48. Cov lej thiab lej tus lej yog cais cais.

Thaum kawg, peb xav tau ib txoj hauv kev kom ua kom muaj nuj nqis los ntawm kev dhia rov qab los. Vim tias yog koj sim siv lub xov tooj nrog daim ntawv qhia (val0, 0, 1023, 0, 100), koj yuav pom cov txiaj ntsig ua rau muaj kev ntxhov siab heev. Zoo ib yam li peb tshaj tawm cov nyees khawm, peb yuav kho qhov no los ntawm kev txi qee qhov tseeb. Kuv pom tias ua daim phiaj rau 1-20 thiab tom qab ntawd sib ntxiv qhov kev sib cav tus nqi los ntawm 5 kom pom tau qhov kev pom zoo.

Txhawm rau txuas lub hwj chim, tsuas yog txuas 5V xaim, hauv av xaim thiab xaim hluav taws xob sib txuas thiab yuav tsum tsis muaj teeb meem.

Qhov tseeb lom zem: yog tias koj siv qhov luv no thaum lub cuab yeej zoo li Lasso raug xaiv, nws yuav hloov txheej txheej opacity xwb. Ib yam yuav tsum nco ntsoov.

Kauj Ruam 4: Rotary Encoder

Rotary Encoder
Rotary Encoder

Cov encoders teb yog me ntsis zoo li potentiometers, tab sis tsis muaj kev txwv ntau npaum li cas lawv tuaj yeem tig. Hloov chaw ntawm tus nqi sib piv, peb yuav saib lub encoder txoj kev tig mus digitally. Kuv yuav tsis nkag mus rau ntau yam ntawm cov haujlwm no li cas, tab sis qhov koj yuav tsum paub yog tias nws siv ob tus lej nkag ntawm arduino los qhia rau hauv kev taw qhia uas nws tau tig. Cov encoder teb tuaj yeem ua kom yooj yim dua los ua haujlwm nrog, cov encoders sib txawv yuav xav tau teeb tsa sib txawv. Txhawm rau ua kom yooj yim dua, Kuv yuav ib qho nrog PCB, uas tau npaj kom tau nuv nrog tus poj niam koob. Tam sim no, cov cai:

#suav nrog

// Teb encoder #define outputA 15 #define outputB 14 int counter = 0; koj aState; ua ntej dhau los; teeb tsa tsis muaj dab tsi () {// muab koj cov cai teeb tsa ntawm no, kom khiav ib zaug: // Teb pinMode (outputA, INPUT); pinMode (outputB, INPUT); // Nyeem thawj lub xeev ntawm qhov outputA aLastState = digitalRead (outputA); } void rotaryAction (int dir) {yog (dir> 0) {Keyboard.press (']'); } lwm {Keyboard.press ('['); } Keyboard.releaseAll (); } // ------------------ MAIN LOOP ------------------------- khoob khoob () {// tso koj tus lej tseem ceeb ntawm no, kom rov ua dua: // Loj aState = digitalRead (outputA); yog (aState! = aLastState) {yog (digitalRead (outputB)! = aState) {// counter ++; TebAction (1); } lwm tus {// txee -; TebAction (-1); } //Serial.print("Position: "); //Serial.println(counter); } aLastState = aState; }

Los ntawm lub neej ntawd, Photoshop's] thiab [luv luv nce thiab txo qhov txhuam me me. Ib yam li ua ntej, peb xav kom nkag mus rau cov uas yog qhov tseem ceeb nias. Tus lej nkag xa tus lej nkag mus rau ib zaug (uas nyob ntawm tus qauv), thiab peb xav kom nce/txo tus txhuam me me rau txhua qhov ntawm cov tswv yim no, yog li koj tuaj yeem tig lub xov tooj nce lossis nqis nrawm heev, tab sis kuj tuaj yeem ua tau tswj nws maj mam nrog qhov zoo tshaj.

Ib yam li nrog lub ntsuas hluav taws xob, peb tsuas yog xav ua qhov haujlwm thaum lub xov tooj tau tig. Tsis zoo li lub tshuab ntsuas hluav taws xob, raws li kuv tau piav qhia ua ntej, lub ntsuas hluav taws xob teb muaj ob txoj kev hloov pauv. Peb saib qhov twg ntawm cov no tau hloov pauv los tsim cov lus qhia uas lub xov tooj tau tig.

Tom qab ntawd nyob ntawm qhov kev taw qhia, peb nias qhov yuam kev raug.

Tsuav koj tsis muaj teeb meem tiv tauj, nws yuav tsum ua haujlwm.

Kauj Ruam 5: Muab Nws Txhua Qhov Ua Ke

Muab Nws Tag Nrho Ua Ke
Muab Nws Tag Nrho Ua Ke
Muab Nws Tag Nrho Ua Ke
Muab Nws Tag Nrho Ua Ke
Muab Nws Tag Nrho Ua Ke
Muab Nws Tag Nrho Ua Ke

Tam sim no mus rau soldering. Ua ntej tshaj, peb laum ob lub qhov rau hauv perfboard kom haum rau ob lub xov tooj. peb muab cov nyees khawm khawm thiab lawv cov khoom sib xws. Kuv tau hlais ob lub qhov me me ntxiv kom tso cov xov hlau nkag mus rau saum kom txuag tau qhov chaw hauv qab, tab sis qhov no tsis tsim nyog. Tsis muaj ntau lub tswv yim hlau yog li GND thiab 5V xov hlau sib txuas ua ke, tab sis yog tias koj xav tias muaj tswv yim koj yuav xav ua tus lej. Kuv tau muab lub microcontroller tso rau lwm qhov, me me perfboard, uas haum hauv qab ib sab ntawm tus lej cim thiab lub tshuab ntsuas cua. Tam sim no kuv tau siv tag nrho cov xov hlau mus rau ProMicro. Tsis tas yuav tsum muaj tswv yim, Kuv tsuas yog yuav tsum ua raws tib lub tswv yim ib yam ntawm ib qho ntawm lub khob cij, tab sis kev siv cov khoom me me hauv qhov chaw no tuaj yeem nkag siab tau. Tsis txhob zoo li kuv, siv lub tshuab xaim hluav taws xob thiab lub lauj kaub zoo!

Thaum kawg, koj yuav xav ua rooj plaub zoo rau koj tus phooj ywg Photoshop tshiab. Ib qho zoo dua li kuv, tsawg kawg!

Tab sis yog tias koj mob siab ua nws, siv qee cov duab los qhia thiab kab xev thiab ntsaws rau hauv koj lub micro-USB.

Kauj Ruam 6: Code + Qhia Tawm

Image
Image

Nco ntsoov sim ntsuas lub ntsuas phoo txoj haujlwm thaum koj txav mus rau hauv qhov haujlwm kom tsis txhob xav tsis thoob!

Nov yog tus lej ua tiav:

Ua tsaug ntau ntau rau kev nyeem!

Pom zoo: