Advertisement
Makerino

Motor mit Joystick

May 5th, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.39 KB | None | 0 0
  1. int x = 0;
  2.  
  3. void setup() {
  4.   pinMode(3, OUTPUT);
  5.   pinMode(5, OUTPUT);
  6.   pinMode(A0, INPUT);
  7.   Serial.begin(9600);
  8.  
  9. }
  10.  
  11. void loop() {
  12.    x = analogRead(A0);
  13.    
  14.   if (x < 490){
  15.     analogWrite(3, ((x-512)*(-1))/2);
  16.     }  
  17.     else{
  18.       analogWrite(3, 0);  
  19.     }
  20.      
  21.    if (x>530){
  22.    analogWrite(5, (x-512)/2);
  23.  }
  24.      else{
  25.       analogWrite(5, 0);  
  26.     }
  27.    x=510;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement