Subversion Repositories svnkaklik

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
1 kaklik 1
#define THRESHOLD  44     // rozhodovaci uroven mezi cernou a bilou
2
#define RED_WHITE  60     // maximum bile na cervenem senzoru
3
#define MLEFT     OUT_A
4
#define MRIGHT    OUT_C
5
#define BLUE      SENSOR_1
6
#define RED       SENSOR_2
7
#define BBUMPER   SENSOR_3
8
#define START_ALL start blue_bumper; start cara_cervena; start cara_modra;
9
 
10
int semafor;
11
 
12
task main()
13
{
14
  PlaySound (SOUND_DOUBLE_BEEP);
15
  Wait(500); // 5s podle pravidel
16
  SetSensor(BLUE,SENSOR_LIGHT);   // senzor na caru modry
17
  SetSensor(RED,SENSOR_LIGHT);   // senzor na caru cerveny
18
  SetSensor(BBUMPER, SENSOR_TOUCH);  // naraznik modry
19
  SetSensorMode (BBUMPER, SENSOR_MODE_BOOL); // koncak bude ...
20
  SetPower (MLEFT,OUT_FULL);
21
  SetPower (MRIGHT,OUT_FULL);
22
  SetDirection(MLEFT, OUT_FWD);
23
  SetDirection(MRIGHT, OUT_FWD);
24
 
25
  OnFwd (MLEFT);         // cuknuti na shozeni radlic
26
  OnFwd (MRIGHT);
27
  Wait(50);
28
  GoRed();
29
 
30
  start red_bumper;
31
  start blue_bumper;
32
  start cara_cervena;
33
  start cara_modra;
34
  start stochastika;
35
}
36
 
37
task stochastika()
38
{
39
  while(true) Zatoc();
40
}
41
 
42
 
43
void GoBlue()
44
{
45
  OnFwd (MLEFT);
46
  OnFwd (MRIGHT);
47
  Wait(300);              // popojed kus
48
  Off(MLEFT);
49
  Off(MRIGHT);
50
}
51
 
52
void GoRed()
53
{
54
  OnRev (MLEFT);
55
  OnRev (MRIGHT);
56
  Wait(300);              // popojed kus
57
  Off(MLEFT);
58
  Off(MRIGHT);
59
}
60
 
61
void Zatoc()
62
{
63
  switch (Random(3))
64
  {
65
    case 0:
66
     OnRev (MLEFT);
67
     OnFwd (MRIGHT);
68
     Wait(200);
69
     break;
70
    case 1:
71
     OnFwd (MLEFT);
72
     OnRev (MRIGHT);
73
     Wait(200);
74
     break;
75
    case 2:
76
     OnRev (MLEFT);
77
     OnRev (MRIGHT);
78
     Wait(20);
79
     break;
80
    case 3:
81
     OnFwd (MLEFT);
82
     OnFwd (MRIGHT);
83
     Wait(20);
84
     break;
85
  }
86
}
87
 
88
task red_bumper()
89
{
90
  while(true)
91
  {
92
    if (100 == RED) // utoc, kdyz neco narazi do narazniku
93
    {
94
      PlaySound (SOUND_FAST_UP);
95
      stop stochastika;
96
      OnRev (MLEFT);
97
      OnRev (MRIGHT);
98
      Wait(50);
99
    }
100
  }
101
}
102
 
103
task blue_bumper()
104
{
105
  while(true)
106
  {
107
    if (1 == BBUMPER) // utoc, kdyz neco narazi do narazniku
108
    {
109
      PlaySound (SOUND_FAST_UP);
110
      stop stochastika;
111
      OnFwd (MLEFT);
112
      OnFwd (MRIGHT);
113
      Wait(50);
114
    }
115
  }
116
}
117
 
118
task cara_cervena() // hlidani natlaceni na caru
119
{
120
  while(true)
121
  {
122
    if ((RED > THRESHOLD) && (RED < RED_WHITE))
123
    {
124
      Wait(2);
125
      if ((RED > THRESHOLD) && (RED < RED_WHITE))
126
      {
127
        PlaySound (SOUND_DOUBLE_BEEP);
128
        stop red_bumper;
129
        GoBlue();
130
        start red_bumper;
131
        start stochastika;
132
      }
133
    }
134
  }
135
}
136
 
137
task cara_modra()    // hlidani cary
138
{
139
  while(true)
140
  {
141
     if (BLUE < THRESHOLD)    // cekej na caru
142
     {
143
        PlaySound (SOUND_DOUBLE_BEEP);
144
        stop blue_bumper;
145
        GoRed();
146
        start blue_bumper;
147
        start stochastika;
148
     }
149
  }
150
}
151