Harigami
ログイン
123
anonymous タイトルなし
C
#import <libcolorpicker.h>
#import <objc/runtime.h>

#define PLIST_PATH @"/var/mobile/Library/Preferences/com.minazuki.badgeview.plist"

#define kPrefsChangedNotification "com.minazuki.badgeview/preferencesChanged"

@interface SBIconBadgeView : UIView
@end

static BOOL enabled;
static int borderWidth = 1;
static NSString *borderColor = nil;

static void loadPrefs()
{

     NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:PLIST_PATH];

     enabled = [[prefs objectForKey:@"enabled"] boolValue];
     borderWidth = [[prefs objectForKey:@"borderWidth"] intValue];
     borderColor = [prefs objectForKey:@"borderColor"];

}

static void updateSettings(CFNotificationCenterRef center,
                    void *observer,
                    CFStringRef name,
                    const void *object,
                    CFDictionaryRef userInfo) {
    loadPrefs();
}

%hook SBIconBadgeView
- (void)layoutSubviews

{
	if (enabled) {

            %orig;
            self.clipsToBounds = YES;
            self.layer.cornerRadius = self.frame.size.height/2;
            self.layer.borderColor = [(LCPParseColorString(borderColor, @"#ffffff")) CGColor];

            if (borderWidth == 1) {
                %orig;
                self.layer.borderWidth = 1;
                    }
            else if (borderWidth == 2) {
                %orig;
                self.layer.borderWidth = 2;
                    }
            else if (borderWidth == 3) {
                %orig;
                self.layer.borderWidth = 3;
                    }

	} else {
		return %orig;
	} 
}
%end


%ctor 
{

CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, &updateSettings, CFSTR(kPrefsChangedNotification), NULL, 0);

    @autoreleasepool {
        loadPrefs();
        %init;
    }
}
  • 0
  • 0
anonymous タイトルなし
C
void rev(char *p,int size){
   char x;
   for(int i = 0;i < size/2;i++){
      x = p[i];
      p[i] = p[size-1-i];
      p[size-1-i] = x;
   }
}
  • 0
  • 0
anonymous タイトルなし
C
#include <stdio.h>
int main(void){
    // Your code here!

   double top = 10;
   double under = 1;

   puts("入力してください。");
   //scanf("%lf",&top);
   //scanf("%lf",&under);
   if (top-under<9){
      printf ("aa");
   }else if (9<=top-under&&top-under<11.5 ){
      printf ("a");
   }else if (11.5<=top-under&&top-under<14){
      printf ("b");
   }else if(14<=top-under&&top-under<16.5){
      printf("c");
   }else if(16.5<=top-under&&top-under<19){
      printf("d");
   }else if(19<=top-under&&top-under<21.5){
      printf("e");
   }else if(21.5<=top-under&&top-under<24)
   return 0;
}
  • 0
  • 0
anonymous 回文判定&回文数判定
C
int palin_str(char *p,int size){
   int check = 1;
   for(int i = 0;i < size/2;i++)if(p[i]!=p[size-1-i])check=0;
   return check==0?0:1;
}
int palin_int(int n){
   char p[10];
   int size=0;
   int check = 1;
   for(int i = inf,j = 0;i > 0;i/=10,j++){
      p[j] = n/i;
      if(p[j]>0)size++;
   }
   for(int i = 0;i < p[i];i++)if(p[i]!=p[size-1-i])check=0;
   return check==0?0:1;
}
  • 0
  • 0
anonymous reverse関数
C
void rev(char *p,int size){
   char x;
   for(int i = 0;i < size/2;i++){
      x = p[i];
      p[i] = p[size-1-i];
      p[size-1-i] = x;
   }
}
  • 0
  • 0
anonymous タイトルなし
C
//i2c通信//i2c通信
#include <Wire.h>
//ジャイロセンサ
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>

#define BNO055_SAMPLERATE_DELAY_MS (100)
Adafruit_BNO055 bno = Adafruit_BNO055(-1, 0x28);

//モーターのピン番号

//左後
#define M_l1 5
#define M_l2 4
//左前
#define M_L1 6
#define M_L2 7
//右後
#define M_r1 10
#define M_r2 11
//右前
#define M_R1 13
#define M_R2 12

//超音波センサのピン番号

//左
#define USS_TRIG_L 51
#define USS_ECHO_L 50
//右
#define USS_TRIG_R 52
#define USS_ECHO_R 53
//後
#define USS_TRIG_B 49
#define USS_ECHO_B 48
//前
#define USS_TRIG_C 46
#define USS_ECHO_C 47



//変数

//壁からの距離
float DIS_L;
float DIS_R;
float DIS_B;
float DIS_C;

//モーターの最大スピード(後に変化する)
int maxspeed = 200;

//方位
int m_Value;

//PID制御
int pidk;
int pidm;

//進行方向(-360°~360°)
int kakudo;

//モーター制御におけるx方向とy方向
int a;
int b;

//進行方向(モーター制御関数の中だけで使用)
int susumukakudo;

//ボールからの距離
int kyori;



void setup(){
   //ジャイロセンサ
 if(!bno.begin())
 {
  while(1);
 }
  int8_t temp = bno.getTemp();
 
  bno.setExtCrystalUse(true);

  //シリアル通信
  Serial.begin(9600);

  //i2c通信 
  Wire.begin();

  //超音波センサのピンモード設定
  pinMode(USS_TRIG_R,OUTPUT);
  pinMode(USS_ECHO_R,INPUT);
  pinMode(USS_TRIG_L,OUTPUT);
  pinMode(USS_ECHO_L,INPUT);
  pinMode(USS_TRIG_B,OUTPUT);
  pinMode(USS_ECHO_B,INPUT);
  pinMode(USS_TRIG_C,OUTPUT);
  pinMode(USS_ECHO_C,INPUT);
}


