Kevin Maddox
/
kevin_maddox_Lab1Part3
Part 3
main.cpp
- Committer:
- kevinmark13
- Date:
- 2014-12-03
- Revision:
- 0:0d434d3bb5cf
File content as of revision 0:0d434d3bb5cf:
/************************************************************************************************************************************************ CREATED BY: KEVIN MADDOX DATE: 2 DEC 2014 SUMMARY: 1. In this part of the Lab 1 you will be using 8 external LEDs and a 2-way switch. Please use external LEDs, not the LEDs on the mbed board. When the switch is in one position, all the LEDs will blink simultaneously and when the switch is in the other position, the 8 LEDs will blink once in turn (in the like manner as the 4 LEDs in part II of Lab 1) 2. Design the hardware connection of your LEDs to mbed. Build your circuit and include all the required information about your hardware design in your lab report. ***************************************************************************************************************************************************/ #include "mbed.h" //calling the mbed.h library // creating the digital out objects for each pin out DigitalOut myLed01(p5); DigitalOut myLed02(p10); DigitalOut myLed03(p15); DigitalOut myLed04(p20); DigitalOut myLed05(p21); DigitalOut myLed06(p23); DigitalOut myLed07(p26); DigitalOut myLed08(p29); DigitalIn switchinput(p30); int main() { char i = 0; //init i to zero while (1){ //endless while lopp myLed01 = 0; myLed02 = 0; myLed03 = 0; myLed04 = 0; myLed05 = 0; myLed06 = 0; myLed07 = 0; myLed08 = 0; if ( switchinput == 1){ for (i = 0; i < 10; i++) { //start conditional loop led 1 myLed01 = 1; wait(0.2); myLed01 = 0; wait(0.2); i++; } for (i = 0; i < 10; i++) {//start conditional loop led 2 myLed02 = 1; wait(0.2); myLed02 = 0; wait(0.2); i++; } for (i = 0; i < 10; i++) { //start conditional loop led 3 myLed03 = 1; wait(0.2); myLed03 = 0; wait(0.2); i++; } for (i = 0; i < 10; i++) { //start conditional loop led 4 myLed04 = 1; wait(0.2); myLed04 = 0; wait(0.2); i++; } for (i = 0; i < 10; i++) { //start conditional loop led 3 myLed05 = 1; wait(0.2); myLed05 = 0; wait(0.2); i++; } for (i = 0; i < 10; i++) { //start conditional loop led 3 myLed06 = 1; wait(0.2); myLed06 = 0; wait(0.2); i++; } for (i = 0; i < 10; i++) { //start conditional loop led 3 myLed07 = 1; wait(0.2); myLed07 = 0; wait(0.2); i++; } for (i = 0; i < 10; i++) { //start conditional loop led 3 myLed08 = 1; wait(0.2); myLed08 = 0; wait(0.2); i++; } } else{ myLed01 = 1; wait(0.2); myLed02 = 1; wait(0.2); myLed03 = 1; wait(0.2); myLed04 = 1; wait(0.2); myLed05 = 1; wait(0.2); myLed06 = 1; wait(0.2); myLed07 = 1; wait(0.2); myLed08 = 1; wait(0.2); } //end else } // closing for endless while } // closing for program