Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define THRESHOLD 40
- #define MIC SENSOR_2
- bool timer = false;
- sub turn(string richtung){
- if(richtung == "rechts"){
- OnFwd(OUT_C,50);
- OnRev(OUT_B,50);
- Wait(700);
- Off(OUT_BC);
- }
- if(richtung == "links"){
- OnFwd(OUT_B,50);
- OnRev(OUT_C,50);
- Wait(700);
- Off(OUT_BC);
- }
- }
- task main(){
- SetSensorSound(IN_2);
- long time;
- long t0;
- int clap = 0;
- int tmp = 0;
- int direction = 0;
- bool motor = false;
- while(true){
- until(MIC > THRESHOLD);
- clap = 1;
- Wait(200);
- t0 = CurrentTick();
- time = CurrentTick() - t0;
- while(time < 1000){
- TextOut(5,LCD_LINE2,"Timer gestartet");
- if(MIC > tmp) tmp = MIC;
- time = CurrentTick() - t0;
- }
- TextOut(5,LCD_LINE2,"Timer beendet");
- if(tmp > THRESHOLD) clap = 2;
- if(clap == 1 && motor){
- Off(OUT_BC);
- motor = false;
- }
- else if(clap == 1 && direction == 0 && motor == false){
- OnFwd(OUT_BC,50);
- motor = true;
- }
- else if(clap == 1 && direction == 1 && motor == false){
- OnRev(OUT_BC,50);
- motor = true;
- }
- if(clap == 2 && motor == false){
- if(direction == 0){
- direction = 1;
- TextOut(5,LCD_LINE3,"Richtung: Rev");
- }
- else if(direction == 1){
- direction = 0;
- TextOut(5,LCD_LINE3,"Richtung: Fwd");
- }
- }
- clap = 0;
- tmp = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement