Advertisement
Guest User

Foot_Slave_3

a guest
Dec 7th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.87 KB | None | 0 0
  1. // 5.) Fuß L+R Auswerten, Verarbeiten, Senden. SLAVE
  2.  
  3. #include <Wire.h>
  4. #include <Keyboard.h>
  5.  
  6. //Analog Pins
  7. const int FRH = A0;
  8. const int FRV = A1;
  9. const int FLH = A2;
  10. const int FLV = A3;
  11.  
  12. //Analogen Werte
  13. int FRh1 = 0;
  14. int FRv2 = 0;
  15. int FLh1 = 0;
  16. int FLv2 = 0;
  17.  
  18.  
  19. //Analog Grenzen (Parameter per Wire Empfangen)
  20. //Fuß Rechts
  21. int FRhmin = 550;
  22. int FRhmax = 590;
  23. int FRvmin = 550;
  24. int FRvmax = 590;
  25. //Fuß Links
  26. int FLhmin = 550;
  27. int FLhmax = 590;
  28. int FLvmin = 550;
  29. int FLvmax = 590;
  30.  
  31. //Timer(Parameter per Wire Empfangen)
  32. //Timer Rechts
  33. int Timer   = 0;
  34. int TimerR1 = 0;
  35. int TimerR2 = 0;
  36. int TimerR3 = 0;
  37.  
  38. //Timer Links
  39. int TimerL1 = 0;
  40. int TimerL2 = 0;
  41. int TimerL3 = 0;
  42.  
  43. //Fuß Status
  44. int FRh1s = 0;
  45. int FRv1s = 0;
  46. int FLh1s = 0;
  47. int FLv1s = 0;
  48.  
  49. void setup() {
  50. //  Wire.begin(?);
  51. //  Wire.onReceive(receiveEvent);
  52. }
  53.  
  54. void loop(){
  55.   FRh1 = analogRead(FRH);
  56.   FRv2 = analogRead(FRV);
  57.   FLh1 = analogRead(FLH);  
  58.   FLv2 = analogRead(FLV);
  59.   //Begrenzen des Messraums
  60.   if (FRh1 < FRhmin){FRh1=FRhmin;}
  61.   if (FRh1 > FRhmax){FRh1=FRhmax;}
  62.   if (FLh1 < FLhmin){FLh1=FLhmin;}
  63.   if (FLh1 > FLhmax){FLh1=FLhmax;}
  64.   //Konvertieren der Analogen werte (Grenze oben/unten per Wire empfangen)
  65.   FRh1s = map(FRh1, 500, 600, 1, 2);
  66.   FRv1s = map(FRv2, 460, 560, 1, 2);
  67.   FLh1s = map(FLh1, 500, 600, 1, 2);
  68.   FLv1s = map(FLv2, 460, 560, 1, 2);
  69.   Stand();
  70.   }
  71.  
  72. void Stand(){
  73.    if ((FRh1s==1)&&(FRv1s==1)&&(FLh1s==1)&&(FLv1s==1)){Stand();}
  74.    if ((FRh1s==0)&&(FRv1s==1)&&(FLh1s==1)&&(FLv1s==1)){Timer=TimerR1; Rechts1();}
  75.    if ((FRh1s==1)&&(FRv1s==1)&&(FLh1s==0)&&(FLv1s==1)){Timer=TimerL1; Links1();}
  76.   }
  77. void Rechts(){
  78.  if ((FRh1s==1)&&(FRv1s==1)&&(FLh1s==1)&&(FLv1s==1)){Stand();}
  79.  if ((FRh1s==0)&&(FRv1s==0)&&(FLh1s==1)&&(FLv1s==1)){Timer=TimerR2; Rechts1();}
  80.  if (Timer>0){Rechts();}
  81. }
  82. void Rechts1(){  
  83.  if ((FRh1s==1)&&(FRv1s==1)&&(FLh1s==1)&&(FLv1s==1)){Stand();}
  84.  if ((FRh1s==1)&&(FRv1s==0)&&(FLh1s==1)&&(FLv1s==1)){
  85.   Keyboard.press('W');
  86.   Timer=TimerR3;
  87.   Rechts2();}
  88.  if (Timer>0){Timer--; Rechts1();}
  89. }
  90. void Rechts2(){      
  91.   if ((FRh1s==1)&&(FRv1s==1)&&(FLh1s==1)&&(FLv1s==1)){Stand();}
  92.   if ((FRh1s==1)&&(FRv1s==1)&&(FLh1s==0)&&(FLv1s==1)){Timer=TimerL1; Links();}
  93.   if (Timer>0){Timer--;Rechts2();}
  94. }
  95. void Links(){
  96.   if ((FRh1s==1)&&(FRv1s==1)&&(FLh1s==1)&&(FLv1s==1)){Stand();}
  97.   if ((FRh1s==1)&&(FRv1s==1)&&(FLh1s==0)&&(FLv1s==0)){Timer=TimerL2;Links1();}
  98.   if (Timer>0){Timer--;Links();}
  99. }
  100. void Links1(){
  101.  if ((FRh1s==1)&&(FRv1s==1)&&(FLh1s==1)&&(FLv1s==1)){Stand();}
  102.  if ((FRh1s==1)&&(FRv1s==1)&&(FLh1s==1)&&(FLv1s==0)){
  103.   Keyboard.press('W');
  104.   Timer=TimerL3;
  105.   Links2();}
  106.  if (Timer>0){Timer--; Links1();}
  107. }
  108. void Links2(){
  109.   if ((FRh1s==1)&&(FRv1s==1)&&(FLh1s==1)&&(FLv1s==1)){Stand();}
  110.   if ((FRh1s==0)&&(FRv1s==1)&&(FLh1s==1)&&(FLv1s==1)){Timer=TimerR1;Rechts();}
  111.   if (Timer>0){Timer--;Links2();}
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement