<commit_before>// Sketch to control the gimbal motor containing the polariser
// Gimbal controlled by Hobby King ESC. Connect black to ground
// and white to pin 10. (Note that you can only control servos
// on pin 9 and 10.) DO NOT CONNECT RED WIRE.
// Connect gate of transistor to pin 2.

// Run this sketch and then start the power to ESC when
// instructed by serial prompt. This needs to be replaced with
// a transistor/relay.

#include <Servo.h> 
Servo gimbal;
const int laser = 11; // PWM to control laser intensity
const int gimbalPower = 2; // to transistor to switch power to gimbal

void setup() 
{ 
  Serial.begin(9600);
  
  // laser off by default
  pinMode(laser, OUTPUT);
  analogWrite(laser, 0); 
  
  // power off to gimbal by default
  pinMode(gimbalPower,OUTPUT);
  digitalWrite(gimbalPower,LOW); 
  
  gimbal.attach(10);
  gimbal.write(0);
} 
 
void loop() 
{
  if (Serial.available() > 0) {
      int msg = Serial.read();
      
      if (msg == 76) {
        // L = laser on
        analogWrite(laser,255);
        Serial.print("1");
      } else if (msg == 108) {
        // l = laser off
        analogWrite(laser,0);
        Serial.print("1");
      } else if (msg == 71) {
        // G = start
        startGimbal();
        Serial.print("1");
      } else if (msg = 103) {
        // g = stop
        gimbal.write(0);
        digitalWrite(gimbalPower, LOW);
        Serial.print("1");
      }
  }
}

void startGimbal()
{
  digitalWrite(gimbalPower,HIGH); // Starts power 
  delay(1750);// picked this value by trial and error
  
  // have to ramp up the value like a joystick
  for (int i = 0; i < 181; i++) {
    gimbal.write(i);
    delay(25); // picked this value by trial and error
    //Serial.println(i);
  }
}
<commit_msg>Check if gimbal already running Only start the motor if it's not already running<commit_after>// Sketch to control the gimbal motor containing the polariser
// Gimbal controlled by Hobby King ESC. Connect black to ground
// and white to pin 10. (Note that you can only control servos
// on pin 9 and 10.) DO NOT CONNECT RED WIRE.
// Connect gate of transistor to pin 2.

// Run this sketch and then start the power to ESC when
// instructed by serial prompt. This needs to be replaced with
// a transistor/relay.

#include <Servo.h> 
Servo gimbal;
const int laser = 11; // PWM to control laser intensity
const int gimbalPower = 2; // to transistor to switch power to gimbal

// need to keep track of gimbal status because if it's already on
// and you try and turn it on it will stop and then restart.
boolean gimbalOn = false;

void setup() 
{ 
  Serial.begin(9600);
  
  // laser off by default
  pinMode(laser, OUTPUT);
  analogWrite(laser, 0); 
  
  // power off to gimbal by default
  pinMode(gimbalPower,OUTPUT);
  digitalWrite(gimbalPower,LOW); 
  
  gimbal.attach(10);
  gimbal.write(0);
} 
 
void loop() 
{
  if (Serial.available() > 0) {
      int msg = Serial.read();
      
      if (msg == 76) {          // L = laser on
        analogWrite(laser,255);
        Serial.print("1");
      } else if (msg == 108) {  // l = laser off
        analogWrite(laser,0);
        Serial.print("1");
      } else if (msg == 71) {   // G = start
        // only switch it on if it's not running
        if (gimbalOn == false) {
          startGimbal();
          gimbalOn = true;
        }
        Serial.print("1");
      } else if (msg = 103) {   // g = stop
        gimbal.write(0);
        digitalWrite(gimbalPower, LOW);
        Serial.print("1");
        gimbalOn = false;
      }
  }
}

void startGimbal()
{
  digitalWrite(gimbalPower,HIGH); // Starts power 
  delay(1750);// picked this value by trial and error
  
  // have to ramp up the value like a joystick
  for (int i = 0; i < 181; i++) {
    gimbal.write(i);
    delay(25); // picked this value by trial and error
    //Serial.println(i);
  }
}

{'fraction_non_alphanumeric': 0.11685625646328852, 'fraction_numerical': 0.024301964839710446, 'mean_word_length': 2.341105354058722, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6916712', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1260, 'n_words': 454}