Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
KentaYanagi committed Sep 15, 2022
0 parents commit ff1cb3a
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
25 changes: 25 additions & 0 deletions PIDcontroll.ino
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;

}
63 changes: 63 additions & 0 deletions skech-rotaryencoding.ino
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秒)待ちます
}
12 changes: 12 additions & 0 deletions sketch_may18a.ino
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);
}
9 changes: 9 additions & 0 deletions sketch_may18b.ino
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);
}

0 comments on commit ff1cb3a

Please sign in to comment.