Created
August 24, 2019 09:01
-
-
Save nobuhikosawai/6d201d9a0ec8cab2aec9bf106d01bbea to your computer and use it in GitHub Desktop.
鉄道模型。ポインタ付き
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
void setup(){ | |
pinMode(2, INPUT); | |
pinMode(3, INPUT); | |
pinMode(12, INPUT); | |
pinMode(13, INPUT); | |
} | |
void loop(){ | |
int blueButtonState = digitalRead(2); | |
int redButtonState = digitalRead(3); | |
int greenButtonState = digitalRead(12); | |
int yellowButtonState = digitalRead(13); | |
if (blueButtonState == 1 && redButtonState == 0) { | |
//正転(逆転) | |
analogWrite(5,0); | |
analogWrite(6,255);//出力値:1~255 | |
} else if (blueButtonState == 0 && redButtonState == 1) { | |
//逆転(正転) | |
analogWrite(5,255); //出力値:1~255 | |
analogWrite(6,0); | |
} else if (blueButtonState == 1 && redButtonState == 1) { | |
//静止 | |
analogWrite(5,0); | |
analogWrite(6,0); | |
} else { | |
//静止 | |
analogWrite(5,0); | |
analogWrite(6,0); | |
} | |
if (greenButtonState == 0 || yellowButtonState == 0) { | |
analogWrite(7, greenButtonState * 255); | |
analogWrite(8, yellowButtonState * 255); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment