Visualizza messaggio singolo
Vecchio 25 aprile 20, 00:10   #4 (permalink)  Top
madqwerty
User
 
L'avatar di madqwerty
 
Data registr.: 18-05-2013
Residenza: Chivasso (TO)
Messaggi: 2.352
considerando che non programmo con Arduino da un tot (non programmo da un tot in generale ) e che non ho mai usato la libreria servo..

#include <Servo.h>

Servo myServo,
myInput;
int newPos,
oldPos;
bool direzione;

void setup()
{
myServo.attach(10);
myInput.attach(ingresso_ch3);
newPos = 90;
oldPos = 90;
direzione = true;
myservo.write(pos);
}


void loop()
{
oldPos = newPos;

if (myInput.read() < soglia_on_off_ch3)
{
newPos = 90;
direzione = true;
}
else
{
if (direzione)
{
if (newPos < 220)
NewPos++;
else
direzione = false;
}
else
{
if(newPos > -40)
NewPos--;
else
direzione = true;
}

if ( (newPos != oldPos) AND (newPos <= 180) AND (newPos >=0) )
myservo.write(newPos);

delay(25);
}


non so se sia giusta la routine di lettura dell'input, e anche non ricordo come dichiarare gli AND
__________________
v911 - mCPX - PRȎTOS - TRex 450 500 550
A959B - Q32 - DF03 - LRP TC2 - XB4 - M06 - B5(M) - T8E - X1 - T4 - XB2C - GF01
madqwerty non è collegato   Rispondi citando