//メインループ
void loop(){
  //ノイズ対策
  delay(100);
    while(1){
    //スイッチ読み取り
    Read_L();
     if(DIS_L<30){
      //試合中の動作
       while(1){
        m_Value = ModCompass();
        //方位修正(回転)
         if(abs(m_Value)>25){
         maxspeed = 0;
         aj(0);
        }
        else{
         //ラインを踏んだ
         if(analogRead(12)>900 || analogRead(13)>50){
         maxspeed = 180;
          while(1){
          int l;
          m_Value = ModCompass();
          Read_C();
          Read_B();
          Read_R();
          Read_L();
          //横にロボットがいない
           if(DIS_L + DIS_R>60){
            //横が近いなら戻る
            if(DIS_L<30 || DIS_R<30){
             if(DIS_L>DIS_R){
             aj(90);
             l = 0;
            }
            else{
            aj(-90); 
            l = 1;
           }
          }
         }
         //前後にロボットがいない
         if(DIS_C + DIS_B>60){
          //前後が近いなら戻る
          if(DIS_C<30|| DIS_B<30){
           if(DIS_C<DIS_B){
           aj(180);
           l = 2;
          }
          else{
          aj(0);
          l = 3;
         }
        }
       }
       //完全に戻った
       if(DIS_L>30&& DIS_R>30 && DIS_C>30 && DIS_B>30){
        while(1){
        m_Value = ModCompass();
        bcnotrun();
        //ラインが横にある
         if(l == 0 || l ==1){
         maxspeed = 100;
         //ラインが右にある
          if(l == 0){
           if(abs(kakudo)<65){
           aj(-10);
          }
          else{
           if(abs(kakudo)<115){
           maxspeed = 0;
           aj(0);
          }
          else{
          aj(-170);
         }
        }
       }
       //ラインが左にある
       else{
        if(abs(kakudo)<65){
        aj(10);
        }
        else{
         if(abs(kakudo)<115){
         maxspeed = 0;
         aj(0);}
           else{
           aj(170);
          }
         }
        }
       }
       //ラインが前後にある
       else{
       maxspeed = 0;
       aj(0);
      }
      //ボールがラインの中に戻った
      if(l == 0 && kakudo>0){
      break;
     }
       if(l == 1 && kakudo<0){
       break;
      }
        if(l == 2 && abs(kakudo)>90){
        break;
       }
         if(l == 3 && abs(kakudo)<90){
         break;
        }
        //ラインを踏んだ
          if(analogRead(12)>900){
          break;
         }
        }
        //不明なので今から調べてみようト思う
        break;
       }
      }
     }
     //ラインの中にいる
     bc();
    }
   }
  }
 }
}


//ボール追跡
void bc(){
//赤外線センサの値(近い=低い)
int seki_A = analogRead(9);
int seki_B = analogRead(10);
int seki_C = analogRead(11);
int seki_D = analogRead(6);
int seki_E = analogRead(7);
int seki_F = analogRead(8);
int seki_G = analogRead(3);
int seki_H = analogRead(4);
int seki_I = analogRead(5);
int seki_J = analogRead(0);
int seki_K = analogRead(1);
int seki_L = analogRead(2);
//一番高かったセンサとその左右ノセンサの平均値(=ボールからの距離)
 if(seki_A<seki_B && seki_A<seki_C && seki_A<seki_D && seki_A<seki_E && seki_A<seki_F && seki_A<seki_G && seki_A<seki_H && seki_A<seki_I && seki_A<seki_J && seki_A<seki_K && seki_A<seki_L){
 kyori = (seki_L+seki_A+seki_B)/3;
}
 else{
  if(seki_B<seki_C && seki_B<seki_D && seki_B<seki_E && seki_B<seki_F && seki_B<seki_G && seki_B<seki_H && seki_B<seki_I && seki_B<seki_J && seki_B<seki_K && seki_B<seki_L){
  kyori = (seki_A+seki_B+seki_C)/3;
 }
  else{
   if(seki_C<seki_D && seki_C<seki_E && seki_C<seki_F && seki_C<seki_G && seki_C<seki_H && seki_C<seki_I && seki_C<seki_J && seki_C<seki_K && seki_C<seki_L){
   kyori = (seki_B + seki_C+ seki_D)/3;
  }
   else{
    if(seki_D<seki_E && seki_D<seki_F && seki_D<seki_G && seki_D<seki_H && seki_D<seki_I && seki_D<seki_J && seki_D<seki_K && seki_D<seki_L){
    kyori = (seki_C+seki_D+seki_E)/3;
   }
    else{
     if(seki_E<seki_F && seki_E<seki_G && seki_E<seki_H && seki_E<seki_I && seki_E<seki_J && seki_E<seki_K && seki_E<seki_L){
     kyori = (seki_D+seki_E+seki_F)/3;
    }
     else{
      if(seki_F<seki_G && seki_F<seki_H && seki_F<seki_I && seki_F<seki_J && seki_F<seki_K && seki_F<seki_L){
      kyori = (seki_E+seki_F+seki_G)/3;
     }
      else{
       if(seki_G<seki_H && seki_G<seki_I && seki_G<seki_J && seki_G<seki_K && seki_G<seki_L){
       kyori = (seki_F+seki_G+seki_H)/3;
      }
       else{
        if(seki_H<seki_I && seki_H<seki_J && seki_H<seki_K && seki_H<seki_L){
        kyori = (seki_G+seki_H+seki_I)/3;
       }
        else{
         if(seki_I<seki_J && seki_I<seki_K && seki_I<seki_L){
         kyori = (seki_H+seki_I+seki_J)/3;
        }
         else{
          if(seki_J<seki_K && seki_J<seki_L){
          kyori = (seki_I+seki_J+seki_K)/3;
         }
          else{
           if(seki_K<seki_L){
           kyori = (seki_J+seki_K+seki_L)/3;
          }
           else{
           kyori = (seki_K+seki_L+seki_A)/3;
          }
         }
        }
       }
      }
     }
    }
   }
  }
 }
}
//赤外線センサの値(近い=高い)
seki_A =-seki_A;
seki_B =-seki_B;
seki_C =-seki_C;
seki_D =-seki_D;
seki_E =-seki_E;
seki_F =-seki_F;
seki_G =-seki_G;
seki_H =-seki_H;
seki_I =-seki_I;
seki_J =-seki_J;
seki_K =-seki_K;
seki_L =-seki_L;
//ボールのx座標とy座標
int Ax = 0.259*seki_A;
int Ay = 0.965*seki_A;
int Bx = 0.707*seki_B;
int By = 0.707*seki_B;
int Cx = 0.965*seki_C;
int Cy = 0.259*seki_C;
int Dx = 0.965*seki_D;
int Dy = -0.259*seki_D;
int Ex = 0.707*seki_E;
int Ey = -0.707*seki_E;
int Fx = 0.259*seki_F;
int Fy = -0.965*seki_F;
int Gx = -0.259*seki_D;
int Gy = -0.965*seki_D;
int Hx = -0.707*seki_E;
int Hy = -0.707*seki_E;
int Ix = -0.965*seki_F;
int Iy = -0.259*seki_F;
int Jx = -0.965*seki_J;
int Jy = 0.259*seki_J;
int Kx = -0.707*seki_K;
int Ky = 0.707*seki_K;
int Lx = -0.259*seki_L;
int Ly = 0.965*seki_L;
int ballx = Ax + Bx + Cx + Dx + Ex + Fx + Gx + Hx + Ix + Jx + Kx + Lx;
int bally = Ay + By + Cy + Dy + Ey + Fy + Gy + Hy + Iy + Jy + Ky + Ly;
//ボールのx座標とy座標
kakudo = atan2(ballx,bally)*53;
maxspeed = 100;
//ボールが見つからない(=審判によるボールの持ち上げ)
 if(kyori>870){
 Read_R();
 Read_L();
 maxspeed = 150;
  if(abs(DIS_R-DIS_L)<20){
  maxspeed = DIS_B;
  Read_B();
   if(DIS_B<40){
   maxspeed = 0;
  }
   else{
   kakudo =180;
  }
 }
  else{
   if(DIS_R<DIS_L){
   kakudo =135;}
    else{
    kakudo = -135;
   }
  }
 }
 //ボールが見える
  else{
    //ボールが正面にある
   if(abs(kakudo)<10){
   maxspeed = 240;
   kakudo = kakudo*90/(kyori/10);
  }
  //ボールが正面にない
  else{
   if(kakudo<0){
   maxspeed = kyori/2-180+(abs(kakudo)/1.5);
   kakudo = kakudo-max((260-(kyori/3)),0);
  }
  else{
  maxspeed = kyori/2-210+(abs(kakudo)/1.5);
  kakudo = kakudo+max((260-(kyori/3)),0);}}}
  aj(kakudo);
}



void bcnotrun(){
int seki_A = analogRead(9);
int seki_B = analogRead(10);
int seki_C = analogRead(11);
int seki_D = analogRead(6);
int seki_E = analogRead(7);
int seki_F = analogRead(8);
int seki_G = analogRead(3);
int seki_H = analogRead(4);
int seki_I = analogRead(5);
int seki_J = analogRead(0);
int seki_K = analogRead(1);
int seki_L = analogRead(2);
 if(seki_A<seki_B && seki_A<seki_C && seki_A<seki_D && seki_A<seki_E && seki_A<seki_F && seki_A<seki_G && seki_A<seki_H && seki_A<seki_I && seki_A<seki_J && seki_A<seki_K && seki_A<seki_L){
 kyori = (seki_L+seki_A+seki_B)/3;
}
 else{
  if(seki_B<seki_C && seki_B<seki_D && seki_B<seki_E && seki_B<seki_F && seki_B<seki_G && seki_B<seki_H && seki_B<seki_I && seki_B<seki_J && seki_B<seki_K && seki_B<seki_L){
  kyori = (seki_A+seki_B+seki_C)/3;
 }
  else{
   if(seki_C<seki_D && seki_C<seki_E && seki_C<seki_F && seki_C<seki_G && seki_C<seki_H && seki_C<seki_I && seki_C<seki_J && seki_C<seki_K && seki_C<seki_L){
   kyori = (seki_B + seki_C+ seki_D)/3;
  }
   else{
    if(seki_D<seki_E && seki_D<seki_F && seki_D<seki_G && seki_D<seki_H && seki_D<seki_I && seki_D<seki_J && seki_D<seki_K && seki_D<seki_L){
    kyori = (seki_C+seki_D+seki_E)/3;
   }
    else{
     if(seki_E<seki_F && seki_E<seki_G && seki_E<seki_H && seki_E<seki_I && seki_E<seki_J && seki_E<seki_K && seki_E<seki_L){
     kyori = (seki_D+seki_E+seki_F)/3;
    }
     else{
      if(seki_F<seki_G && seki_F<seki_H && seki_F<seki_I && seki_F<seki_J && seki_F<seki_K && seki_F<seki_L){
      kyori = (seki_E+seki_F+seki_G)/3;
     }
      else{
       if(seki_G<seki_H && seki_G<seki_I && seki_G<seki_J && seki_G<seki_K && seki_G<seki_L){
       kyori = (seki_F+seki_G+seki_H)/3;
      }
       else{
        if(seki_H<seki_I && seki_H<seki_J && seki_H<seki_K && seki_H<seki_L){
        kyori = (seki_G+seki_H+seki_I)/3;
       }
        else{
         if(seki_I<seki_J && seki_I<seki_K && seki_I<seki_L){
         kyori = (seki_H+seki_I+seki_J)/3;
        }
         else{
          if(seki_J<seki_K && seki_J<seki_L){
          kyori = (seki_I+seki_J+seki_K)/3;
         }
          else{
           if(seki_K<seki_L){
           kyori = (seki_J+seki_K+seki_L)/3;
          }
           else{
           kyori = (seki_K+seki_L+seki_A)/3;
          }
         }
        }
       }
      }
     }
    }
   }
  }
 }
}
seki_A =-seki_A;
seki_B =-seki_B;
seki_C =-seki_C;
seki_D =-seki_D;
seki_E =-seki_E;
seki_F = -seki_F;
seki_G =-seki_G;
seki_H =-seki_H;
seki_I = -seki_I;
seki_J =-seki_J;
seki_K =-seki_K;
seki_L =-seki_L;
int Ax = 0.259*seki_A;
int Ay = 0.965*seki_A;
int Bx = 0.707*seki_B;
int By = 0.707*seki_B;
int Cx = 0.965*seki_C;
int Cy = 0.259*seki_C;
int Dx = 0.965*seki_D;
int Dy = -0.259*seki_D;
int Ex = 0.707*seki_E;
int Ey = -0.707*seki_E;
int Fx = 0.259*seki_F;
int Fy = -0.965*seki_F;
int Gx = -0.259*seki_D;
int Gy = -0.965*seki_D;
int Hx = -0.707*seki_E;
int Hy = -0.707*seki_E;
int Ix = -0.965*seki_F;
int Iy = -0.259*seki_F;
int Jx = -0.965*seki_J;
int Jy = 0.259*seki_J;
int Kx = -0.707*seki_K;
int Ky = 0.707*seki_K;
int Lx = -0.259*seki_L;
int Ly = 0.965*seki_L;
int ballx = Ax + Bx + Cx + Dx + Ex + Fx + Gx + Hx + Ix + Jx + Kx + Lx;
int bally = Ay + By + Cy + Dy + Ey + Fy + Gy + Hy + Iy + Jy + Ky + Ly;
kakudo = atan2(ballx,bally)*53;
maxspeed = 100;
if(kyori>870){
 Read_R();
 Read_L();
 maxspeed = 150;
  if(abs(DIS_R-DIS_L)<20){
   Read_B();
   maxspeed = DIS_B;
    if(DIS_B<40){
    maxspeed = 0;
    }
     else{
     kakudo =180;
     }
   }
  else{
   if(DIS_R<DIS_L){
   kakudo =135;
   }
    else{
    kakudo = -135;
    }
  }
}
 else{
  if(abs(kakudo)<10){
  maxspeed = 240;
  kakudo = kakudo*90/(kyori/10);
  }
   else{
    if(kakudo<0){
    maxspeed = kyori/2-180+(abs(kakudo)/1.5);
    kakudo = kakudo-max((260-(kyori/3)),0);
    }
    else{
      maxspeed = kyori/2-210+(abs(kakudo)/1.5);
      kakudo = kakudo+max((260-(kyori/3)),0);
      }
    }
  }
}

//平行移動(方位による補正あり)
void aj(int kakudo){
  //進行方向を-180°~180°に変換
 if(kakudo<-180){
 kakudo = 360+kakudo;
}
//不明なので今から調べようと思う
 if(kakudo <-135){
 susumukakudo = kakudo+315;
}
 else{
 susumukakudo = kakudo-45;}
 susumu(susumukakudo);
 //PID制御による補正値&実際に出力
 Rwrite(max(-255,(min(255,(a + 1.35*(m_Value)+(m_Value-pidk)*5+(m_Value-2*pidk+pidm))))));
 lwrite(max(-255,(min(255,(a - 1.35*(m_Value)-(m_Value-pidk)*5-(m_Value-2*pidk+pidm))))));
 rwrite(max(-255,(min(255,(b - 1.35*(m_Value)-(m_Value-pidk)*5-(m_Value-2*pidk+pidm))))));
 Lwrite(max(-255,(min(255,(b + 1.35*(m_Value)+(m_Value-pidk)*5+(m_Value-2*pidk+pidm))))));
 pidk = m_Value;
 pidm = pidk;
}

//斜めを向いて平行移動(方位による補正あり)
void ajkakudo(int kakudo,int degree){
 if(kakudo<-180){
 kakudo = 360+kakudo;
}
 if(kakudo <-135){
 susumukakudo = kakudo+315;
}
 else{
 susumukakudo = kakudo-45;}
 susumu(susumukakudo);
 Rwrite(max(-255,(min(255,(a + 1.3*(m_Value+a))))));
 lwrite(max(-255,(min(255,(a - 1.3*(m_Value+a))))));
 rwrite(max(-255,(min(255,(b - 1.3*(m_Value+a))))));
 Lwrite(max(-255,(min(255,(b + 1.3*(m_Value+a))))));
}


//一度単位での走行
void susumu(int kakudo){
 //角度が正
 if(kakudo>0){
 //degからradへの変換
 float deg = kakudo/57.3;
 //tanθの値での場合分け
 if(0<=kakudo && kakudo<45){
 float degree = tan(deg);
 a = maxspeed;
 b = maxspeed*degree;
}
 else{
  if(45<=kakudo && kakudo<135){
   float degree = tan(deg);
   b = maxspeed;
   a = maxspeed/degree;
  }
   else{
    if(135<=kakudo && kakudo<180){
    float degree = tan(deg);
    a = -maxspeed;
    b = -maxspeed*degree;
   }
  }
 }
}

//角度が負
 else{
 //degからradへの変換
 float deg = -kakudo/57.3;
 //tanθでの場合分け
  if(-45<=kakudo && kakudo<0){
  float degree = tan(deg);
  a = maxspeed;
  b = -maxspeed*degree;
 }
  else{
   if(-135<=kakudo && kakudo<-45){
   float degree = tan(deg);
   b = -maxspeed;
   a = maxspeed/degree;
  }
    else{
     if(-180<=kakudo && kakudo<-135){
     float degree = tan(deg);
     a = -maxspeed;
     b = maxspeed*degree;
    }
   }
  }
 }
}


//モーター出力(右前)
void Rwrite(int MSpeed){
 if(MSpeed<0){
 digitalWrite(M_R1,HIGH);
 analogWrite(M_R2,(255+MSpeed));
}
 else{
 digitalWrite(M_R2,HIGH);
 analogWrite(M_R1,(255-MSpeed));
 }
}


//モーター出力(右後)
void rwrite(int MSpeed){
 if(MSpeed<0){
 digitalWrite(M_r1,HIGH);
 analogWrite(M_r2,(255+MSpeed));
}
 else{
 digitalWrite(M_r2,HIGH);
 analogWrite(M_r1,(255-MSpeed));
 }
}
    

//モーター出力(左前)    
void Lwrite(int MSpeed){
 if(MSpeed<0){
 digitalWrite(M_L2,HIGH);
 analogWrite(M_L1,(255+MSpeed));
}
 else{
 digitalWrite(M_L1,HIGH);
 analogWrite(M_L2,(255-MSpeed));
 }
}

//モーター出力(左後)
void lwrite(int MSpeed){
 if(MSpeed<0){
 digitalWrite(M_l2,HIGH);
 analogWrite(M_l1,(255+MSpeed)); 
}
 else{
 digitalWrite(M_l1,HIGH);
 analogWrite(M_l2,(255-MSpeed));
 }
}


