-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ff1cb3a
Showing
4 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
void setup() { | ||
// put your setup code here, to run once: | ||
|
||
|
||
|
||
} | ||
|
||
const int Kp=1; | ||
const int Ki=2; | ||
const int Kd=3; | ||
int preValueDif=0; | ||
int sumValueDif=0; | ||
|
||
void loop() { | ||
// put your main code here, to run repeatedly: | ||
|
||
int input=2; | ||
int goal=3; | ||
int ValueDif=goal-input; | ||
sumValueDif+=ValueDif; | ||
int DValueDif=ValueDif-preValueDif; | ||
int output=Kp*ValueDif+Ki*sumValueDif+Kd*DValueDif; | ||
preValueDif=ValueDif; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
int pinA=2; | ||
int pinB=4; | ||
|
||
int preValA=-1; | ||
int preValB=-1; | ||
int rotation=0; | ||
|
||
int JudgeHighLow(int a){ | ||
if(a==HIGH)return 1; | ||
else return 0; | ||
} | ||
|
||
int JudgeRotate(int a,int b, int preA, int preB){ | ||
if(preA==0 && preB==0){ | ||
if(a==1 && b==0)return 1; | ||
else if(a== 0 && b==1)return -1; | ||
else return 0; | ||
} | ||
if(preA==1 && preB==0){ | ||
if(a==1 && b==1)return 1; | ||
else if(a== 0 && b==0)return -1; | ||
else return 0; | ||
} | ||
if(preA==1 && preB==1){ | ||
if(a==0 && b==1)return 1; | ||
else if(a== 1 && b==0)return -1; | ||
else return 0; | ||
} | ||
if(preA==0 && preB==1){ | ||
if(a==0 && b==0)return 1; | ||
else if(a== 1 && b==1)return -1; | ||
else return 0; | ||
} | ||
} | ||
|
||
void setup() { //一回だけ実行 | ||
pinMode(13, OUTPUT); //LEDを接続した13番ピンを出力用に設定する | ||
Serial.begin(9600); | ||
pinMode(pinA, INPUT); | ||
pinMode(pinB, INPUT); | ||
preValA=JudgeHighLow(digitalRead(pinA)); | ||
preValB=JudgeHighLow(digitalRead(pinB)); | ||
} | ||
|
||
|
||
void loop() { //{}内を無限ループで実行 | ||
//digitalWrite(13, HIGH); | ||
int valA=JudgeHighLow(digitalRead(pinA)); | ||
int valB=JudgeHighLow(digitalRead(pinB)); | ||
rotation += JudgeRotate(valA, valB, preValA, preValB); | ||
if (rotation<0) rotation+=5000; | ||
else rotation%=5000; | ||
Serial.println(rotation, DEC); | ||
preValA=valA; | ||
preValB=valB; | ||
/* | ||
Serial.write('0' + valA); | ||
Serial.write(' '); | ||
Serial.write('0' + valB); | ||
Serial.write(n); | ||
*/ | ||
//delay(500); //1000ms(1秒)待ちます | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
void setup() { | ||
// put your setup code here, to run once: | ||
pinMode(3, OUTPUT); | ||
} | ||
|
||
void loop() { | ||
// put your main code here, to run repeatedly: | ||
analogWrite(3, 200); | ||
delay(1000); | ||
analogWrite(3, 50); | ||
delay(1000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
void setup() { | ||
Serial.begin(9600); | ||
} | ||
|
||
void loop() { | ||
Serial.print("*** Arduino test ***"); | ||
Serial.println("+++ Uno R3 test +++"); | ||
delay(300); | ||
} |