football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Committer:
andriym
Date:
Thu Jun 16 06:52:07 2016 +0000
Revision:
98:9241041ec253
Parent:
97:2894fbc2d4f8
Removed timer.;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andriym 78:43a6b54f0372 1 #include <list>
andriym 82:1e552cc1a615 2 #include <DebounceIn.h>
andriym 97:2894fbc2d4f8 3 #include "configs.h"
AntonLS 0:28ca4562fe1a 4
andriym 78:43a6b54f0372 5 using namespace std;
andriym 78:43a6b54f0372 6
andriym 78:43a6b54f0372 7 /////////////////////////////////// PINS ///////////////////////////////////
andriym 79:9db29f41dc9d 8
andriym 82:1e552cc1a615 9 DebounceIn buttonTeam(BUT_TEAM);
andriym 82:1e552cc1a615 10 DebounceIn buttonSpace(BUT_SPACE);
andriym 82:1e552cc1a615 11 DebounceIn buttonVolMore(BUT_VOL_MORE);
andriym 82:1e552cc1a615 12 DebounceIn buttonVolLess(BUT_VOL_LESS);
andriym 81:3cd7de5d01ef 13
andriym 79:9db29f41dc9d 14 DigitalOut ledTeamA(LED_TEAM_A);
andriym 79:9db29f41dc9d 15 DigitalOut ledTeamB(LED_TEAM_B);
andriym 79:9db29f41dc9d 16 DigitalOut ledSpace5(LED_SPACE5);
andriym 79:9db29f41dc9d 17 DigitalOut ledSpace10(LED_SPACE10);
andriym 79:9db29f41dc9d 18 DigitalOut ledSpace15(LED_SPACE15);
andriym 79:9db29f41dc9d 19 DigitalOut ledSpace20(LED_SPACE20);
andriym 81:3cd7de5d01ef 20 DigitalOut ledBuzzer(LED_BUZZER_ON);
andriym 81:3cd7de5d01ef 21
andriym 79:9db29f41dc9d 22 AnalogIn ain(ANALOG_IN); // used for randomizing
andriym 78:43a6b54f0372 23 #ifdef NORDIC
andriym 79:9db29f41dc9d 24 DigitalOut buzzer(BUZZER);
andriym 88:d3f0394da5aa 25 #ifndef HARD_V2
andriym 79:9db29f41dc9d 26 DigitalOut buzzLow(BUZZ_LOW);
andriym 88:d3f0394da5aa 27 #endif
andriym 79:9db29f41dc9d 28 DigitalOut buzzMed(BUZZ_MED);
andriym 79:9db29f41dc9d 29 DigitalOut buzzHigh(BUZZ_HIGH);
andriym 79:9db29f41dc9d 30 #else
andriym 79:9db29f41dc9d 31 PwmOut speaker(BUZZER); // passive buzzer
andriym 79:9db29f41dc9d 32 #endif
AntonLS 30:c60b0d52b067 33
andriym 78:43a6b54f0372 34 /////////////////////////////////// FUNCTIONS ///////////////////////////////////
andriym 78:43a6b54f0372 35
andriym 81:3cd7de5d01ef 36 void beep(float period, float time, uint8_t vol) {
andriym 78:43a6b54f0372 37 #ifdef ENABLE_SOUND
andriym 81:3cd7de5d01ef 38 if(!vol) return;
andriym 79:9db29f41dc9d 39 #ifdef NORDIC
andriym 81:3cd7de5d01ef 40 if(vol>=3) {
andriym 88:d3f0394da5aa 41 #ifndef HARD_V2
andriym 88:d3f0394da5aa 42 buzzLow = LOW_ON;
andriym 88:d3f0394da5aa 43 #endif
andriym 88:d3f0394da5aa 44 buzzMed = MED_OFF; buzzHigh = HIGH_OFF;
andriym 81:3cd7de5d01ef 45 } else if(vol>=2) {
andriym 88:d3f0394da5aa 46 #ifndef HARD_V2
andriym 88:d3f0394da5aa 47 buzzLow = LOW_OFF;
andriym 88:d3f0394da5aa 48 #endif
andriym 88:d3f0394da5aa 49 buzzMed = MED_ON; buzzHigh = HIGH_OFF;
andriym 79:9db29f41dc9d 50 } else {
andriym 88:d3f0394da5aa 51 #ifndef HARD_V2
andriym 88:d3f0394da5aa 52 buzzLow = LOW_OFF;
andriym 88:d3f0394da5aa 53 #endif
andriym 88:d3f0394da5aa 54 buzzMed = MED_OFF; buzzHigh = HIGH_ON;
andriym 79:9db29f41dc9d 55 }
andriym 80:8d4f190bd253 56 buzzer = 0; // P-MOSFET
andriym 80:8d4f190bd253 57 wait(time);
andriym 79:9db29f41dc9d 58 buzzer = 1;
andriym 79:9db29f41dc9d 59 #else
andriym 78:43a6b54f0372 60 speaker.period(period);
andriym 81:3cd7de5d01ef 61 if(vol>=3)
andriym 81:3cd7de5d01ef 62 speaker = 0.5; //50% duty cycle - max volume
andriym 81:3cd7de5d01ef 63 else if(vol>=2)
andriym 81:3cd7de5d01ef 64 speaker = 0.33;
andriym 81:3cd7de5d01ef 65 else
andriym 81:3cd7de5d01ef 66 speaker = 0.2;
andriym 78:43a6b54f0372 67 wait(time);
andriym 78:43a6b54f0372 68 speaker=0.0; // turn off audio
andriym 78:43a6b54f0372 69 #endif
andriym 79:9db29f41dc9d 70 #endif
andriym 78:43a6b54f0372 71 }
andriym 78:43a6b54f0372 72
andriym 78:43a6b54f0372 73 void binary_sound(int z) {
andriym 78:43a6b54f0372 74 // Beeps numbers according to their binary form
andriym 78:43a6b54f0372 75 // (used for debugging in display-less and serial-less environments)
andriym 78:43a6b54f0372 76 #ifdef ENABLE_SOUND
andriym 79:9db29f41dc9d 77 #ifndef NORDIC
andriym 78:43a6b54f0372 78 speaker.period(0.004);
andriym 78:43a6b54f0372 79 while(z) {
andriym 78:43a6b54f0372 80 speaker = 0.5;
andriym 78:43a6b54f0372 81 if(z&1) wait(0.5);
andriym 78:43a6b54f0372 82 else wait(0.25);
andriym 78:43a6b54f0372 83 speaker = 0.0;
andriym 78:43a6b54f0372 84 wait(1.0);
andriym 78:43a6b54f0372 85 z >>= 1;
andriym 78:43a6b54f0372 86 }
andriym 81:3cd7de5d01ef 87 beep(NOTE_A4, 1.0, 2);
andriym 79:9db29f41dc9d 88 #endif
andriym 78:43a6b54f0372 89 #endif
andriym 78:43a6b54f0372 90 }
andriym 78:43a6b54f0372 91
andriym 78:43a6b54f0372 92 void generate_name(char rand_name[], uint8_t size) {
andriym 78:43a6b54f0372 93 // Generate random name on the 62 character alphabet
andriym 78:43a6b54f0372 94 memset(rand_name, 0x00, size);
andriym 78:43a6b54f0372 95 char alph[63] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
andriym 97:2894fbc2d4f8 96 uint32_t seed = ((ain.read_u16()+3)/17)*((ain.read_u16()+5)/13);
andriym 78:43a6b54f0372 97 srand(seed);
andriym 78:43a6b54f0372 98 for(int i=0;i<size-1;i++) {
andriym 78:43a6b54f0372 99 rand_name[i] = alph[abs(rand()) % 62];
andriym 78:43a6b54f0372 100 }
andriym 78:43a6b54f0372 101 }
andriym 78:43a6b54f0372 102
andriym 86:2a569d9e67f5 103 void spaceLEDs(int level) {
andriym 85:4692a1790cfa 104 if(level<=0) {
andriym 85:4692a1790cfa 105 ledSpace5 = 1; ledSpace10 = 0; ledSpace15 = 0; ledSpace20 = 0;
andriym 85:4692a1790cfa 106 } else if(level<=1) {
andriym 85:4692a1790cfa 107 ledSpace5 = 0; ledSpace10 = 1; ledSpace15 = 0; ledSpace20 = 0;
andriym 85:4692a1790cfa 108 } else if(level<=2) {
andriym 85:4692a1790cfa 109 ledSpace5 = 0; ledSpace10 = 0; ledSpace15 = 1; ledSpace20 = 0;
andriym 85:4692a1790cfa 110 } else {
andriym 85:4692a1790cfa 111 ledSpace5 = 0; ledSpace10 = 0; ledSpace15 = 0; ledSpace20 = 1;
andriym 85:4692a1790cfa 112 }
andriym 85:4692a1790cfa 113 }
andriym 85:4692a1790cfa 114
andriym 89:425369a595c4 115
andriym 78:43a6b54f0372 116 /////////////////////////////////// CLASSES ///////////////////////////////////
andriym 78:43a6b54f0372 117
andriym 78:43a6b54f0372 118 struct Contact {
andriym 78:43a6b54f0372 119 int16_t rssi;
andriym 78:43a6b54f0372 120 uint32_t time_ms;
andriym 78:43a6b54f0372 121 };
andriym 78:43a6b54f0372 122
andriym 78:43a6b54f0372 123 class Player {
andriym 78:43a6b54f0372 124 public:
andriym 78:43a6b54f0372 125 char name[NAME_LEN+1];
andriym 78:43a6b54f0372 126 int8_t team;
andriym 78:43a6b54f0372 127 Player(const char rand_name[]) {
andriym 78:43a6b54f0372 128 memset(name, 0x00, NAME_LEN+1);
andriym 78:43a6b54f0372 129 memcpy(name, rand_name, NAME_LEN);
andriym 78:43a6b54f0372 130 }
andriym 78:43a6b54f0372 131 void update(int8_t _team, int rssi, uint32_t time=NULL) {
andriym 78:43a6b54f0372 132 // Remember this contact
andriym 78:43a6b54f0372 133 team = _team;
andriym 78:43a6b54f0372 134 Contact c;
andriym 78:43a6b54f0372 135 c.rssi = rssi;
andriym 98:9241041ec253 136 c.time_ms = (time!=NULL) ? time : 0; //tmr.read_ms();
andriym 78:43a6b54f0372 137 contacts.push_front(c);
andriym 78:43a6b54f0372 138
andriym 78:43a6b54f0372 139 // Cleanup
andriym 78:43a6b54f0372 140 while(contacts.size() > MAX_RECORDS) contacts.pop_back();
andriym 78:43a6b54f0372 141 while(!contacts.empty() && c.time_ms - contacts.back().time_ms > MAX_HISTORY_MS) contacts.pop_back();
andriym 78:43a6b54f0372 142 }
andriym 78:43a6b54f0372 143 int16_t get_distance(int &cnt) {
andriym 78:43a6b54f0372 144 // Find max RSSI
andriym 98:9241041ec253 145 uint32_t cur_time = 0; //tmr.read_ms();
andriym 78:43a6b54f0372 146 int16_t max_rssi=-128;
andriym 78:43a6b54f0372 147 cnt=0;
andriym 78:43a6b54f0372 148 for (list<Contact>::iterator it=contacts.begin(); it != contacts.end(); ++it) {
andriym 78:43a6b54f0372 149 if(cur_time - it->time_ms > SIGNALS_VALID_MS) break;
andriym 78:43a6b54f0372 150 if(it->rssi > max_rssi) max_rssi = it->rssi;
andriym 78:43a6b54f0372 151 cnt++;
andriym 78:43a6b54f0372 152 }
andriym 78:43a6b54f0372 153 return max_rssi;
andriym 78:43a6b54f0372 154 }
andriym 78:43a6b54f0372 155 inline bool operator==(const char rhs[]){ return memcmp(name, rhs, NAME_LEN)==0; }
andriym 78:43a6b54f0372 156 inline bool operator==(const Player& rhs){ return *this==rhs.name; }
andriym 78:43a6b54f0372 157 //inline bool operator!=(const char rhs[]){ return !(*this == rhs); }
andriym 78:43a6b54f0372 158 private:
andriym 78:43a6b54f0372 159 list<Contact> contacts;
andriym 78:43a6b54f0372 160 };
andriym 78:43a6b54f0372 161
andriym 78:43a6b54f0372 162 class Players {
andriym 78:43a6b54f0372 163 public:
andriym 78:43a6b54f0372 164 list<Player> players;
andriym 78:43a6b54f0372 165
andriym 78:43a6b54f0372 166 void update(const char name[], int8_t team, int16_t rssi, uint32_t time_ms=NULL) {
andriym 78:43a6b54f0372 167 list<Player>::iterator it;
andriym 78:43a6b54f0372 168 for (it=players.begin(); it != players.end(); ++it) {
andriym 78:43a6b54f0372 169 if(*it==name) break;
andriym 78:43a6b54f0372 170 }
andriym 78:43a6b54f0372 171 if(it!=players.end()) {
andriym 78:43a6b54f0372 172 it->update(team, rssi, time_ms);
andriym 78:43a6b54f0372 173 } else {
andriym 78:43a6b54f0372 174 Player p(name);
andriym 78:43a6b54f0372 175 p.update(team, rssi, time_ms);
andriym 78:43a6b54f0372 176 players.push_front(p);
andriym 78:43a6b54f0372 177 }
andriym 78:43a6b54f0372 178 }
andriym 78:43a6b54f0372 179
andriym 81:3cd7de5d01ef 180 void showAll(int8_t team, uint8_t level, uint8_t volume) {
andriym 79:9db29f41dc9d 181 // Output the current state to the user:
andriym 79:9db29f41dc9d 182 // - show the current information table and/or
andriym 79:9db29f41dc9d 183 // - beep if the user is too close to another one
andriym 79:9db29f41dc9d 184 int i=0, nContacts, signal, maxTeamSignal = -128;
andriym 78:43a6b54f0372 185 list<Player>::iterator it;
andriym 95:3cc3ae2e5e7f 186 //out.clear();
andriym 78:43a6b54f0372 187 for (it=players.begin(); it != players.end(); ++it) {
andriym 79:9db29f41dc9d 188 signal = it->get_distance(nContacts);
andriym 79:9db29f41dc9d 189 if(signal>-128) {
andriym 95:3cc3ae2e5e7f 190 /*
andriym 78:43a6b54f0372 191 out.printf("%d ", ++i);
andriym 78:43a6b54f0372 192 out.printf((team==it->team) ? "+" : "-"); // teammate or opponent?
andriym 78:43a6b54f0372 193 out.printf("%s ", it->name);
andriym 79:9db29f41dc9d 194 out.printf("%d/%d", -signal, nContacts);
andriym 79:9db29f41dc9d 195 out.printf((-signal<SPACE[level]) ? "!" : " ");
andriym 79:9db29f41dc9d 196 out.printf("\r\n");
andriym 95:3cc3ae2e5e7f 197 */
andriym 79:9db29f41dc9d 198 }
andriym 79:9db29f41dc9d 199 if(team==it->team && signal>maxTeamSignal) {
andriym 79:9db29f41dc9d 200 maxTeamSignal = signal;
andriym 78:43a6b54f0372 201 }
andriym 78:43a6b54f0372 202 }
andriym 79:9db29f41dc9d 203 //if(!i) {
andriym 79:9db29f41dc9d 204 // out.printf("Nobody around\r\n");
andriym 81:3cd7de5d01ef 205 // beep(NOTE_A5,0.5,volume);
andriym 79:9db29f41dc9d 206 //}
andriym 79:9db29f41dc9d 207 if(-maxTeamSignal<SPACE[level]) {
andriym 81:3cd7de5d01ef 208 beep(NOTE_A4, 0.33, volume);
andriym 78:43a6b54f0372 209 }
andriym 78:43a6b54f0372 210 }
andriym 78:43a6b54f0372 211 };
andriym 78:43a6b54f0372 212
andriym 78:43a6b54f0372 213 /////////////////////////////////// MAIN CODE ///////////////////////////////////
andriym 78:43a6b54f0372 214
elmbed 76:6638d83939d5 215 int main()
andriym 78:43a6b54f0372 216 {
elmbed 76:6638d83939d5 217 char tx_buff[100] = {0};
elmbed 76:6638d83939d5 218 char rx_buff[100] = {0};
andriym 78:43a6b54f0372 219 char rand_name[NAME_LEN+1] = {0};
andriym 78:43a6b54f0372 220 char other_name[NAME_LEN+1] = {0};
andriym 79:9db29f41dc9d 221 int8_t myTeam = 1, otherTeam;
andriym 87:a9870d513fcf 222 uint8_t level = 1, volume = 1; // SPACE10, VOL_LOW
andriym 89:425369a595c4 223 int bTeamNew, bTeamOld, bSpaceOld, bSpaceNew, bVMNew, bVLNew, bVMOld, bVLOld;
elmbed 76:6638d83939d5 224
andriym 94:831a7fc2d69a 225 // Blink all the LEDs at startup
andriym 94:831a7fc2d69a 226 spaceLEDs(0); wait(0.2); spaceLEDs(1); wait(0.2); spaceLEDs(2); wait(0.2); spaceLEDs(3); wait(0.2); ledSpace20 = 0;
andriym 94:831a7fc2d69a 227 #ifdef TEST_LED_SOUND
andriym 94:831a7fc2d69a 228 // Test LEDs and sound simultaneously to save time
andriym 94:831a7fc2d69a 229 buzzMed = MED_OFF; buzzHigh = HIGH_OFF;
andriym 94:831a7fc2d69a 230 ledBuzzer = 1; buzzer=0; wait(0.2); buzzer=1; ledBuzzer = 0;
andriym 94:831a7fc2d69a 231 buzzMed = MED_ON;
andriym 94:831a7fc2d69a 232 ledTeamA = 1; buzzer=0; wait(0.2); buzzer=1; ledTeamA = 0;
andriym 94:831a7fc2d69a 233 buzzMed = MED_OFF; buzzHigh = HIGH_ON;
andriym 94:831a7fc2d69a 234 ledTeamB = 1; buzzer=0; wait(0.2); buzzer=1; ledTeamB = 0;
andriym 94:831a7fc2d69a 235 buzzHigh = HIGH_OFF;
andriym 94:831a7fc2d69a 236 #else
andriym 94:831a7fc2d69a 237 ledBuzzer = 1; wait(0.2); ledBuzzer = 0;
andriym 94:831a7fc2d69a 238 ledTeamA = 1; wait(0.2); ledTeamA = 0;
andriym 94:831a7fc2d69a 239 ledTeamB = 1; wait(0.2); ledTeamB = 0;
andriym 89:425369a595c4 240
andriym 94:831a7fc2d69a 241 // Beep all the levels on startup
andriym 94:831a7fc2d69a 242 beep(NOTE_A5, 0.2, 1);
andriym 94:831a7fc2d69a 243 beep(NOTE_A5, 0.2, 2);
andriym 94:831a7fc2d69a 244 beep(NOTE_A5, 0.2, 3);
andriym 94:831a7fc2d69a 245 #endif
andriym 94:831a7fc2d69a 246
andriym 94:831a7fc2d69a 247 // ...and go to a informative LEDs
andriym 94:831a7fc2d69a 248 spaceLEDs(level);
andriym 81:3cd7de5d01ef 249 ledBuzzer = volume ? 1 : 0;
andriym 94:831a7fc2d69a 250 if(myTeam & 1) ledTeamA = 1;
andriym 94:831a7fc2d69a 251 else ledTeamB = 1;
andriym 89:425369a595c4 252
andriym 89:425369a595c4 253 // Buttons initialization
andriym 79:9db29f41dc9d 254 buttonSpace.mode(PullDown);
andriym 81:3cd7de5d01ef 255 buttonVolMore.mode(PullDown);
andriym 81:3cd7de5d01ef 256 buttonVolLess.mode(PullDown);
andriym 79:9db29f41dc9d 257 #ifdef NORDIC
andriym 79:9db29f41dc9d 258 buttonTeam.mode(PullDown);
andriym 89:425369a595c4 259 bTeamOld = 0;
andriym 79:9db29f41dc9d 260 #else
andriym 79:9db29f41dc9d 261 buttonTeam.mode(PullUp);
andriym 89:425369a595c4 262 bTeamOld = 1;
andriym 79:9db29f41dc9d 263 #endif
andriym 89:425369a595c4 264 bSpaceOld = 0;
andriym 89:425369a595c4 265 bVMOld = 0;
andriym 89:425369a595c4 266 bVLOld = 0;
andriym 97:2894fbc2d4f8 267
andriym 89:425369a595c4 268 // Pick node number
andriym 78:43a6b54f0372 269 char this_node = int(ain.read()*255+17)*int(ain.read()*255+11); // random node value
andriym 95:3cc3ae2e5e7f 270 //out.printf("Node: %d\r\n", this_node);
andriym 78:43a6b54f0372 271
andriym 89:425369a595c4 272 // Pick node name
andriym 78:43a6b54f0372 273 generate_name(rand_name, sizeof(rand_name));
andriym 95:3cc3ae2e5e7f 274 /*
andriym 78:43a6b54f0372 275 out.printf("Name: %s\r\n", rand_name);
andriym 78:43a6b54f0372 276 out.sleep(2.0);
andriym 95:3cc3ae2e5e7f 277 */
andriym 78:43a6b54f0372 278
andriym 98:9241041ec253 279 //tmr.start();
andriym 78:43a6b54f0372 280
andriym 78:43a6b54f0372 281 Players players;
andriym 78:43a6b54f0372 282
andriym 98:9241041ec253 283 uint32_t last_send = 0; //tmr.read_ms();
andriym 98:9241041ec253 284 uint32_t last_shown = 0; // tmr.read_ms();
andriym 78:43a6b54f0372 285 //uint32_t min_wait = SEND_RATE_MS - 0.5*SEND_RATE_MS*SEND_DESYNC;
andriym 78:43a6b54f0372 286 //uint32_t send_wait = min_wait;
AntonLS 49:626e84ce5e52 287
elmbed 76:6638d83939d5 288 while (true)
AntonLS 19:afcbb425b3cf 289 {
andriym 79:9db29f41dc9d 290 // Read team button
andriym 79:9db29f41dc9d 291 bTeamNew = buttonTeam;
andriym 79:9db29f41dc9d 292 if(bTeamNew==PRESSED && bTeamOld==RELEASED) {
andriym 79:9db29f41dc9d 293 myTeam = (myTeam==1) ? 2 : 1;
andriym 79:9db29f41dc9d 294 ledTeamA = myTeam & 1;
andriym 79:9db29f41dc9d 295 ledTeamB = ~myTeam & 1;
andriym 95:3cc3ae2e5e7f 296 /*
andriym 78:43a6b54f0372 297 out.clear();
andriym 79:9db29f41dc9d 298 out.printf("New team: %d\r\n", myTeam);
andriym 78:43a6b54f0372 299 out.sleep(2);
andriym 95:3cc3ae2e5e7f 300 */
andriym 78:43a6b54f0372 301 }
andriym 79:9db29f41dc9d 302 bTeamOld = bTeamNew;
andriym 79:9db29f41dc9d 303
andriym 79:9db29f41dc9d 304 // Read space button
andriym 79:9db29f41dc9d 305 bSpaceNew = buttonSpace;
andriym 79:9db29f41dc9d 306 if(bSpaceNew && !bSpaceOld) {
andriym 79:9db29f41dc9d 307 level = (level+1) & 0b11; // four states
andriym 85:4692a1790cfa 308 spaceLEDs(level);
andriym 95:3cc3ae2e5e7f 309 /*
andriym 79:9db29f41dc9d 310 out.clear();
andriym 79:9db29f41dc9d 311 out.printf("New level: %d\r\n", level);
andriym 79:9db29f41dc9d 312 out.sleep(2);
andriym 95:3cc3ae2e5e7f 313 */
andriym 79:9db29f41dc9d 314 }
andriym 79:9db29f41dc9d 315 bSpaceOld = bSpaceNew;
andriym 81:3cd7de5d01ef 316
andriym 81:3cd7de5d01ef 317 // Read volume buttons
andriym 82:1e552cc1a615 318 bVMNew = buttonVolMore.read();
andriym 82:1e552cc1a615 319 bVLNew = buttonVolLess.read();
andriym 81:3cd7de5d01ef 320 if(bVMNew && !bVMOld) {
andriym 81:3cd7de5d01ef 321 volume++;
andriym 81:3cd7de5d01ef 322 if(volume>3) volume=3;
andriym 81:3cd7de5d01ef 323 ledBuzzer = 1;
andriym 95:3cc3ae2e5e7f 324 /*
andriym 81:3cd7de5d01ef 325 out.clear();
andriym 81:3cd7de5d01ef 326 out.printf("New volume: %d\r\n", volume);
andriym 81:3cd7de5d01ef 327 out.sleep(2);
andriym 95:3cc3ae2e5e7f 328 */
andriym 81:3cd7de5d01ef 329 }
andriym 81:3cd7de5d01ef 330 if(bVLNew && !bVLOld) {
andriym 81:3cd7de5d01ef 331 if(volume>0) volume--;
andriym 81:3cd7de5d01ef 332 if(!volume) ledBuzzer = 0;
andriym 95:3cc3ae2e5e7f 333 /*
andriym 81:3cd7de5d01ef 334 out.clear();
andriym 81:3cd7de5d01ef 335 out.printf("New volume: %d\r\n", volume);
andriym 81:3cd7de5d01ef 336 out.sleep(2);
andriym 95:3cc3ae2e5e7f 337 */
andriym 81:3cd7de5d01ef 338 }
andriym 81:3cd7de5d01ef 339 bVMOld = bVMNew;
andriym 81:3cd7de5d01ef 340 bVLOld = bVLNew;
andriym 81:3cd7de5d01ef 341
andriym 81:3cd7de5d01ef 342 // Output
andriym 98:9241041ec253 343 unsigned long current_time = 0; //tmr.read_ms();
elmbed 76:6638d83939d5 344
andriym 79:9db29f41dc9d 345 if (current_time - last_shown > CYCLE_MS)
andriym 78:43a6b54f0372 346 {
andriym 81:3cd7de5d01ef 347 players.showAll(myTeam, level, volume);
andriym 78:43a6b54f0372 348 last_shown = current_time;
andriym 78:43a6b54f0372 349 }
andriym 78:43a6b54f0372 350
AntonLS 0:28ca4562fe1a 351 }
elmbed 76:6638d83939d5 352 }