Problem with calling a fonction
good evening everyone!
english isnt native language gonna full of mistakes, sorry!
i student in master mechatronics.
i have mini project arduino: turret controlled joystick (2 servos). 2 operating modes:
- holding position when releasing joystick (with dead zone or dead band).
- continuous monitoring of position of joystick.
for used push button, turned switch (a simple algorithm toggle state) , select between two.
i added lcd show of modes active. far, good
the problem when i call functions, depending on state of button, functions of both modes not work, if lcd displays correctly mode active, without problem.
i have tested every part of code. lcd works perfectly, th 2 modes too, bouton mission pretty fine. dont know be.
i leave here sample of code, call of 1 of 2 modes. without lcd , without buttons:
and here entire code
i hope u can me because im blocked.
thanks lot!!
english isnt native language gonna full of mistakes, sorry!

i student in master mechatronics.
i have mini project arduino: turret controlled joystick (2 servos). 2 operating modes:
- holding position when releasing joystick (with dead zone or dead band).
- continuous monitoring of position of joystick.
for used push button, turned switch (a simple algorithm toggle state) , select between two.
i added lcd show of modes active. far, good
the problem when i call functions, depending on state of button, functions of both modes not work, if lcd displays correctly mode active, without problem.
i have tested every part of code. lcd works perfectly, th 2 modes too, bouton mission pretty fine. dont know be.
i leave here sample of code, call of 1 of 2 modes. without lcd , without buttons:
code: [select]
#include <servo.h>;
const int servohpin = 9;
const int servovpin = 10;
int horzpin = a0;
int vertpin = a1;
servo horzservo;
servo vertservo;
int horzinitpos;
int vertinitpos;
int horzpotmax = 2350;
int horzpotmin = 594;
int vertpotmax = 2350;
int vertpotmin = 594;
int horzdeadbandlow = 400;
int horzdeadbandhigh = 600;
int vertdeadbandlow = 400;
int vertdeadbandhigh = 600;
int horzspeed = 4 ;
int vertspeed = 4 ;
int jyhorzval;
int jyvertval;
int jyhorzmapped;
int jyvertmapped;
void setup() {
// put setup code here, run once:
horzservo.attach(servohpin);
vertservo.attach(servovpin);
horzinitpos = 1472;
vertinitpos = 1472;
horzservo.writemicroseconds(horzinitpos);
vertservo.writemicroseconds(vertinitpos);
}
void loop() {
// put main code here, run repeatedly:
holdpositionmode();
}
void holdpositionmode() {
int horzinitpos;
int vertinitpos;
jyhorzval=analogread(horzpin);
jyvertval=analogread(vertpin);
horzinitpos = constrain(horzinitpos, horzpotmin, horzpotmax) ;
vertinitpos = constrain(vertinitpos, vertpotmin, vertpotmax) ;
if(jyhorzval<horzdeadbandlow || jyhorzval>horzdeadbandhigh)
{
jyhorzmapped=map(jyhorzval,0,1023,horzspeed,-horzspeed);
horzinitpos=horzinitpos+jyhorzmapped;
}
if(jyvertval<vertdeadbandlow || jyvertval>vertdeadbandhigh)
{
jyvertmapped=map(jyvertval,0,1023,vertspeed,-vertspeed);
vertinitpos=vertinitpos+jyvertmapped;
}
horzservo.writemicroseconds(horzinitpos);
vertservo.writemicroseconds(vertinitpos);
delay(20);
}
and here entire code
i hope u can me because im blocked.
thanks lot!!
by holding position mean turret stays still , has no motion @ all?
Arduino Forum > Using Arduino > Programming Questions > Problem with calling a fonction
arduino
Comments
Post a Comment