์๋
ํ์ธ์.
์ธ๊ฐ์ @joonghoonlee์
๋๋ค.

๋ง์ค ๋ฌผ์ ๊ตฌ๋งคํ๋ฌ ์ฝ์คํธ์ฝ์ ๋ค๋ ์์ต๋๋ค.
์ธ์ ? ์ด์ !
์๋ฌดํผ ๋ฌผ๋ง ๋ฑ ์ฌ์ ๊ณ์ฐ๋๋ก ํฅํ์ต๋๋ค.
์ฌ๋ฌ๋ถ๋ค์ ๊ณ์ฐ๋๋ก ํฅํ๋ฉฐ, ์ด๋ค ํ๋๊ณผ ์๊ฐ์ ํ์ญ๋๊น?
์ ๋ ๋นจ๋ฆฌ ๊ณ์ฐํ๊ณ , ๊ณ์ฐ๋๋ฅผ ๋น ์ ธ ๋์ค๊ธฐ ์ํด ์ค์ ์ ์ฌ๋๋ค์ ์ค์บํ๊ฒ๋ฉ๋๋ค.
๋จผ์ ์ค์ ๊ธธ์ด, ์นดํธ์ ๋ค์ด์๋ ๋ฌผํ์ ์, ์ฑ๋ณ, ๋์ด, ๋จ์ฒด์ธ์ง ํผ์์ธ์ง ์ฌ๋ถ๋ฑ์
๋ฐ์ ธ์ ๊ณ์ฐ๋๋ฅผ ์ ํฉ๋๋ค.
ํ์ง๋ง ์ฌ๋์ ๊ฐ์ ์ํ ์ด๋ฐ ์ ํ์ ์ ๋ง์ง ์๋ ๊ฒฝ์ฐ๋ ๋ง์ต๋๋ค.
step 1.0์์๋ ์ ํํ๊ณ ์ธ์ธํ๊ฒ ์๋ ค๋๋ฆฌ๋ ค๋ค๋ณด๋ ๋ค์ ๋ฃจ์ฆํ๊ณ
๋ผ๋ฉด๋ฐ์นจ์ฉ ๋์๋ฅผ ์ฝ๋ ๋๋์ ๋ง์ด ๋๋ฆฐ๊ฒ๊ฐ์ ์ข ๋ฐ๊ฟ๋ณด๋ คํฉ๋๋ค.
์ด๋ป๊ฒ? ์ด๋ ๊ฒ!!
๋์์๋ถํฐ ๊ฐ์ ํ์๊ฒ ์ต๋๋ค.
๋ณด์๋ฉด ์๊ฒ ์ง๋ง ํ๋ชฉ๋ถ๋ถ์ ๊ฒ์ถ์ ํ
์คํธ ํด๋ณด์์ต๋๋ค.(feat.์๋ฐ์)
๋์์์ ๋ณด์ด๋ test๋ ์๋์ด๋
ธ UNO๋ณด๋์ ์์ฒด์ธ์ ์ฐํ๋ฅผ ์ฐ๊ฒฐํ ๊ตฌ์กฐ์
๋๋ค.
์ฆ ์กฐ๋ง๊ฐ ์๋์ด๋
ธ์ ์ค๊ณํ ๋ณด๋๋ฅผ ์ฐ๊ฒฐํด ์ฌ์ฉํ๋ ๋ฒ๋ ์๋ ค๋๋ฆด ์์ ์
๋๋ค.
๊ทธ๋๋ ํน์๋ ์์๊ฐ์ค ๋ถ์ด ์์ผ์๋ค๋ฉด, ์ธ์ ๋ ์คํ์
๋๋ค~
๊ทธ๋ฐ ์๋ฏธ์์
#include <avr/interrupt.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
int a = 300; //ํ์ ์์ง์์๋ ๊ทผ์ ๋ ๊ฐ์ด ์ต๋๋ก ๋์ค๋ ๊ฐ์ ์
๋ ฅํด์ผํจ.
int b = 300;
int c = 300;
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
//////////////////////////////////////////////////////////์ผ์ชฝ ์ฃผ๋จน ์ด๊ธฐ๊ฐ
ax12SetRegisterSoft2( 1, AX_GOAL_POSITION_L , 1024 - 100);
ax12SetRegisterSoft2( 2, AX_GOAL_POSITION_L , 0 + 50);
//////////////////////////////////////////////////////////์ค๋ฅธ์ชฝ ์ฃผ๋จน ์ด๊ธฐ๊ฐ
ax12SetRegisterSoft2( 3, AX_GOAL_POSITION_L , 0 + 100);
ax12SetRegisterSoft2( 4, AX_GOAL_POSITION_L , 1024 - 50);
//////////////////////////////////////////////////////////ํํผ ์ด๊ธฐ๊ฐ
ax12SetRegisterSoft2( 5, AX_GOAL_POSITION_L , 512);
delay(100);
}
void loop() {
// read the state of the pushbutton value:
int sensorValue1 = analogRead(A0);
int sensorValue2 = analogRead(A1);
//int sensorValue2 = analogRead(A2);
// Serial.println(sensorValue1); //์ผ์
// Serial.println(sensorValue2); //์ค๋ฅธ์
// Serial.println(sensorValue3); //ํํผ
if (sensorValue1 > a) {
a = sensorValue1;
}
if (sensorValue1 > b) {
a = sensorValue2;
}
// if (sensorValue1 > c) {
// a = sensorValue3;
// }
//////////////////////////////////////////////////////////์ผ์ชฝ ์ฃผ๋จน
if (sensorValue1 > a) {
ax12SetRegisterSoft2( 2, AX_GOAL_POSITION_L , 512);
delay(200);
ax12SetRegisterSoft2( 1, AX_GOAL_POSITION_L , 800);
delay(100);
ax12SetRegisterSoft2( 1, AX_GOAL_POSITION_L , 1024 - 100);
ax12SetRegisterSoft2( 2, AX_GOAL_POSITION_L , 0 + 50);
delay(1000);
}
//////////////////////////////////////////////////////////์ค๋ฅธ์ชฝ ์ฃผ๋จน
if (sensorValue2 > b) {
ax12SetRegisterSoft2( 4, AX_GOAL_POSITION_L , 512);
delay(200);
ax12SetRegisterSoft2( 3, AX_GOAL_POSITION_L , 224);
delay(100);
}
else {
ax12SetRegisterSoft2( 3, AX_GOAL_POSITION_L , 0 + 100);
ax12SetRegisterSoft2( 4, AX_GOAL_POSITION_L , 1024 - 50);
delay(100);
}
//////////////////////////////////////////////////////////ํํผ
// if (sensorValue3 > c) {
// ax12SetRegisterSoft2( 5, AX_GOAL_POSITION_L , 1024 - 200);
// delay(100);
// }
// else {
// ax12SetRegisterSoft2( 5, AX_GOAL_POSITION_L , 512);
// delay(100);
// }
}
void ax12SetRegisterSoft2(int id, int regstart, int data) {
mySerial.write(0xFF);
mySerial.write(0xFF);
mySerial.write(id);
mySerial.write(5);
mySerial.write(AX_WRITE_DATA);
mySerial.write(regstart);
mySerial.write((data & 0xff));
mySerial.write(((data & 0xff00) >> 8));
mySerial.write((0xFF - ((id + 5 + AX_WRITE_DATA + regstart + (data & 0xFF) + ((data & 0xFF00) >> 8)) % 256)));
}
define๊น์ง ์ ๊ธฐ์ ๋๋ฌด ๊ธธ์ด ์ง์ ์ต๋๋ค.^^;;
์ด๋ฒ์ ์ผ๊ฐ๊ทผ์์์ ๊ฒ์ถ์ ๋๋ค.
https://youtu.be/NibgrZ1TDxU(feat.์ฃผ์)
๋ณด์๋ ๊ฒ์ฒ๋ผ ์ ๋์ต๋๋ค.
์ค๋์ ๊ฐ๋จํ๊ณ ๋ช
๋ฃํ๊ฒ ๋ง๋ฌด๋ฆฌํ๋ คํฉ๋๋ค.
๋ณด์
์ ์๊ฒ ์ง๋ง

์ค๋์ ๋์์์ด 2๊ฐ์ง์~~!!
๊ฒฐ๋ก ์!! ์ด์ ์๊ฐ๋ฝ์ ์ํํ์ผ๋, ๋๋จธ์ง ๋ถ๋ถ์ ๊ทผ์ก๋ค์ ์ํํด๋ณธ ๊ฒ์ ์ฌ๋ ธ์ต๋๋ค.
๊ทธ๋์ ๋ฌด์ฒ ๋ง์กฑ์ค๋ฐ ๊ฒฐ๊ณผ๊ฐ ๋์๋จ ๊ฒ๋๋ค.
์ํํํํํํํํํํํํํํ
์ข ์ ๋นํด์ ์ด๋ค์์ ์์ผ๋ก ๊ทธ๋ฆผ์ ๊ทธ๋ ค๋ณด๋ ๋ฐฉ๋ฒ์ ์ฌ์ฉํด๋ณด๊ฒ ์ต๋๋ค;;
๋ค์ํ๊ณ ์๋ฆ๋ต๊ฒ ์ ๊ทผํ๊ฒ ์ต๋๋ค.
๋ถ์ฐ์ ์ค๋์ ๋ฌด์ฒ ํ๋ ธ์ต๋๋ค.
๊ทธ์์ค์๋ ๋ญ๋ง์ ์ธ ์๊ฐ์ด ๋จธ๋ฌผ๋ค ๊ฐ๊ธธ ๊ธฐ๋ํฉ๋๋ค.
๊ฐ์ฌํฉ๋๋ค.