// for https://forum.arduino.cc/t/trouble-with-ardupid-h-library/1189957/11
const byte LHS = 11;
const byte RHS = 10;
const int KnobPin = A3;
int lastKnob ;
int thresholdL = -10;
int thresholdR = 10;
void setup() {
// put your setup code here, to run once:
pinMode(LHS, OUTPUT);
pinMode(RHS, OUTPUT);
lastKnob = -1; // make sure it adjusts // analogRead(KnobPin)-512;
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
int knob = analogRead(KnobPin)-512;
if(knob != lastKnob){ //change
if(knob <= thresholdL){
int offset = map(knob,-512,thresholdL,0,255);
analogWrite(LHS, offset);
analogWrite(RHS, 255);
// Serial.print(offset);
} else if (knob >= thresholdR) {
int offset = map(knob,thresholdR,511,255,0);
analogWrite(LHS, 255);
analogWrite(RHS, offset);
// Serial.print(offset);
} else {
analogWrite(LHS, 255);
analogWrite(RHS, 255);
Serial.print('.');
}
Serial.print(knob > lastKnob? "^": "v");
lastKnob = knob;
}
}