-

   dev58

 - e-mail

 

 -

 LiveInternet.ru:
: 11.05.2017
:
:
: 9

:


Arduino nano,

, 12 2017 . 20:14 +

arduino nano ( RobotDyn). , , . , : arduino uno, , .  , , .

 

 

, . :

1. Arduino :

  • ( ) - (gnd);
  • - 5v;
  • - 8 .

2. Arduino :

  • gnd - gnd;
  • 5v - 5v ( 3.3v);
  • VRX ( X) - A1;
  • VRY ( Y) - A0;
  • SW ( - ) - 2 .

, arduino , Arduino IDE, , . , .

 

#include <Servo.h> //    

int xPin = A1; //1 -     

int yPin = A0; //0 -     

int buttonPin = 2; //     (  )

int xPosition = 0;  //         X

int yPosition = 0; //         Y

int buttonState = 0; //   ()

int servoPin = 8; //     

Servo servo; //   Servo

int angle = 90; //   

int currentXpos = 0; //  X


void setup() {

  pinMode(xPin, INPUT); //   xPin    

  pinMode(yPin, INPUT); //   yPin    

  pinMode(buttonPin, INPUT_PULLUP); //      

  servo.attach(servoPin); //   

  servo.write(angle); //    90 

}

void loop() {

  xPosition = analogRead(xPin); //   xPin

  yPosition = analogRead(yPin); //   yPin

  buttonState = digitalRead(buttonPin); //  '' 


  //  xPosition  360 
  if(xPosition > 360) {

    angle  = angle-10; //     10 

    //    0
    if(angle < 0) {
      angle = 0; //   0 
    }
  }
  
  // xPosition  300
  if(xPosition < 300) {

    angle =  angle+10; //      10 

    //    180 
    if(angle > 180) {
      angle = 180; //    180 
    }
  }
  
  //    
  if(buttonState == 0)
  {
    angle = 90; //   90 
  }
  
  servo.write(angle); //     
  
  delay(50); //     

}

 

 

3.3V X Y 330 ( 5V ), 30 .

( : -> CTRL + SHIFT + M). setup() :

 

  Serial.begin(9600); //         9600 bps



loop() :

 

  Serial.print("X: ");

  Serial.print(xPosition);

  Serial.print(" | Y: ");

  Serial.print(yPosition);

  Serial.print(" | Button: ");

  Serial.println(buttonState);


, Arduino Uno, . , X Y.

 

, http://dev58.ru/articles/arduino_nano_servomotor_i_joystick

:  

   , 07 2017 . 19:55 ()
   
   , 29 2018 . 13:55 ()
- ?
        |    
: [1] []
 

:
: 

: ( )

:

  URL