transformer le code en c en utilisant les registres ocr des pin pwm de atmega 328p je suis caller normalement mon programme fonctionne mais on m'a exiger d'utiliser les registres pour presenter cela malgres tout mes efforts meme avec IA je reussir pas a le faire ``#define IR_SENSOR_RIGHT A2
#define IR_SENSOR_LEFT A1
#define MOTOR_SPEED 180
// Right motor
int rightMotorPin1 = 3;
int rightMotorPin2 = 5;
// Left motor
int leftMotorPin1 = 6;
int leftMotorPin2 = 10;
void setup() {
TCCR0B = TCCR0B & B11111000 | B00000010; // This sets PWM frequency as 7812.5 Hz.
pinMode(rightMotorPin1, OUTPUT);
pinMode(rightMotorPin2, OUTPUT);
pinMode(leftMotorPin1, OUTPUT);
pinMode(leftMotorPin2, OUTPUT);
pinMode(IR_SENSOR_RIGHT, INPUT);
pinMode(IR_SENSOR_LEFT, INPUT);
rotateMotor(0, 0);
}
void loop() {
int rightIRSensorValue = analogRead(IR_SENSOR_RIGHT);
int leftIRSensorValue = analogRead(IR_SENSOR_LEFT);
// Define a threshold value to determine if the sensor detects a black line
int threshold = 500;
// If none of the sensors detects black line, then go straight
if (rightIRSensorValue < threshold && leftIRSensorValue < threshold) {
rotateMotor(MOTOR_SPEED, MOTOR_SPEED);
}
// If right sensor detects black line, then turn right
else if (rightIRSensorValue >= threshold && leftIRSensorValue < threshold) {
rotateMotor(-MOTOR_SPEED, MOTOR_SPEED);
}
// If left sensor detects black line, then turn left
else if (rightIRSensorValue < threshold && leftIRSensorValue >= threshold) {
rotateMotor(MOTOR_SPEED, -MOTOR_SPEED);
}
// If both the sensors detect black line, then stop
else {
rotateMotor(0, 0);
}
}
void rotateMotor(int rightMotorSpeed, int leftMotorSpeed) {
if (rightMotorSpeed < 0) {
digitalWrite(rightMotorPin1, LOW);
digitalWrite(rightMotorPin2, HIGH);
} else if (rightMotorSpeed > 0) {
digitalWrite(rightMotorPin1, HIGH);
digitalWrite(rightMotorPin2, LOW);
} else {
digitalWrite(rightMotorPin1, LOW);
digitalWrite(rightMotorPin2, LOW);
}
if (leftMotorSpeed < 0) {
digitalWrite(leftMotorPin1, LOW);
digitalWrite(leftMotorPin2, HIGH);
} else if (leftMotorSpeed > 0) {
digitalWrite(leftMotorPin1, HIGH);
digitalWrite(leftMotorPin2, LOW);
} else {
digitalWrite(leftMotorPin1, LOW);
digitalWrite(leftMotorPin2, LOW);
}
analogWrite(3, abs(rightMotorSpeed)); // Assuming 3 is the PWM pin for the right motor speed control
analogWrite(6, abs(leftMotorSpeed)); // Assuming 6 is the PWM pin for the left motor speed control
}``