Skip to content

Instantly share code, notes, and snippets.

@ymt117
Last active November 21, 2018 05:46
Show Gist options
  • Save ymt117/1b4b46b52df050628812f843fe81b65b to your computer and use it in GitHub Desktop.
Save ymt117/1b4b46b52df050628812f843fe81b65b to your computer and use it in GitHub Desktop.
100kinSAT - モータの動作テスト用プログラム
const int motorA[3] = {4, 13, 25}; // AIN1, AIN2, PWMA
const int motorB[3] = {14, 27, 26}; // BIN1, BIN2, PWMB
const int CHANNEL_A = 0;
const int CHANNEL_B = 1;
const int LEDC_TIMER_BIT = 8;
const int LEDC_BASE_FREQ = 490;
void setup() {
for(int i = 0; i < 3; i++){
pinMode(motorA[i], OUTPUT);
pinMode(motorB[i], OUTPUT);
}
ledcSetup(CHANNEL_A, LEDC_BASE_FREQ, LEDC_TIMER_BIT);
ledcSetup(CHANNEL_B, LEDC_BASE_FREQ, LEDC_TIMER_BIT);
ledcAttachPin(motorA[2], CHANNEL_A);
ledcAttachPin(motorB[2], CHANNEL_B);
}
void loop() {
// 正転
digitalWrite(motorA[0], LOW);
digitalWrite(motorA[1], HIGH);
ledcWrite(CHANNEL_A, 80);
digitalWrite(motorB[0], LOW);
digitalWrite(motorB[1], HIGH);
ledcWrite(CHANNEL_B, 80);
delay(1000);
// 停止
digitalWrite(motorA[0], LOW);
digitalWrite(motorA[1], LOW);
ledcWrite(CHANNEL_A, HIGH);
digitalWrite(motorB[0], LOW);
digitalWrite(motorB[1], LOW);
ledcWrite(CHANNEL_B, HIGH);
delay(1000);
// 逆転
digitalWrite(motorA[1], LOW);
digitalWrite(motorA[0], HIGH);
ledcWrite(CHANNEL_A, 80);
digitalWrite(motorB[1], LOW);
digitalWrite(motorB[0], HIGH);
ledcWrite(CHANNEL_B, 80);
delay(1000);
// 停止
digitalWrite(motorA[0], LOW);
digitalWrite(motorA[1], LOW);
ledcWrite(CHANNEL_A, HIGH);
digitalWrite(motorB[0], LOW);
digitalWrite(motorB[1], LOW);
ledcWrite(CHANNEL_B, HIGH);
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment