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

03-03 IfElseSwitch

From Manuals

(Difference between revisions)
Jump to: navigation, search
 
(6 intermediate revisions not shown)
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.
+
This example flashes one of two LEDs, depending on the state of a 2-way switch.  
 +
The signals used for this example are listed below:
 +
{| border="1" cellpadding="5" cellspacing="2" align="center" style="text-align: center;"
 +
|+ align="bottom"|'''Signals Used and Connector Locations for Example 03-03'''
 +
|'''Signal'''
 +
|'''LPC4330 PIN NAME'''
 +
|'''BAM210E'''
 +
|'''BAM210'''
 +
|'''BAM200E'''
 +
|'''BAM200'''
 +
|'''Used for'''
 +
|-
 +
|D0
 +
|P6_5
 +
|J9-1
 +
|J9-1
 +
|S2-5
 +
|S2-5
 +
|Red LED
 +
|-
 +
|D1
 +
|P6_4
 +
|J9-2
 +
|J9-2
 +
|S2-4
 +
|S2-4
 +
|Green LED
 +
|-
 +
|D2
 +
|P1_7
 +
|J9-3
 +
|J9-3
 +
|S3-7
 +
|S3-7
 +
|Push-button
 +
|-
 +
|}
 +
 +
The following schematic can be used to build the circuit with a BAM210E or BAM210.
 +
[[Image:BAM210_03_03_SCH.png|center|alt=BAM210|frame|<div align="center">'''Schematic for example 03-03''']]
 +
 +
<div style="text-align: left;">
  /*Program Example 3.3: Flashes one of two LEDs, depending on the state of a 2-way switch
  /*Program Example 3.3: Flashes one of two LEDs, depending on the state of a 2-way switch
                                                                             */
                                                                             */
Line 29: Line 70:
  }
  }
 +
The following image shows the built circuit on a BAM210E.
[[Image:BAM210_IfElse.jpeg|center|]]
[[Image:BAM210_IfElse.jpeg|center|]]
-
 
-
 
-
[[Image:BAM210_03_03_SCH.png|center|alt=BAM210|frame|<div align="center">'''Schematic for example 03-03''']]
 

Current revision as of 18:01, 17 September 2014

This example flashes one of two LEDs, depending on the state of a 2-way switch.

The signals used for this example are listed below:

Signals Used and Connector Locations for Example 03-03
Signal LPC4330 PIN NAME BAM210E BAM210 BAM200E BAM200 Used for
D0 P6_5 J9-1 J9-1 S2-5 S2-5 Red LED
D1 P6_4 J9-2 J9-2 S2-4 S2-4 Green LED
D2 P1_7 J9-3 J9-3 S3-7 S3-7 Push-button

The following schematic can be used to build the circuit with a BAM210E or BAM210.

BAM210
Schematic for example 03-03
/*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)
}

The following image shows the built circuit on a BAM210E.