Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of football_project by
Diff: main.cpp
- Revision:
- 51:fabe54861f1b
- Parent:
- 49:626e84ce5e52
- Child:
- 54:2878d62714d6
--- a/main.cpp Tue Jan 12 21:08:31 2016 +0000
+++ b/main.cpp Wed Jan 13 18:58:11 2016 +0000
@@ -259,7 +259,7 @@
if( wasCharging )
{
pct = 102; // Show 102% at charger unplug.
- tickTock = /* 25 */ 50; // Cause another normal update in 5s (10 half s).
+ tickTock = 50; // Cause another normal update in 5s (60 -50 = 10 half s).
} else
{
@@ -571,28 +571,37 @@
void periodicCallback( void )
{
- static int callCnt;
- do
+ static unsigned long prevMillis = millis() +125;
+ static int callCnt = 0;
+
+ unsigned long elapsedMillis = millis() -prevMillis;
+
+ if( elapsedMillis >= 125 )
{
-// if( is_master && ((callCnt % 3) == 0) ) writeToPhone( "Rnd: %u\r\n", rnd() );
-
- if( (callCnt % 4) != 0 ) break;
+ do
+ {
+ prevMillis = millis();
+
+// if( is_master && ((callCnt % 3) == 0) ) writeToPhone( "Rnd: %x\r\n", rndHW() );
+
+ if( (callCnt % 4) != 0 ) break;
#if BLENANO
- led0 = !led0;
+ led0 = !led0;
#endif
- led1 = !led1;
- led2 = !led2;
-// rts = !rts;
+ led1 = !led1;
+ led2 = !led2;
+// rts = !rts;
- // Check battery level every 30s.
- if( 0 == (tickTock % /* 30 */ 60 ) ) updateBatt( getBattLevel() );
+ // Check battery level every 30s.
+ if( 0 == (tickTock % 60 ) ) updateBatt( getBattLevel() );
+
+ tickTock++;
- tickTock++;
+ } while( false );
- } while( false );
-
- callCnt++;
+ callCnt++;
+ }
}
/*
@@ -611,7 +620,7 @@
int main( void )
{
Ticker ticker;
- ticker.attach( periodicCallback, 0.125 /** 0.2 **/ /** 0.5 **/ /* 1 */ );
+////// ticker.attach( periodicCallback, 0.125 /** 0.2 **/ /** 0.5 **/ /* 1 */ );
/*
// Thread thread( led_thread );
@@ -710,11 +719,20 @@
int mac_addr = ((int)macAddr[0]);
mac_addr |= ((int)macAddr[1] << 8);
+
+ unsigned long lastMillis = millis();
+ unsigned long currMillis = lastMillis +25;
// Main Loop
while( true ) // for( uint32_t loop=1; ;loop++ )
{
- ble.waitForEvent();
+////// ble.waitForEvent();
+
+ currMillis = millis();
+ if( currMillis -lastMillis < 25 ) continue;
+ lastMillis = currMillis;
+
+ periodicCallback();
/**/ toPhoneChk(); // Write any pending data to phone.
