Hi, as you probably will see I’m new to this forum.
I’ve been an old-school plc-programmer and switched over to the arduino, in this case the mega.
In my attempt to power a small car with double electro motor over a sabretooth 2x25 with an arduino mego (will be replaced by a mini!), the output from the arduino to the sabretooth was between 0.9v and 4.5v . I expected from 0 to 5v!
I tried to keep the program as short and compact as possible so I came with the following script:
/* ArduinoMega Example: 2 analog pot-footpedals for sabretooth 2x25 synchron
- Moves two motors on a pegperego gator (kidstoycar)
through a range of positions in response to the position
of two footpedals analog pot-type attached to 2 Analog inputs.
- the sabretooth needs 2.5v for zero output.
0-2.5v is full backwards to stop
2.5-5v is stop to full forward
- acc. pedal and backw. pedal kicked in should result in 2.5v output or full stop.
- acc. pedal and backw. pedal not actuated should result in 2.5v output or full stop.
const int potpinA = A0; // input analog pot accelerator pedal
const int potpinB = A2; // input analog pot backup pedal
const int sabretoothS1out = 9; // output to pin S1 on sabretooth 2x25 pwm
int sensorAvalue = 0; // value from potpinA, acc. pedal
int sensorBvalue = 0; // value from potpinB, backup pedal
int valuedifferenceAB = 0; // if input from potpin A and B is zero, the output to sabretoothS1out should be 128 (range 0-255) or 2.5volt
// this is going to be the output from the arduino to the sabretooth S1 input signal PWM
void setup() /****** SETUP: RUNS ONCE ******/
valuedifferenceAB = 128; // at startup the output of the sabretooth should be 0 volt or full stop. input S1 on sabratooth should been half-value
}//–(end setup )—
void loop() /****** LOOP: RUNS CONSTANTLY ******/
sensorAvalue = analogRead(potpinA); // reads value of accelerator pedal pot
sensorBvalue = analogRead(potpinB); // reads value of backup pedal pot
valuedifferenceAB = map((sensorAvalue-sensorBvalue),-512,512,0,255); // gives output from 0.9v to 4.5v ?? why not 0v to 5v ?
}//–(end main loop )—
Anyone an idea?
Best regards, Hugo