//超音波センサによる測定(右)
float Read_R(){
 int dur;
 digitalWrite(USS_TRIG_R,HIGH);
 delayMicroseconds(10);
 digitalWrite(USS_TRIG_R,LOW);
 dur = pulseIn(USS_ECHO_R,HIGH);
 DIS_R = dur*0.017;
}


//超音波センサによる測定(左)
float Read_L(){
 int dur;
 digitalWrite(USS_TRIG_L,HIGH);
 delayMicroseconds(10);
 digitalWrite(USS_TRIG_L,LOW);
 dur = pulseIn(USS_ECHO_L,HIGH);
 DIS_L = dur*0.017;
}



//超音波センサによる測定(後)
float Read_B(){
 int dur;
 digitalWrite(USS_TRIG_B,HIGH);
 delayMicroseconds(10);
 digitalWrite(USS_TRIG_B,LOW);
 dur = pulseIn(USS_ECHO_B,HIGH);
 DIS_B= dur*0.017;
}



//超音波センサによる測定(前)
float Read_C(){
 int dur;
 digitalWrite(USS_TRIG_C,HIGH);
 delayMicroseconds(10);
 digitalWrite(USS_TRIG_C,LOW);
 dur = pulseIn(USS_ECHO_C,HIGH);
 DIS_C= dur*0.017;
}



//方位読み込み
int ModCompass(){
int headingValue;
imu::Vector<3> euler = bno.getVector(Adafruit_BNO055::VECTOR_EULER);
headingValue = euler.x();
 if(headingValue > 180){
  headingValue = headingValue-360;
 }
 return headingValue;
} 
  • 0
  • 0
anonymous タイトルなし
C

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#define BNO055_SAMPLERATE_DELAY_MS (100)
Adafruit_BNO055 bno = Adafruit_BNO055(-1, 0x28);

#define M_l1 5   // モータ1(左1)M
#define M_l2 4    // モータ1(左2)M

#define M_L1 6   // モータ2(右1)M
#define M_L2 7  // モータ2(右2)M

#define M_r1 10
#define M_r2 11

#define M_R1 9
#define M_R2 8
#define USS_TRIG_L 51
#define USS_ECHO_L 50
#define USS_TRIG_R 52
#define USS_ECHO_R 53
#define USS_TRIG_B 49
#define USS_ECHO_B 48
#define USS_TRIG_C 46
#define USS_ECHO_C 47
int L_Flag = 0;
float DIS_L;
float DIS_R;
float DIS_B;
float DIS_C;
int pidk;
int pidm;
int kakudo;
int a;
int b;
int maxspeed = 200;
int susumukakudo;
float deg;
int kyori;
int m_Value;


void setup(){
  
 //Initialise the sensor 
  if(!bno.begin())
  {
     //There was a problem detecting the BNO055 ... check your connections 
   
    while(1);
  }



   //Display the current temperature 
  int8_t temp = bno.getTemp();
 

  bno.setExtCrystalUse(true);
Serial.begin(9600); 
Wire.begin();
  pinMode(USS_TRIG_R,OUTPUT);
  pinMode(USS_ECHO_R,INPUT);
  pinMode(USS_TRIG_L,OUTPUT);
  pinMode(USS_ECHO_L,INPUT);
  pinMode(USS_TRIG_B,OUTPUT);
  pinMode(USS_ECHO_B,INPUT);
  pinMode(USS_TRIG_C,OUTPUT);
  pinMode(USS_ECHO_C,INPUT);
}

void loop(){

  delay(100);
  while(1){
Read_L();
if(DIS_L<30){
  while(1){
 m_Value = ModCompass();
   if(abs(m_Value)>25){
maxspeed = 0;
aj(0);}
else{
 
  if(analogRead(A12)>900 || analogRead(A13)>50){
maxspeed = 180;
 while(1){
  int l;
 m_Value = ModCompass();
  Read_C();
  Read_B();
  Read_R();
  Read_L();
  if(DIS_L + DIS_R>60){
  if(DIS_L<30 || DIS_R<30){
  if(DIS_L>DIS_R){
    aj(90);
    l = 0;}
    else{
     aj(-90); 
     l = 1;}}}
     if(DIS_C + DIS_B>60){
     if(DIS_C<30|| DIS_B<30){
      if(DIS_C<DIS_B){
       aj(180);
       l = 2;}
       else{
       aj(0);
       l = 3;}}}
       if(DIS_L>30&& DIS_R>30 && DIS_C>30 && DIS_B>30){
        while(1){
          m_Value = ModCompass();
          bcnotrun();
          if(l == 0 || l ==1){
            maxspeed = 100;
            if(l == 0){
 if(abs(kakudo)<65){
  aj(-10);}
  else{
    if(abs(kakudo)<115){
     maxspeed = 0;
     aj(0);}
  else{
    aj(-170);}}}
    else{
 if(abs(kakudo)<65){
  aj(10);}
  else{
    if(abs(kakudo)<115){
     maxspeed = 0;
     aj(0);}
  else{
    aj(170);}}   }}
    else{
      maxspeed = 0;
      aj(0);}
          if(l == 0 && kakudo>0){
            break;}
            if(l == 1 && kakudo<0){
              break;}
              if(l == 2 && abs(kakudo)>90){
                break;}
                if(l == 3 && abs(kakudo)<90){
                  break;}
                  if(analogRead(A12)>900){
                    break;}
          }
        break;}}}
bc();}}}}}

void bc(){
   int seki_A = analogRead(A9);
int seki_B = analogRead(A10);
int seki_C = analogRead(A11);
int seki_D = analogRead(A6);
int seki_E = analogRead(A7);
int seki_F = analogRead(A8);
int seki_G = analogRead(A3);
int seki_H = analogRead(A4);
int seki_I = analogRead(A5);
int seki_J = analogRead(A0);
int seki_K = analogRead(A1);
int seki_L = analogRead(A2);
if(seki_A<seki_B && seki_A<seki_C && seki_A<seki_D && seki_A<seki_E && seki_A<seki_F && seki_A<seki_G && seki_A<seki_H && seki_A<seki_I && seki_A<seki_J && seki_A<seki_K && seki_A<seki_L){
kyori = (seki_L+seki_A+seki_B)/3;}
else{
if(seki_B<seki_C && seki_B<seki_D && seki_B<seki_E && seki_B<seki_F && seki_B<seki_G && seki_B<seki_H && seki_B<seki_I && seki_B<seki_J && seki_B<seki_K && seki_B<seki_L){
kyori = (seki_A+seki_B+seki_C)/3;
}
else{
if(seki_C<seki_D && seki_C<seki_E && seki_C<seki_F && seki_C<seki_G && seki_C<seki_H && seki_C<seki_I && seki_C<seki_J && seki_C<seki_K && seki_C<seki_L){
kyori = (seki_B + seki_C+ seki_D)/3;}
else{
if(seki_D<seki_E && seki_D<seki_F && seki_D<seki_G && seki_D<seki_H && seki_D<seki_I && seki_D<seki_J && seki_D<seki_K && seki_D<seki_L){
kyori = (seki_C+seki_D+seki_E)/3;}
else{
if(seki_E<seki_F && seki_E<seki_G && seki_E<seki_H && seki_E<seki_I && seki_E<seki_J && seki_E<seki_K && seki_E<seki_L){
kyori = (seki_D+seki_E+seki_F)/3;}
else{
if(seki_F<seki_G && seki_F<seki_H && seki_F<seki_I && seki_F<seki_J && seki_F<seki_K && seki_F<seki_L){
kyori = (seki_E+seki_F+seki_G)/3;
}
else{
if(seki_G<seki_H && seki_G<seki_I && seki_G<seki_J && seki_G<seki_K && seki_G<seki_L){
kyori = (seki_F+seki_G+seki_H)/3;
}
else{
if(seki_H<seki_I && seki_H<seki_J && seki_H<seki_K && seki_H<seki_L){
kyori = (seki_G+seki_H+seki_I)/3;}
else{
if(seki_I<seki_J && seki_I<seki_K && seki_I<seki_L){
kyori = (seki_H+seki_I+seki_J)/3;}
else{
if(seki_J<seki_K && seki_J<seki_L){
kyori = (seki_I+seki_J+seki_K)/3;}
else{
if(seki_K<seki_L){
kyori = (seki_J+seki_K+seki_L)/3;}
else{
kyori = (seki_K+seki_L+seki_A)/3;}}}}}}}}}}}
seki_A =-seki_A;
seki_B =-seki_B;
seki_C =-seki_C;
seki_D =-seki_D;
seki_E =-seki_E;
seki_F = -seki_F;
seki_G =-seki_G;
seki_H =-seki_H;
seki_I = -seki_I;
seki_J =-seki_J;
seki_K =-seki_K;
seki_L =-seki_L;
int Ax = 0.259*seki_A;
int Ay = 0.965*seki_A;
int Bx = 0.707*seki_B;
int By = 0.707*seki_B;
int Cx = 0.965*seki_C;
int Cy = 0.259*seki_C;
int Dx = 0.965*seki_D;
int Dy = -0.259*seki_D;
int Ex = 0.707*seki_E;
int Ey = -0.707*seki_E;
int Fx = 0.259*seki_F;
int Fy = -0.965*seki_F;
int Gx = -0.259*seki_D;
int Gy = -0.965*seki_D;
int Hx = -0.707*seki_E;
int Hy = -0.707*seki_E;
int Ix = -0.965*seki_F;
int Iy = -0.259*seki_F;
int Jx = -0.965*seki_J;
int Jy = 0.259*seki_J;
int Kx = -0.707*seki_K;
int Ky = 0.707*seki_K;
int Lx = -0.259*seki_L;
int Ly = 0.965*seki_L;
int ballx = Ax + Bx + Cx + Dx + Ex + Fx + Gx + Hx + Ix + Jx + Kx + Lx;
int bally = Ay + By + Cy + Dy + Ey + Fy + Gy + Hy + Iy + Jy + Ky + Ly;
kakudo = atan2(ballx,bally)*53;
maxspeed = 100;
if(kyori>870){
  Read_R();
  Read_L();
  maxspeed = 150;
  if(abs(DIS_R-DIS_L)<20){
    maxspeed = DIS_B;
    Read_B();
    if(DIS_B<40){
    maxspeed = 0;}
    else{
  kakudo =180;}}
  else{
  if(DIS_R<DIS_L){
kakudo =135;}
else{
kakudo = -135;}}}
else{
if(abs(kakudo)<10){
  maxspeed = 240;
 kakudo = kakudo*90/(kyori/10);}
  else{
  if(kakudo<0){
        maxspeed = kyori/2-180+(abs(kakudo)/1.5);
    kakudo = kakudo-max((260-(kyori/3)),0);
}
    else{
          maxspeed = kyori/2-210+(abs(kakudo)/1.5);
      kakudo = kakudo+max((260-(kyori/3)),0);}}}
aj(kakudo);
}

void bcnotrun(){
    int seki_A = analogRead(A9);
int seki_B = analogRead(A10);
int seki_C = analogRead(A11);
int seki_D = analogRead(A6);
int seki_E = analogRead(A7);
int seki_F = analogRead(A8);
int seki_G = analogRead(A3);
int seki_H = analogRead(A4);
int seki_I = analogRead(A5);
int seki_J = analogRead(A0);
int seki_K = analogRead(A1);
int seki_L = analogRead(A2);
if(seki_A<seki_B && seki_A<seki_C && seki_A<seki_D && seki_A<seki_E && seki_A<seki_F && seki_A<seki_G && seki_A<seki_H && seki_A<seki_I && seki_A<seki_J && seki_A<seki_K && seki_A<seki_L){
kyori = (seki_L+seki_A+seki_B)/3;}
else{
if(seki_B<seki_C && seki_B<seki_D && seki_B<seki_E && seki_B<seki_F && seki_B<seki_G && seki_B<seki_H && seki_B<seki_I && seki_B<seki_J && seki_B<seki_K && seki_B<seki_L){
kyori = (seki_A+seki_B+seki_C)/3;
}
else{
if(seki_C<seki_D && seki_C<seki_E && seki_C<seki_F && seki_C<seki_G && seki_C<seki_H && seki_C<seki_I && seki_C<seki_J && seki_C<seki_K && seki_C<seki_L){
kyori = (seki_B + seki_C+ seki_D)/3;}
else{
if(seki_D<seki_E && seki_D<seki_F && seki_D<seki_G && seki_D<seki_H && seki_D<seki_I && seki_D<seki_J && seki_D<seki_K && seki_D<seki_L){
kyori = (seki_C+seki_D+seki_E)/3;}
else{
if(seki_E<seki_F && seki_E<seki_G && seki_E<seki_H && seki_E<seki_I && seki_E<seki_J && seki_E<seki_K && seki_E<seki_L){
kyori = (seki_D+seki_E+seki_F)/3;}
else{
if(seki_F<seki_G && seki_F<seki_H && seki_F<seki_I && seki_F<seki_J && seki_F<seki_K && seki_F<seki_L){
kyori = (seki_E+seki_F+seki_G)/3;
}
else{
if(seki_G<seki_H && seki_G<seki_I && seki_G<seki_J && seki_G<seki_K && seki_G<seki_L){
kyori = (seki_F+seki_G+seki_H)/3;
}
else{
if(seki_H<seki_I && seki_H<seki_J && seki_H<seki_K && seki_H<seki_L){
kyori = (seki_G+seki_H+seki_I)/3;}
else{
if(seki_I<seki_J && seki_I<seki_K && seki_I<seki_L){
kyori = (seki_H+seki_I+seki_J)/3;}
else{
if(seki_J<seki_K && seki_J<seki_L){
kyori = (seki_I+seki_J+seki_K)/3;}
else{
if(seki_K<seki_L){
kyori = (seki_J+seki_K+seki_L)/3;}
else{
kyori = (seki_K+seki_L+seki_A)/3;}}}}}}}}}}}
seki_A =-seki_A;
seki_B =-seki_B;
seki_C =-seki_C;
seki_D =-seki_D;
seki_E =-seki_E;
seki_F = -seki_F;
seki_G =-seki_G;
seki_H =-seki_H;
seki_I = -seki_I;
seki_J =-seki_J;
seki_K =-seki_K;
seki_L =-seki_L;
int Ax = 0.259*seki_A;
int Ay = 0.965*seki_A;
int Bx = 0.707*seki_B;
int By = 0.707*seki_B;
int Cx = 0.965*seki_C;
int Cy = 0.259*seki_C;
int Dx = 0.965*seki_D;
int Dy = -0.259*seki_D;
int Ex = 0.707*seki_E;
int Ey = -0.707*seki_E;
int Fx = 0.259*seki_F;
int Fy = -0.965*seki_F;
int Gx = -0.259*seki_D;
int Gy = -0.965*seki_D;
int Hx = -0.707*seki_E;
int Hy = -0.707*seki_E;
int Ix = -0.965*seki_F;
int Iy = -0.259*seki_F;
int Jx = -0.965*seki_J;
int Jy = 0.259*seki_J;
int Kx = -0.707*seki_K;
int Ky = 0.707*seki_K;
int Lx = -0.259*seki_L;
int Ly = 0.965*seki_L;
int ballx = Ax + Bx + Cx + Dx + Ex + Fx + Gx + Hx + Ix + Jx + Kx + Lx;
int bally = Ay + By + Cy + Dy + Ey + Fy + Gy + Hy + Iy + Jy + Ky + Ly;
kakudo = atan2(ballx,bally)*53;
maxspeed = 100;
if(kyori>870){
  Read_R();
  Read_L();
  maxspeed = 150;
  if(abs(DIS_R-DIS_L)<20){
    maxspeed = DIS_B;
    Read_B();
    if(DIS_B<40){
    maxspeed = 0;}
    else{
  kakudo =180;}}
  else{
  if(DIS_R<DIS_L){
kakudo =135;}
else{
kakudo = -135;}}}
else{
if(abs(kakudo)<10){
  maxspeed = 240;
 kakudo = kakudo*90/(kyori/10);}
  else{
  if(kakudo<0){
        maxspeed = kyori/2-180+(abs(kakudo)/1.5);
    kakudo = kakudo-max((260-(kyori/3)),0);
}
    else{
          maxspeed = kyori/2-210+(abs(kakudo)/1.5);
      kakudo = kakudo+max((260-(kyori/3)),0);}}}
 }

  
void aj(int kakudo){
if(kakudo<-180){
kakudo = 360+kakudo;}
if(kakudo <-135){
susumukakudo = kakudo+315;}
else{
susumukakudo = kakudo-45;}
susumu(susumukakudo);
Rwrite(max(-255,(min(255,(a + 1.35*(m_Value)+(m_Value-pidk)*5+(m_Value-2*pidk+pidm))))));
lwrite(max(-255,(min(255,(a - 1.35*(m_Value)-(m_Value-pidk)*5-(m_Value-2*pidk+pidm))))));
rwrite(max(-255,(min(255,(b - 1.35*(m_Value)-(m_Value-pidk)*5-(m_Value-2*pidk+pidm))))));
Lwrite(max(-255,(min(255,(b + 1.35*(m_Value)+(m_Value-pidk)*5+(m_Value-2*pidk+pidm))))));
pidk = m_Value;
pidm = pidk;}

void ajkakudo(int kakudo,int degree){
if(kakudo<-180){
kakudo = 360+kakudo;}
if(kakudo <-135){
susumukakudo = kakudo+315;}
else{
susumukakudo = kakudo-45;}
susumu(susumukakudo);
Rwrite(max(-255,(min(255,(a + 1.3*(m_Value+a))))));
lwrite(max(-255,(min(255,(a - 1.3*(m_Value+a))))));
rwrite(max(-255,(min(255,(b - 1.3*(m_Value+a))))));
Lwrite(max(-255,(min(255,(b + 1.3*(m_Value+a))))));}

void susumu(int kakudo){
 if(kakudo>0){
float deg = kakudo/57.3;
if(0<=kakudo && kakudo<45){
float degree = tan(deg);
a = maxspeed;
b = maxspeed*degree;

}
  else{
    if(45<=kakudo && kakudo<135){
float degree = tan(deg);
b = maxspeed;
a= maxspeed/degree;
}
    else{
if(135<=kakudo && kakudo<180){
float degree = tan(deg);
a = -maxspeed;
b= -maxspeed*degree;}}}}

else{
float deg = -kakudo/57.3;
if(-45<=kakudo && kakudo<0){
float degree = tan(deg);
a = maxspeed;
b = -maxspeed*degree;
}
  else{
    if(-135<=kakudo && kakudo<-45){
float degree = tan(deg);
b = -maxspeed;
a= maxspeed/degree;
}
    else{
if(-180<=kakudo && kakudo<-135){
float degree = tan(deg);
a = -maxspeed;
b= maxspeed*degree;}}}}}

