<commit_before>#include <wiringPi.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <softPwm.h>

const int speedMax = 100;

// Motor 1 1st: GPIO 0, aka pin 11
const int motor1pin1 = 0;
// Motor 1 2nd: GPIO 1, aka pin 12
const int motor1pin2 = 1;

// Motor 2 1st: GPIO 3, aka pin 15
const int motor2pin1 = 3;
// Motor 2 2nd: GPIO 4, aka pin 16
const int motor2pin2 = 4;

void motor1(int pin1, int pin2)
{
  digitalWrite(motor1pin1, pin1);
  digitalWrite(motor1pin2, pin2);
}

void motor2(int pin1, int pin2)
{
  digitalWrite(motor2pin1, pin1);
  digitalWrite(motor2pin2, pin2);
}

void close()
{
  motor1(LOW, LOW);
  motor2(LOW, LOW);
}

int main()
{
  if (-1 == wiringPiSetup())
  {
    printf("setup wiringPi failed!\n");
    return 1;
  }

  signal(SIGINT, close);

  // Set pin mode
  pinMode(motor1pin1, OUTPUT);
  pinMode(motor1pin2, OUTPUT);
  pinMode(motor2pin1, OUTPUT);
  pinMode(motor2pin2, OUTPUT);

  //Software PWM
  if (0 == softPwmCreate(motor1pin1, 0, speedMax))
  {
    printf("softPwmCreate ok for motor 1\n");
  }
  if (0 == softPwmCreate(motor2pin1, 0, speedMax))
  {
    printf("softPwmCreate ok for motor 2\n");
  }
  softPwmWrite(motor1pin1, 30);
  softPwmWrite(motor2pin1, 30);

  close();

  printf("Moving forward\n");

  motor1(HIGH, LOW);
  motor2(HIGH, LOW);

  sleep(3);

  /*printf("Moving backward\n");

  motor1(LOW, HIGH);
  motor2(LOW, HIGH);

  sleep(1);*/

  close();

  return 0;
}<commit_msg>motor.c: Add software PWM for backward.<commit_after>#include <wiringPi.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <softPwm.h>

const int speedMax = 200;

// Motor 1 1st: GPIO 0, aka pin 11
const int motor1pin1 = 0;
// Motor 1 2nd: GPIO 1, aka pin 12
const int motor1pin2 = 1;

// Motor 2 1st: GPIO 3, aka pin 15
const int motor2pin1 = 3;
// Motor 2 2nd: GPIO 4, aka pin 16
const int motor2pin2 = 4;

void motor1(int pin1, int pin2)
{
  digitalWrite(motor1pin1, pin1);
  digitalWrite(motor1pin2, pin2);
}

void motor2(int pin1, int pin2)
{
  digitalWrite(motor2pin1, pin1);
  digitalWrite(motor2pin2, pin2);
}

void brake()
{
  softPwmWrite(motor1pin1, 0);
  softPwmWrite(motor1pin2, 0);
  softPwmWrite(motor2pin1, 0);
  softPwmWrite(motor2pin2, 0);
  motor1(LOW, LOW);
  motor2(LOW, LOW);
}

void enablePWM(pin, speed)
{
  if (0 != softPwmCreate(pin, 0, speed))
  {
    printf("ERROR: Cannot enable software PWM for pin %d", pin);
  }
}

int main()
{
  if (-1 == wiringPiSetup())
  {
    printf("setup wiringPi failed!\n");
    return 1;
  }

  signal(SIGINT, brake);

  // Set pin mode
  pinMode(motor1pin1, OUTPUT);
  pinMode(motor1pin2, OUTPUT);
  pinMode(motor2pin1, OUTPUT);
  pinMode(motor2pin2, OUTPUT);

  //Software PWM
  enablePWM(motor1pin1, speedMax);
  enablePWM(motor1pin2, speedMax);
  enablePWM(motor2pin1, speedMax);
  enablePWM(motor2pin2, speedMax);

  brake();

  printf("Moving forward\n");

  softPwmWrite(motor1pin1, 90);
  softPwmWrite(motor2pin1, 90);

  motor1(HIGH, LOW);
  motor2(HIGH, LOW);

  sleep(3);

  printf("Stop\n");

  brake();
  sleep(5);

  printf("Moving backward\n");

  softPwmWrite(motor1pin2, 70);
  softPwmWrite(motor2pin2, 70);

  motor1(LOW, HIGH);
  motor2(LOW, HIGH);

  sleep(3);

  brake();

  return 0;
}
{'fraction_non_alphanumeric': 0.14695893794380982, 'fraction_numerical': 0.06205619018215498, 'mean_word_length': 3.8868778280542986, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3073925', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1307, 'n_words': 332}