Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 5.) Fuß L+R Auswerten, Verarbeiten, Senden. SLAVE
- #include <Wire.h>
- #include <Keyboard.h>
- //Analog Pins
- const int FRH = A0;
- const int FRV = A1;
- const int FLH = A2;
- const int FLV = A3;
- //Analogen Werte
- int FRh1 = 0;
- int FRv2 = 0;
- int FLh1 = 0;
- int FLv2 = 0;
- //Analog Grenzen (Parameter per Wire Empfangen)
- //Fuß Rechts
- int FRhmin = 550;
- int FRhmax = 590;
- int FRvmin = 550;
- int FRvmax = 590;
- //Fuß Links
- int FLhmin = 550;
- int FLhmax = 590;
- int FLvmin = 550;
- int FLvmax = 590;
- //Timer(Parameter per Wire Empfangen)
- //Timer Rechts
- int Timer = 0;
- int TimerR1 = 0;
- int TimerR2 = 0;
- int TimerR3 = 0;
- //Timer Links
- int TimerL1 = 0;
- int TimerL2 = 0;
- int TimerL3 = 0;
- //Fuß Status
- int FRh1s = 0;
- int FRv1s = 0;
- int FLh1s = 0;
- int FLv1s = 0;
- void setup() {
- // Wire.begin(?);
- // Wire.onReceive(receiveEvent);
- }
- void loop(){
- FRh1 = analogRead(FRH);
- FRv2 = analogRead(FRV);
- FLh1 = analogRead(FLH);
- FLv2 = analogRead(FLV);
- //Begrenzen des Messraums
- if (FRh1 < FRhmin){FRh1=FRhmin;}
- if (FRh1 > FRhmax){FRh1=FRhmax;}
- if (FLh1 < FLhmin){FLh1=FLhmin;}
- if (FLh1 > FLhmax){FLh1=FLhmax;}
- //Konvertieren der Analogen werte (Grenze oben/unten per Wire empfangen)
- FRh1s = map(FRh1, 500, 600, 1, 2);
- FRv1s = map(FRv2, 460, 560, 1, 2);
- FLh1s = map(FLh1, 500, 600, 1, 2);
- FLv1s = map(FLv2, 460, 560, 1, 2);
- Stand();
- }
- void Stand(){
- if ((FRh1s==1)&&(FRv1s==1)&&(FLh1s==1)&&(FLv1s==1)){Stand();}
- if ((FRh1s==0)&&(FRv1s==1)&&(FLh1s==1)&&(FLv1s==1)){Timer=TimerR1; Rechts1();}
- if ((FRh1s==1)&&(FRv1s==1)&&(FLh1s==0)&&(FLv1s==1)){Timer=TimerL1; Links1();}
- }
- void Rechts(){
- if ((FRh1s==1)&&(FRv1s==1)&&(FLh1s==1)&&(FLv1s==1)){Stand();}
- if ((FRh1s==0)&&(FRv1s==0)&&(FLh1s==1)&&(FLv1s==1)){Timer=TimerR2; Rechts1();}
- if (Timer>0){Rechts();}
- }
- void Rechts1(){
- if ((FRh1s==1)&&(FRv1s==1)&&(FLh1s==1)&&(FLv1s==1)){Stand();}
- if ((FRh1s==1)&&(FRv1s==0)&&(FLh1s==1)&&(FLv1s==1)){
- Keyboard.press('W');
- Timer=TimerR3;
- Rechts2();}
- if (Timer>0){Timer--; Rechts1();}
- }
- void Rechts2(){
- if ((FRh1s==1)&&(FRv1s==1)&&(FLh1s==1)&&(FLv1s==1)){Stand();}
- if ((FRh1s==1)&&(FRv1s==1)&&(FLh1s==0)&&(FLv1s==1)){Timer=TimerL1; Links();}
- if (Timer>0){Timer--;Rechts2();}
- }
- void Links(){
- if ((FRh1s==1)&&(FRv1s==1)&&(FLh1s==1)&&(FLv1s==1)){Stand();}
- if ((FRh1s==1)&&(FRv1s==1)&&(FLh1s==0)&&(FLv1s==0)){Timer=TimerL2;Links1();}
- if (Timer>0){Timer--;Links();}
- }
- void Links1(){
- if ((FRh1s==1)&&(FRv1s==1)&&(FLh1s==1)&&(FLv1s==1)){Stand();}
- if ((FRh1s==1)&&(FRv1s==1)&&(FLh1s==1)&&(FLv1s==0)){
- Keyboard.press('W');
- Timer=TimerL3;
- Links2();}
- if (Timer>0){Timer--; Links1();}
- }
- void Links2(){
- if ((FRh1s==1)&&(FRv1s==1)&&(FLh1s==1)&&(FLv1s==1)){Stand();}
- if ((FRh1s==0)&&(FRv1s==1)&&(FLh1s==1)&&(FLv1s==1)){Timer=TimerR1;Rechts();}
- if (Timer>0){Timer--;Links2();}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement