Arduino Servo z Joystickiem

W tym przykładzie połączymy arduino z mini servo 9g SG90 i dwukierunkowym joystickiem.

Użyjemy biblioteki Servo.h, która jest domyślnie wgrana w Arduino IDE 2.

#include <Servo.h>
#define SERVO_PIN 9         
#define XJOY_PIN A1  
Servo myservo;
 
void setup()
{
 Serial.begin(9600);
 myservo.attach(9);
}
 
void loop()
{
 delay(100);                    
 int joystickXVal = analogRead(XJOY_PIN) ; 
 int val = map(joystickXVal, 0, 1023, 0, 180); 
 myservo.write(val);  
}
Ask ChatGPT
Set ChatGPT API key
Find your Secret API key in your ChatGPT User settings and paste it here to connect ChatGPT with your Tutor LMS website.
Scroll to Top