Hello,
I want to make a small steeringrobot with a DC motor connected to arduino which let’s the steering wheel turn with a sinusoidal movement with a pre-defined frequency.
I already tried with the build in sin() function of arduino but it seems like I can’t choose any step/frequency lower than 1?
I also saw on several forums that the most people use sin tables, but what is the difference between the sin tables and the sin() function of arduino?
This is the code I already have:
int MotorLinks=5;
int MotorRechts=6;
int frequency=1; //In Hz
int K=1; //Correctiefactor (P-regeling)
const float pi = 3.14;
float sinfunction=0;
int x=0;
void setup() {
pinMode(MotorLinks, OUTPUT);
pinMode(MotorRechts, OUTPUT);
Serial.begin(9600);
}
void loop() {
int frequency_realtime=frequency*K;
Serial.println(frequency_realtime);
for(x=0;x<50*pi;x++){
sinfunction=255*sin(x*frequency_realtime);
Serial.println(sinfunction);
delay(150);
if(sinfunction<=0){
sinfunction=-sinfunction;
analogWrite(MotorLinks,0);
}else{
analogWrite(MotorRechts,0);
}
}
}