servo verplaatsen van a naar b

Arduino specifieke Software
Berichten: 2820
Geregistreerd: 16 Okt 2013, 14:31
Woonplaats: s hertogenbosch

Re: servo verplaatsen van a naar b

Berichtdoor shooter » 14 Aug 2019, 23:09

dat komt door de plaatsing van die haken, de laatste keer werd de delay elke graad uitgevoerd, en de eerste was alleen maar aan het einde van de for loop.
paul deelen
shooter@home.nl

Advertisement

Berichten: 7
Geregistreerd: 13 Aug 2019, 08:58

Re: servo verplaatsen van a naar b

Berichtdoor erve » 21 Aug 2019, 22:02

Probleem opgelost.

Code: Alles selecteren
/* LDR_drives_servo 60819
 * Created: 16-08-2019
 * Software version: 1.8.9
 * Board: arduino mega
 ldr connected to 5v to a0 and 10k resistor to ground
 write ldr a0 analog value to arduino ide serial terminal
 turn onboard leds on or off depending off ldr value
 Open or close door depending off LDR value.
 */

// define variables for servo use
#include <Servo.h>
Servo myservo;  // create servo object to control a servo
int pos = 0;    // punt a van de servo
// --------------------------------------

// define variables for led's and LDR

#define LDRpin A0 // pin where we connected the LDR and the resistor
int LDRValue = 0; // variable to store the value coming from the sensor
boolean x = true;

int ledGPin=8; // Red Led
int ledRPin=9; // Green led

// -------------------------------------

// the setup routine runs once when you press reset:
void setup() {   
             
  myservo.attach(11);  // attaches the servo on pin 11 to the servo object
  pinMode(ledGPin, OUTPUT);// initialize the digital pin as an output.
  pinMode(ledRPin, OUTPUT);
  Serial.begin(9600); //sets serial port for communication 
}
// -------------------------------------

// the loop routine runs over and over again forever:
void loop() {
  LDRValue = analogRead(A0);
  Serial.println(LDRValue);
  delay(50);
 
  if ( LDRValue < 300 && x == true){
    digitalWrite(ledGPin,LOW);
    digitalWrite(ledRPin,HIGH);
    x = false;
    delay(50);
    OpenDoor();
  }
  else if ( LDRValue >300 && x == false){
    x = true;
    digitalWrite(ledGPin,HIGH);
    digitalWrite(ledRPin,LOW);
    delay(50);
    CloseDoor();
  }
}
void CloseDoor()
 {
   for ( pos = 0; pos <= 180; pos += 1)  // goes from 0 degrees to 180 degrees in steps of 1 degree
    {
   myservo.write(pos);                   // tell servo to go to position in variable 'pos'
     delay(15);                          // waits 15ms for the servo to reach the position
  }
   }

void OpenDoor()
 {
   for (pos = 180; pos >= 0; pos -= 1)  // goes from 180 degrees to 0 degrees
   {
    myservo.write(pos);                 // tell servo to go to position in variable 'pos'
    delay(15);                          // waits 15ms for the servo to reach the position
   }
 
}

Vorige

Terug naar Arduino software

Wie is er online?

Gebruikers in dit forum: Google [Bot] en 1 gast