void Rwrite(int MSpeed){
  if(MSpeed<0){
    digitalWrite(M_R1,HIGH);
    analogWrite(M_R2,(255+MSpeed));  }
  else{
    digitalWrite(M_R2,HIGH);
    analogWrite(M_R1,(255-MSpeed));}}
    
    
void rwrite(int MSpeed){
  if(MSpeed<0){
    digitalWrite(M_r1,HIGH);
    analogWrite(M_r2,(255+MSpeed)); }
  else{
    digitalWrite(M_r2,HIGH);
    analogWrite(M_r1,(255-MSpeed));}}
    
    
void Lwrite(int MSpeed){
  if(MSpeed<0){
    digitalWrite(M_L2,HIGH);
    analogWrite(M_L1,(255+MSpeed)); }
  else{
    digitalWrite(M_L1,HIGH);
    analogWrite(M_L2,(255-MSpeed));
}}


void lwrite(int MSpeed){
  if(MSpeed<0){
    digitalWrite(M_l2,HIGH);
    analogWrite(M_l1,(255+MSpeed)); }
  else{
    digitalWrite(M_l1,HIGH);
    analogWrite(M_l2,(255-MSpeed));}}

float Read_R(){
  int dur;
  digitalWrite(USS_TRIG_R,HIGH);
  delayMicroseconds(10);
  digitalWrite(USS_TRIG_R,LOW);
  dur = pulseIn(USS_ECHO_R,HIGH);
DIS_R = dur*0.017;
}


float Read_L(){
  int dur;
  digitalWrite(USS_TRIG_L,HIGH);
  delayMicroseconds(10);
  digitalWrite(USS_TRIG_L,LOW);
  dur = pulseIn(USS_ECHO_L,HIGH);
 DIS_L = dur*0.017;
}

float Read_B(){
  int dur;
  digitalWrite(USS_TRIG_B,HIGH);
  delayMicroseconds(10);
  digitalWrite(USS_TRIG_B,LOW);
  dur = pulseIn(USS_ECHO_B,HIGH);
 DIS_B= dur*0.017;
}

float Read_C(){
  int dur;
  digitalWrite(USS_TRIG_C,HIGH);
  delayMicroseconds(10);
  digitalWrite(USS_TRIG_C,LOW);
  dur = pulseIn(USS_ECHO_C,HIGH);
 DIS_C= dur*0.017;
}

    int ModCompass(){
  int headingValue;
 imu::Vector<3> euler = bno.getVector(Adafruit_BNO055::VECTOR_EULER);
 headingValue = euler.x();
 if(headingValue > 180){
  headingValue = headingValue-360;}
  return headingValue;
} 
  • 0
  • 0
anonymous タイトルなし
C
//文字列はsに入れてください。また、文字数はsizeまでです。
   char x[101];
   for (int i=0; i<n; ++i) {
      for (int j=i+1; j<n; ++j) {
         if (strcmp(s[i],s[j])>0) {
            strcpy(x,s[i]);
            strcpy(s[i],s[j]);
            strcpy(s[j],x);
         }else {
            continue;
         }
      }
   }
  • 0
  • 1
anonymous タイトルなし
C
#include <stdio.h>
#include <math.h>

#define MAX(a,b) (a > b) ? a : b
#define MIN(a,b) (a < b) ? a : b

int mv(int a,int b){
   int x = pow(a-b,2);
   return x;
}
int Amax(int *p,int size){
   int _max = 0;
   for(int i = 0;i < size;i++)
      if(p[i] > _max)_max = p[i];
   return _max;
}
int Amin(int *p,int size){
   int _min = 0;
   for(int i = 0;i < size;i++)
      if(p[i] < _min)_min = p[i];
   return _min;
}
int main(){
   int n;scanf("%d",&n);
   int x[100];for(int i = 0;i < n;i++)scanf("%d",&x[i]);
   long int ans = 100000000000000;
   for(int i = 0;i < n;i++){
      ans += mv(x[i],1);
   }
   for(int j = Amin(x,n);j < Amax(x,n);j++){
      int _ans;
      for(int i = 0;i < n;i++){
         //printf("  x[i]:%d i:%d",x[i],i);
         _ans += mv(x[i],j);
         //printf("  %d\n",_ans);
      }
      //printf("%d:%d\n",j,_ans);
      if (ans>_ans)ans = _ans;
      _ans = 0;
   }
   printf("%d\n",ans);
   //printf("%d\n",mv(1,2));
}
  • 0
  • 1
anonymous タイトルなし
C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int Amax(int *p,int size){
   int _max = 0;
   for(int i = 0;i < size;i++)
      if(p[i] > _max)_max = p[i];
   return _max;
}

int main(){
   int n;scanf("%d",&n);
   char paper[200000][11];for(int i = 0;i < n;i++)scanf("%s",paper[i]);
   char tmp[11];
   int count[200000] ={0};
   int pointer;
   for(int i=1;i<n;i++){
      for(int j=1;j<n;j++){
         if(strcmp(paper[j-1], paper[j])>0){
            strcpy(tmp, paper[j-1]);
            strcpy(paper[j-1], paper[j]);
            strcpy(paper[j], tmp);
         }
      }
   }
   pointer = 0;
   for(int i = 0;i < n-1;i++){
      if (!(strcmp(paper[i],paper[i+1]))){
         count[pointer]++;
      }else {
         pointer = i+1;
      }
   }
   /*for(int i = 0;i < n;i++){
      printf("%d\n",count[i]);
      printf("%s\n",paper[i]);
   }*/

   int x = Amax(count,n);
   for(int i = 0;i < n;i++){
      if(count[i] == x)printf("%s\n",paper[i]);
   }
}
  • 0
  • 1
あなたもコードを投稿しませんか?
投稿する
123