読者です 読者をやめる 読者になる 読者になる

11/30/2016 ロボ足駆動プログラム

① 足部モーター3つ駆動プログラム

int lefta = 8;
int righta = 9;
int leftb =10;
int rightb =11;
int leftc =12;
int rightc =13;

void setup() {
Serial.begin(9600);    
pinMode(lefta, OUTPUT);
pinMode(righta, OUTPUT);
pinMode(leftb, OUTPUT);
pinMode(rightb, OUTPUT);
pinMode(leftc, OUTPUT);
pinMode(rightc,OUTPUT);
}

void loop() {
  if(Serial.available()){
  char cmd = Serial.read();
    
switch (cmd){  
case 'w':
analogWrite(righta, 200);
analogWrite(lefta, 0);
analogWrite(rightb, 200);
analogWrite(leftb, 0);
analogWrite(rightc, 200);
analogWrite(leftc, 0);
Serial.print(F("a\n"));
break;

case 's':
analogWrite(righta, 200);
analogWrite(lefta, 0);
analogWrite(rightb,200);
analogWrite(leftb, 0);
analogWrite(rightc, 200);
analogWrite(leftc, 0);
break;

case 'd':
analogWrite(righta, 200);
analogWrite(lefta, 0);
analogWrite(rightb,200);
analogWrite(leftb, 0);
analogWrite(rightc, 200);
analogWrite(leftc, 0);
break;

case 'a':
analogWrite(righta, 200);
analogWrite(lefta, 0);
analogWrite(rightb,200);
analogWrite(leftb, 0);
analogWrite(rightc, 200);
analogWrite(leftc, 0);
break;

case 'z':
analogWrite(righta, 200);
analogWrite(lefta, 0);
analogWrite(rightb,200);
analogWrite(leftb, 0);
analogWrite(rightc, 200);
analogWrite(leftc, 0);
break;

default://case'o':
analogWrite(righta, 0);
analogWrite(lefta, 0);
analogWrite(rightb, 0);
analogWrite(leftb, 0);
analogWrite(rightc,0);
analogWrite(leftc, 0);
break;
}
   }

Serial.print("righta = ");
Serial.print(digitalRead(righta));
Serial.print("   lefta = ");
Serial.println(digitalRead(lefta));
}