Я пытаюсь использовать мой ардуино и потенциометр, чтобы двигатель вращается в одну сторону, когда потенциометр прошел 0 и вращает другой, когда потенциометр проходит 0 в другом направлении. Код работает на стороне SensorValue < 512, но не на стороне> 507.Управление двигателем с потенциометром
const int analogInPin = A1; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; //
const int analogOutPin_2 = 11; //
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
sensorValue = analogRead(analogInPin);
if (sensorValue < 507) {
analogWrite(analogOutPin, LOW);
outputValue = map(sensorValue, 0, 512, 0, 255);
analogWrite(analogOutPin_2, outputValue);
}
if (512 > sensorValue) {
analogWrite(analogOutPin_2, LOW);
outputValue = map(sensorValue, 512, 1023, 0, 255);
analogWrite(analogOutPin, outputValue);
}
else {
}
delay(2);
}
Кроме выяснить, что правильные значения карты, я думаю, что это правильно, может быть, мой чип сломан – Rufus