16 Kasım 2018 Cuma

Bash Ping Test

       


#!/bin/bash
A=""
for i in {1..30}
do 
 ping -q -c1 192.168.1.$i
 if [ $? -eq 0 ]
 then
  A+="Ok 192.168.1.$i\n"
 else
  A+="No 192.168.1.$i\n"
 fi
done
echo -e "$A"

28 Ekim 2018 Pazar

Book Page Turner Arduino Code

       


#include 
#define lArm 8
#define rArm 5
#define wheel 4
#define wArm 6
#define turner 7

Servo solkol;
Servo sagkol;
Servo teker;
Servo tekerkol;
Servo donduren;
const int solDugme = 12;
const int sagDugme = 13;
int dtime = 10;
int leftbutton =0;
int rightbutton = 0;
int counter = 0;

void setup() {
     pinMode(solDugme, OUTPUT);
     pinMode(sagDugme, OUTPUT);
     Serial.begin(9600);
}

void loop() {
     leftbutton = digitalRead(solDugme);
     rightbutton = digitalRead(sagDugme);
     if(counter == 0) {
          defaultPosition();
     }
     if(counter == 1000) {
           counter = 1;    
     }
     if(rightbutton == HIGH) {
          attachedAll();
          servoTurn(donduren, dtime, 0);
          servoTurn(sagkol, dtime, 165);
          servoTurn(solkol, dtime, 165);
          servoTurn(teker, dtime, 180);
          servoTurn(tekerkol, dtime, 5);
          servoTurn(teker, dtime, 0);
          servoTurn(sagkol, dtime, 90);
          servoTurn(donduren, dtime, 20);
          servoTurn(tekerkol, dtime, 50);
          servoTurn(solkol, dtime, 90);
          servoTurn(sagkol, dtime, 165);
          servoTurn(donduren, dtime, 180);
          servoTurn(solkol, dtime, 165);
          servoTurn(tekerkol, dtime, 90);
          servoTurn(donduren, dtime, 0);
          Serial.println("Left button pressed");
          detachAll();
     }
     
     if(leftbutton == HIGH) {
          attachedAll();
          servoTurn(donduren, dtime, 180);
          servoTurn(solkol, dtime, 165);
          servoTurn(sagkol, dtime, 165);
          servoTurn(teker, dtime, 0);
          servoTurn(tekerkol, dtime, 150);
          servoTurn(solkol, dtime, 90);
          servoTurn(teker, dtime, 180);
          servoTurn(donduren, dtime, 160);
          servoTurn(sagkol, dtime, 90);
          servoTurn(tekerkol, dtime, 90);
          servoTurn(donduren, dtime, 0);
          servoTurn(sagkol, dtime, 165);
          servoTurn(solkol, dtime, 165);
          servoTurn(donduren, dtime, 180);
          Serial.println("Right button pressed");
          detachAll();
     }
     
     counter++;
}

void defaultPosition() {
          attachedAll();
          servoTurn(sagkol, dtime, 15);
          servoTurn(solkol, dtime, 15);
          servoTurn(tekerkol, dtime, 90);
          servoTurn(teker, dtime, 0);
          servoTurn(donduren, dtime, 0);
          Serial.println("Start");
          detachAll();
}

void detachAll() {
     if(solkol.attached()) solkol.detach();
     if(sagkol.attached()) sagkol.detach();
     if(teker.attached()) teker.detach();
     if(tekerkol.attached()) tekerkol.detach();
     if(donduren.attached()) donduren.detach();
}

void attachedAll() {
     if (!solkol.attached()) {
          solkol.attach(lArm);
     }
     if (!sagkol.attached()) {
          sagkol.attach(rArm);
     }
     if(!teker.attached()) {
          teker.attach(wheel);
     }
     if(!tekerkol.attached()) {
          tekerkol.attach(wArm);
     }
     if(!donduren.attached()) {
          donduren.attach(turner);
     }
}


void servoTurn(Servo v,int d, int angle) {
     int sp = v.read();
     int diff = angle -sp;
     if(diff < 0) {
          for(int i=0; i < abs(diff); i++) {
               v.write(sp -i);
               delay(d);
          }
     } else {
          for(int i=0; i < diff; i++) {
               v.write(sp +i);
               delay(d);
          }
     }
}

