LEDシーリングライトメモリ点灯 LEDHCL-R3

Dependencies:   mbed-dev

Committer:
nameless129
Date:
Mon May 16 17:38:47 2016 +0000
Revision:
1:99bfec2c8ed6
Parent:
0:9bf7a5073dc2
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nameless129 0:9bf7a5073dc2 1 #include "mbed.h"
nameless129 0:9bf7a5073dc2 2
nameless129 0:9bf7a5073dc2 3 #define DEBOUNCEDELAY 500
nameless129 0:9bf7a5073dc2 4
nameless129 0:9bf7a5073dc2 5 // Turn ON/OFF the power of TV
nameless129 0:9bf7a5073dc2 6 int ARRAY_HIGHLOW[] = {
nameless129 0:9bf7a5073dc2 7 2021, 971, 5512, 971, 1522, 473, 525, 473, 524, 473, 524, 473, 524, 474, 523, 474, 524,
nameless129 0:9bf7a5073dc2 8 474, 523, 474, 525, 473, 524, 473, 524, 474, 523, 474, 524, 473, 525, 472, 524, 474,
nameless129 0:9bf7a5073dc2 9 1521, 474, 523, 474, 524, 474, 524, 473, 524, 474, 523, 474, 523, 474, 523, 475, 523,
nameless129 0:9bf7a5073dc2 10 474, 523, 474, 524, 473, 524, 473, 525, 473, 525, 472, 525, 473, 524, 473, 524, 473, 1522,
nameless129 0:9bf7a5073dc2 11 474, 1521, 472, 525, 474, 1521, 474, 1521, 474, 523, 473, 1522, 473, 1522, 473, 525, 8950,
nameless129 0:9bf7a5073dc2 12 5512, 970, 1523, 473, 524, 474, 523, 473, 526, 472, 525, 472, 525, 473, 525, 472, 525, 473,
nameless129 0:9bf7a5073dc2 13 524, 473, 525, 472, 525, 472, 526, 472, 524, 474, 525, 472, 524, 473, 1523, 472, 525, 472,
nameless129 0:9bf7a5073dc2 14 525, 473, 525, 472, 525, 472, 525, 473, 525, 472, 525, 472, 526, 472, 525, 472, 525, 473, 524,
nameless129 0:9bf7a5073dc2 15 472, 526, 473, 524, 472, 526, 472, 525, 472, 525, 473, 1521, 474, 1522, 473, 524, 473, 1522,
nameless129 0:9bf7a5073dc2 16 473, 1521, 473, 525, 473, 1522, 473, 1521, 473, 525, 8950, 5512, 971, 1522, 473, 524, 473, 525,
nameless129 0:9bf7a5073dc2 17 473, 525, 472, 524, 473, 525, 473, 524, 473, 525, 473, 524, 473, 524, 473, 526, 471, 525, 473,
nameless129 0:9bf7a5073dc2 18 525, 472, 526, 471, 526, 472, 1523, 472, 525, 472, 526, 471, 526, 471, 526, 472, 526, 471, 527,
nameless129 0:9bf7a5073dc2 19 470, 527, 471, 526, 471, 527, 470, 527, 470, 527, 470, 528, 470, 527, 470, 528, 469, 528, 469,
nameless129 0:9bf7a5073dc2 20 529, 469, 1525, 469, 1526, 469, 529, 468, 1527, 467, 1528, 467, 530, 467, 1528, 467, 1528, 467, 531,};
nameless129 0:9bf7a5073dc2 21
nameless129 0:9bf7a5073dc2 22 DigitalIn g_digitalinButton(P0_17);
nameless129 0:9bf7a5073dc2 23 PwmOut g_pwmoutLed(P0_13);
nameless129 0:9bf7a5073dc2 24
nameless129 0:9bf7a5073dc2 25 void sendSignal()
nameless129 0:9bf7a5073dc2 26 {
nameless129 0:9bf7a5073dc2 27 g_pwmoutLed.period_us( 26 ); // 38KHz => 1/38000[s] = 26.315 * 10 ^ -6 [s] = 26.315 [us]
nameless129 0:9bf7a5073dc2 28
nameless129 0:9bf7a5073dc2 29 int iCountHighLow = sizeof( ARRAY_HIGHLOW ) / sizeof( ARRAY_HIGHLOW[0] );
nameless129 0:9bf7a5073dc2 30 for( int iIndexHighLow = 0; iIndexHighLow < iCountHighLow; iIndexHighLow++ )
nameless129 0:9bf7a5073dc2 31 {
nameless129 0:9bf7a5073dc2 32 g_pwmoutLed.write( 0.5 * (1 - (iIndexHighLow % 2)) ); // iIndexHighLow : even number -> 0.5, uneven number -> 0
nameless129 0:9bf7a5073dc2 33 wait_us( ARRAY_HIGHLOW[iIndexHighLow] );
nameless129 0:9bf7a5073dc2 34 }
nameless129 0:9bf7a5073dc2 35 g_pwmoutLed.write(0);
nameless129 0:9bf7a5073dc2 36 }
nameless129 0:9bf7a5073dc2 37
nameless129 0:9bf7a5073dc2 38 int main()
nameless129 0:9bf7a5073dc2 39 {
nameless129 0:9bf7a5073dc2 40 int iButtonState_prev = 0;
nameless129 0:9bf7a5073dc2 41
nameless129 0:9bf7a5073dc2 42 while(1)
nameless129 0:9bf7a5073dc2 43 {
nameless129 0:9bf7a5073dc2 44 int iButtonState = g_digitalinButton;
nameless129 0:9bf7a5073dc2 45
nameless129 0:9bf7a5073dc2 46 if( 0 == iButtonState_prev && 1 == iButtonState )
nameless129 0:9bf7a5073dc2 47 {
nameless129 0:9bf7a5073dc2 48 sendSignal();
nameless129 0:9bf7a5073dc2 49 wait(1);
nameless129 0:9bf7a5073dc2 50 }
nameless129 0:9bf7a5073dc2 51
nameless129 0:9bf7a5073dc2 52 iButtonState_prev = iButtonState;
nameless129 0:9bf7a5073dc2 53 }
nameless129 0:9bf7a5073dc2 54 }