5.3.13

Mõtetu kasti soft, ver2

Siin siis üks töötav ja testitud versioon mõtetust boxist:


#include <Servo.h>

Servo myservo;  // create servo object to control a servo 

int pos = 0;    // variable to store the servo position 
int maxPos = 140; // Servo maximum position, in degrees
int minPos = 54; // servo minimum position, in degreed
int buttonPos = LOW;

void setup(){
  // servo red cable to +5
  // servo black cable to ground
  // servo yellow cable to pin 9
  myservo.attach(9);  
  
  pinMode(3,INPUT); // this is button input
  pinMode(7,OUTPUT); // this is led output
}


void loop(){
  // read the button
  buttonPos = digitalRead(3);
  // set led to same value 
  digitalWrite(7,buttonPos);

  if (buttonPos == LOW){
    // move servo
    myservo.write(minPos);
  } 
  else {
    // move servo
    myservo.write(maxPos);
  }
}




Ja ühendused fritzingus


Kommentaare ei ole:

Postita kommentaar