21 Mayıs 2018 Pazartesi

Vnh2sp Monster motorshield & Joystick Control

       


int xPin = A4; // A0-A5 analog pinlerinden herhangi birine bağlanabilir.
int yPin = A5; // A0-A5 analog pinlerinden herhangi birine bağlanabilir.
int butonPin = 10; // Joystick buton pini arduino bağlantısı (Joystick SW çıkışı)

int xPozisyonu = 0;
int yPozisyonu = 0;
int butonDurum = 0;
int motorLimit = 255;
int halfMotor = int(motorLimit/2.0);
int joystickLimit = 1024;
int halfJoystick = int(joystickLimit / 2.0);
int xDiff =0;
int yDiff =0;
int speed1 = 0;
int speed2 = 0;
int tolerans = 5;

#define BRAKEVCC 0
#define CW   1
#define CCW  2
#define BRAKEGND 3
#define CS_THRESHOLD 100
#define MOTOR_1 0
#define MOTOR_2 1

int usSpeed = 1023;  //default motor speed
unsigned short usMotor_Status = BRAKEVCC;

/*  VNH2SP30 pin definitions
 xxx[0] controls '1' outputs
 xxx[1] controls '2' outputs */
int inApin[2] = {7, 4};  // INA: Clockwise input
int inBpin[2] = {8, 9}; // INB: Counter-clockwise input
int pwmpin[2] = {5, 6}; // PWM input
int cspin[2] = {2, 3}; // CS: Current sense ANALOG input
int enpin[2] = {0, 1}; // EN: Status of switches output (Analog pin)

int statpin = 13;

void setup()
{
  Serial.begin(9600);
  
  pinMode(statpin, OUTPUT);

  // Initialize digital pins as outputs
  for (int i=0; i<2; i++)
  {
    pinMode(inApin[i], OUTPUT);
    pinMode(inBpin[i], OUTPUT);
    pinMode(pwmpin[i], OUTPUT);
  }
  // Initialize braked
  for (int i=0; i<2; i++)
  {
    digitalWrite(inApin[i], LOW);
    digitalWrite(inBpin[i], LOW);
  }
 
}

void loop()
{
  xPozisyonu = analogRead(xPin);
  yPozisyonu = analogRead(yPin);
  butonDurum = digitalRead(butonPin);
  /*
  if(butonDurum == 1) {
    xPozisyonu = halfJoystick;
    yPozisyonu = halfJoystick;
  }
  */
  xDiff = xPozisyonu - halfJoystick;
  yDiff = yPozisyonu - halfJoystick;
  xDiff = map(xDiff, 0, halfJoystick, 0, halfMotor);
  yDiff = -map(yDiff, 0, halfJoystick, 0, halfMotor);
  speed1 = abs(yDiff);
  speed2 = abs(abs(yDiff)- abs(xDiff));
  Serial.print("---X: ");
  Serial.print(xPozisyonu);
  Serial.print("|Y: ");
  Serial.print(yPozisyonu);
  Serial.print("|B: ");
  Serial.print(butonDurum);
  Serial.print("|xDiff: ");
  Serial.print(xDiff);
  Serial.print("|yDiff: ");
  Serial.print(yDiff);
  
  Serial.print("|S1: ");
  Serial.print(speed1);
  Serial.print("|S2: ");
  Serial.print(speed2);
  Serial.print("----\r\n\r");
  

  if(abs(xDiff) < tolerans && abs(yDiff) < tolerans){
    Serial.print("sag dur ");
    Serial.print("sol dur\r\n\r");
    usMotor_Status = BRAKEVCC;
    motorGo(MOTOR_1, usMotor_Status, 0);
    motorGo(MOTOR_2, usMotor_Status, 0);
  }
  else if(xDiff == 0 && yDiff > 0) {
    Serial.print("sol one ");
    Serial.print("sag one\n\r");
    usMotor_Status = CW;
    motorGo(MOTOR_1, usMotor_Status, speed1);
    motorGo(MOTOR_2, usMotor_Status, speed1);
  }
  else if(xDiff == 0 && yDiff <= 0) {
    Serial.print("sol arka ");
    Serial.print("sag arka\n\r");
    usMotor_Status = CCW;
    motorGo(MOTOR_1, usMotor_Status, speed1);
    motorGo(MOTOR_2, usMotor_Status, speed1);
  }
  else if(xDiff > 0 && yDiff == 0) {
    Serial.print("sol one ");
    Serial.print("sag arka\n\r");
    usMotor_Status = CW;
    motorGo(MOTOR_1, usMotor_Status, speed1);
    usMotor_Status = CCW;
    motorGo(MOTOR_2, usMotor_Status, speed2);
  }
  else if(xDiff <= 0 && yDiff == 0) {
    Serial.print("sol arka ");
    Serial.print("sag one\n\r");
    usMotor_Status = CCW;
    motorGo(MOTOR_1, usMotor_Status, speed1);
    usMotor_Status = CW;
    motorGo(MOTOR_2, usMotor_Status, speed2);
  }
  else if(xDiff > 0 && yDiff > 0) {
    Serial.print("yon : Front right");
    Serial.print("sol one hizli ");
    Serial.print("sag one yavas\n\r");
    usMotor_Status = CW;
    motorGo(MOTOR_1, usMotor_Status, speed1);
    motorGo(MOTOR_2, usMotor_Status, speed2);
  }
  else if(xDiff < 0 && yDiff < 0) {
    Serial.print("yon : back left ");
    Serial.print("sol arka yavas ");
    Serial.print("sag arka hizli\n\r");
    usMotor_Status = CCW;
    motorGo(MOTOR_1, usMotor_Status, speed2);
    motorGo(MOTOR_2, usMotor_Status, speed1);
  }
  else if(xDiff > 0 && yDiff < 0) {
    Serial.print("yon : back right ");
    Serial.print("sol arka hizli ");
    Serial.print("sag arka yavas\n\r");
    usMotor_Status = CCW;
    motorGo(MOTOR_1, usMotor_Status, speed1);
    motorGo(MOTOR_2, usMotor_Status, speed2);
  }
  else if(xDiff < 0 && yDiff > 0) {
    Serial.print("yon : Front left ");
    Serial.print("sol one yavas");
    Serial.print("sag one hizli\n\r");
    usMotor_Status = CW;
    motorGo(MOTOR_1, usMotor_Status, speed2);
    motorGo(MOTOR_2, usMotor_Status, speed1);
  }
  else {
    Serial.println("Anlamsiz");
  }
  
  
  if ((analogRead(cspin[0]) < CS_THRESHOLD) && (analogRead(cspin[1]) < CS_THRESHOLD)) {
    Serial.println("Stat pin activ");
    digitalWrite(statpin, HIGH);
  }
}

void motorOff(int motor)
{
  // Initialize braked
  for (int i=0; i<2; i++)
  {
    digitalWrite(inApin[i], LOW);
    digitalWrite(inBpin[i], LOW);
  }
  analogWrite(pwmpin[motor], 0);
}


void motorGo(uint8_t motor, uint8_t direct, uint8_t pwm)
{
  if (motor <= 1)
  {
    if (direct <=4)
    {
      // Set inA[motor]
      if (direct <=1)
        digitalWrite(inApin[motor], HIGH);
      else
        digitalWrite(inApin[motor], LOW);

      // Set inB[motor]
      if ((direct==0)||(direct==2))
        digitalWrite(inBpin[motor], HIGH);
      else
        digitalWrite(inBpin[motor], LOW);

      analogWrite(pwmpin[motor], pwm);
    }
  }
}


2 Nisan 2018 Pazartesi

Yokuş çıkmak için Elektrikli Scooter yapmak

Parçalar

  1. Gövde (yapılacak)
  2. Direksiyon
  3. Teker 2 adet (rulmanlı yük tekeri) +
  4. Disk fren seti
  5. Dc motor (350watt 3500rpm motor) +
  6. Motor hız ayarı
  7. Vites kutusu
  8. Zincir büyük dişli freewheel rulman
  9. Lamba ön arka +
  10. Jel Akü ve koruma kutusu
  11. Amortisör
  12. Zil
  13. Stop
  14. motor kilit
  15. ayna
  16. hız ayarlı elbarı
  17. gösterge paneli
  18. sinyal
  19. telefon tutacak