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.
Diff: main.cpp
- Revision:
- 0:edaa83475c21
- Child:
- 1:b2ed25e02889
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sat Dec 01 13:28:44 2012 +0000
@@ -0,0 +1,55 @@
+#include "mbed.h"
+
+#define DEBOUNCEDELAY 500
+
+// On the power of TV
+short ARRAY_HIGHLOW[] = { 2461, 543, 1290, 514, 692, 507, 1289, 514, 692, 507, 1290, 514, 691, 507, 690, 508, 1289, 516, 717, 481,
+ 690, 508, 689, 508, 692, 25634, 2487, 517, 1289, 516, 688, 510, 1289, 515, 689, 509, 1289, 518, 686, 510,
+ 664, 534, 1288, 516, 691, 507, 690, 509, 689, 508, 690, 25635, 2490, 515, 1289, 515, 691, 508, 1288, 516,
+ 691, 508, 1288, 515, 691, 508, 690, 507, 1291, 513, 693, 507, 689, 506, 692, 509, 689, 25635, 2490, 515,
+ 1288, 516, 692, 506, 1289, 516, 691, 507, 1289, 516, 691, 506, 690, 508, 1291, 514, 691, 507, 690, 508,
+ 690, 509, 689, 25616, 2508, 515, 1290, 515, 690, 508, 1289, 516, 690, 508, 1288, 516, 690, 509, 688, 509,
+ 1289, 515, 689, 509, 690, 508, 690, 508, 690, 25636, 2489, 515, 1290, 517, 688, 508, 1289, 517, 689, 507,
+ 1290, 516, 690, 507, 692, 506, 1289, 515, 691, 507, 692, 507, 690, 506, 692,};
+
+DigitalIn g_dpinButton(p30);
+PwmOut g_pwmout(p21);
+
+void onPress()
+{
+ int iCountOnOff = sizeof( ARRAY_HIGHLOW ) / sizeof( ARRAY_HIGHLOW[0] );
+ for( int iIndexOnOff = 0; iIndexOnOff < iCountOnOff; iIndexOnOff++ )
+ {
+ g_pwmout.write( 0.5 * (1 - (iIndexOnOff % 2)) ); // iIndexOnOff : even number -> 0.5, uneven number -> 0
+ wait_us( ARRAY_HIGHLOW[iIndexOnOff] );
+ }
+}
+
+int main()
+{
+ Timer timer;
+ timer.start();
+ int iMilliSec_prev = timer.read_ms();
+ int iButtonState_prev = 0;
+
+ g_pwmout.period_us( 26 ); // 38KHz => 1/38000[s] = 26.315 * 10 ^ 6 [s] = 26.315 [us]
+
+ while(1)
+ {
+ int iButtonState = g_dpinButton;
+
+ if( 0 == iButtonState_prev
+ && 1 == iButtonState )
+ {
+ int iMilliSec = timer.read_ms();
+ if( DEBOUNCEDELAY < (iMilliSec - iMilliSec_prev) )
+ {
+ onPress();
+ }
+
+ iMilliSec_prev = iMilliSec;
+ }
+
+ iButtonState_prev = iButtonState;
+ }
+}