SEARCH
TOOLBOX
LANGUAGES
modified on 17 September 2014 at 18:01 ••• 48,162 views

03-03 IfElseSwitch

From Manuals

(Difference between revisions)
Jump to: navigation, search
Line 1: Line 1:
Flashes one of two LEDs, depending on the state of a 2-way switch. The LEDs are connected to D0 and D1 of J9. The switch is connected to D2 of J9. Please see schematic below for further details.
Flashes one of two LEDs, depending on the state of a 2-way switch. The LEDs are connected to D0 and D1 of J9. The switch is connected to D2 of J9. Please see schematic below for further details.
-
  Debian GNU/Linux 5.0 electrum100 ttyS0
+
  /*Program Example 3.3: Flashes one of two LEDs, depending on the state of a 2-way switch
 +
                                                                            */
 +
#include "mbed.h"
 +
DigitalOut redled(D0);
 +
DigitalOut greenled(D1);
 +
DigitalIn  switchinput(D2);
   
   
-
  electrum100 login: root
+
  int main()
-
  Password:
+
  {
-
Last login: Wed Jun 30 09:00:23 UTC 2010 on ttyS0
+
    while(1) {
-
Linux electrum100 2.6.33.5-at91 #1 Tue Jun 29 11:37:56 EST 2010 armv5tejl
+
        if (switchinput==1) {      //test value of switchinput
-
+
            //execute following block if switchinput is 1
-
The programs included with the Debian GNU/Linux system are free software;
+
            greenled = 0;          //green led is off
-
the exact distribution terms for each program are described in the
+
            redled = 1;            // flash red led
-
individual files in /usr/share/doc/*/copyright.
+
            wait(0.2);
-
+
            redled = 0;
-
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
+
            wait(0.2);
-
permitted by applicable law.
+
        }                          //end of if
-
Last was Wed Jun 30 09:10:46 2010 on ttyS0.
+
        else {                      //here if switchinput is 0
-
+
            redled = 0;            //red led is off
-
electrum100:~# passwd root
+
            greenled = 1;          // flash green led
-
Enter new UNIX password:
+
            wait(0.2);
-
Retype new UNIX password:
+
            greenled = 0;
-
passwd: password updated successfully
+
            wait(0.2);
-
+
        }                          //end of else
-
electrum100:~# date 063012222010
+
    }                              //end of while(1)
-
Wed Jun 30 12:22:00 UTC 2010
+
  }
-
+
-
  electrum100:~# hwclock --systohc
+
[[Image:BAM210_IfElse.jpeg|center|]]
[[Image:BAM210_IfElse.jpeg|center|]]

Revision as of 14:33, 14 August 2014

Flashes one of two LEDs, depending on the state of a 2-way switch. The LEDs are connected to D0 and D1 of J9. The switch is connected to D2 of J9. Please see schematic below for further details.

/*Program Example 3.3: Flashes one of two LEDs, depending on the state of a 2-way switch
                                                                            */
#include "mbed.h"
DigitalOut redled(D0);
DigitalOut greenled(D1);
DigitalIn  switchinput(D2);

int main()
{
    while(1) {
        if (switchinput==1) {       //test value of switchinput
            //execute following block if switchinput is 1
            greenled = 0;           //green led is off
            redled = 1;             // flash red led
            wait(0.2);
            redled = 0;
            wait(0.2);
        }                           //end of if
        else {                      //here if switchinput is 0
            redled = 0;             //red led is off
            greenled = 1;           // flash green led
            wait(0.2);
            greenled = 0;
            wait(0.2);
        }                           //end of else
    }                               //end of while(1)
}


BAM210
Schematic for example 03-03