0

Hello everybody,

I'm trying to make a script bash to move a cam with servoblaster. when I strike a lettre (i,o,l,p) I would like increment or decrement a variable, to move the camera degree by degree or percent

My problem I can't adapt my command echo P1-11=90% >/dev/servoblaster to a variable to increase or decrease the nomber 90%. this is my code:

#!/bin/sh

#ServoBlaster

sudo /home/user/PiBits/ServoBlaster/user/./servod --p1=11,12

readkeyboard=`stty -icanon ; dd bs=1 count=1 2>/dev/null`

if [ "$readkeyboard" = 'o' ]; then i=$((i+1))  echo P1-11=$i >/dev/servoblaster #up

elif [ "$readkeyboard" = 'l' ]; then i=$((i-1)) echo P1-11=$i >/dev/servoblaster #down

elif [ "$readkeyboard" = 'i' ]; then i=$((i+1)) echo P1-12=$i >/dev/servoblaster #left

elif [ "$readkeyboard" = 'p' ]; then i=$((i-1)) echo P1-12=$i >/dev/servoblaster #right 

fi

done

Thank you in advance for your help.

Finally I have found, This is my code:

#!/bin/sh
#echo p1-22=250 > /dev/servoblaster #angle
#echo P1­-11=80% > /dev/servoblaster #pourcent


#ServoBlaster

#$i=90
#$s=90
sudo /home/user/PiBits/ServoBlaster/user/./servod --p1=11,12

while(true);do

readkeyboard=`stty -icanon ; dd bs=1 count=1 2>/dev/null`

if [ "$readkeyboard" = 'l' ]; then i=$((i+1)) ;  echo P1-11=$i >/dev/servoblaster #up

elif [ "$readkeyboard" = 'o' ]; then i=$((i-1)) ;  echo P1-11=$i >/dev/servoblaster #down

elif [ "$readkeyboard" = 'i' ]; then s=$((s+1)) ; echo P1-12=$s >/dev/servoblaster #left

elif [ "$readkeyboard" = 'p' ]; then s=$((s-1)) ; echo P1-12=$s >/dev/servoblaster #right 


fi

clear
done
  • Are you saying the script is working now? – joan Jun 28 '16 at 11:58
1

Your shell script is wrong. You need a semicolon between the reassignment of i and echo so that they are run as two separate commands.

Also, this has nothing to do with Raspberry Pi; it's a shell question.

  • Thanks for you answer, I change it to stackoverflow.com in area bash. – John Jun 27 '16 at 17:40
  • Thank for your correction in my code, some time I'm lost and need external help – John Jun 28 '16 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.