Advertisement
Guest User

Hier nochmal der Code richtig

a guest
Jul 14th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. #include <Servo.h>
  2. Servo s;
  3. int servopin = 13;
  4. const int waitTime = 50;
  5.  
  6. int eingang= A0;
  7. int sensorWert = 0;
  8.  
  9. int pos = 90;
  10.  
  11. void setup() {
  12.  
  13. Serial.begin(9600);
  14. s.attach(servopin);
  15. delay(10000);
  16. }
  17.  
  18. void loop() {
  19.  
  20. sensorWert =analogRead(eingang);
  21. Serial.print("Sensorwert = " );
  22. Serial.println(sensorWert);
  23.  
  24. do {
  25.  
  26.  
  27.   for(pos = 90; pos < 150; pos += 1) {  // von 0 bis 180 Grad, in Schritten von einem Grad
  28.     s.write(pos);                   // sagt dem Servomotor, in welche Position sich drehen soll      
  29.     delay(50);
  30.     sensorWert =analogRead(eingang);
  31.     Serial.print("Sensorwert = " );
  32.     Serial.println(sensorWert);
  33.   }
  34.  
  35.   delay(500);
  36.   for(pos = 150; pos > 30; pos -= 1) {  // von 0 bis 180 Grad, in Schritten von einem Grad
  37.     s.write(pos);                   // sagt dem Servomotor, in welche Position sich drehen soll      
  38.     delay(50);
  39.     sensorWert =analogRead(eingang);
  40.     Serial.print("Sensorwert = " );
  41.     Serial.println(sensorWert);
  42.   }
  43.   delay(500);
  44.   for(pos = 30; pos < 90; pos += 1) {  // von 0 bis 180 Grad, in Schritten von einem Grad
  45.     s.write(pos);                   // sagt dem Servomotor, in welche Position sich drehen soll      
  46.     delay(50);
  47.     sensorWert =analogRead(eingang);
  48.     Serial.print("Sensorwert = " );
  49.     Serial.println(sensorWert);
  50.   }
  51.  
  52. } while (sensorWert < 80);
  53.  
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement