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.
Dependencies: mbed
Fork of lab2programa by
Revision 2:b295ac52a79f, committed 2018-09-22
- Comitter:
- corwinstites
- Date:
- Sat Sep 22 23:11:47 2018 +0000
- Parent:
- 1:4ba19383f367
- Child:
- 3:b5310b20de62
- Commit message:
- Part A
Changed in this revision
| lab2programa.cpp | Show annotated file Show diff for this revision Revisions of this file |
| parta.cpp | Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lab2programa.cpp Sat Sep 22 23:11:47 2018 +0000
@@ -0,0 +1,66 @@
+//Part A
+//MIDN 3/C Stites and Maly
+//Modified: 9/20/21
+#include "mbed.h"
+
+DigitalIn sw1(p16); //Assigns pin 16 as switch 1
+DigitalIn sw2(p17); //Assigns pin 17 as switch 2
+DigitalOut lights[5] = {p26,p27,p28,p29,p30}; //Puts five lights in array based on their corresponding pin
+
+int main()
+{
+ lights[0]=0; //Turns on light three and turns off other lights
+ lights[1]=0;
+ lights[2]=1;
+ lights[3]=0;
+ lights[4]=0;
+ wait(3);// Wait three seconds
+
+ int a, b; //Variables to store switch states
+
+ while(1) //Continue to repeat
+ {
+
+ a = sw1.read(); //Read in switch states
+ b = sw2.read();
+
+ if (a == 1 && b == 1) //Check to see if switches 1 and 2 are on
+ {
+ lights[0]=0; //Turns on light three and turns off other lights
+ lights[1]=0;
+ lights[2]=1;
+ lights[3]=0;
+ lights[4]=0;
+ }
+ if (a == 1 && b == 0) //Check to see if switch 1 is on and 2 is off
+ {
+ lights[2]=0; //Turns off light three
+ int i; //Stores assignment of value in array lights
+ for (i=0; i<5; i++) //Starts i at 0 and adds 1 to i while it is less than 5
+ {
+ lights[i]=1; //Turns coresponding light on
+ lights[i-1]=0; //Turns last light off
+ wait(.5); //Wait half a second
+ if (i == 4) //Turn last light in row off
+ {
+ lights[4]=0;
+ }
+ }
+ }
+ if (a == 0 && b == 1) // Check to see if switch 1 is off and 2 is on
+ {
+ lights[0]=0;//Turn off all lights
+ lights[1]=0;
+ lights[2]=0;
+ lights[3]=0;
+ lights[4]=0;
+ int j; //Stores assignment of value in array lights
+ for (j=4; j>-1; j--) //Starts j at 4 and subtracts 1 from i while it is greater than -1
+ {
+ lights[j]=1; //Turns the jth light in the array on
+ wait(.5); //Wait half a second
+ lights[j] = 0; //Turn all lights off
+ }
+ }
+ }
+}
\ No newline at end of file
--- a/parta.cpp Thu Sep 20 19:38:54 2018 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-#include "mbed.h"
-
-DigitalIn sw1(p16);
-DigitalIn sw2(p17);
-DigitalOut lights[5] = {p26,p27,p28,p29,p30};
-
-int main()
-{
- lights[0]=0;
- lights[1]=0;
- lights[2]=1;
- lights[3]=0;
- lights[4]=0;
- wait(3);
-
- int a, b;
- a = sw1.read();
- b = sw2.read();
-
- if (a == 1 && b == 1)
- {
- lights[0]=0;
- lights[1]=0;
- lights[2]=1;
- lights[3]=0;
- lights[4]=0;
- }
- if (a == 1 && b == 0)
- {
- lights[2]=0;
- int i;
- while(1)
- for (i=0; i<5; i++)
- {
- lights[i]=1;
- lights[i-1]=0;
- wait(.5);
- if (i == 4)
- {
- wait(.5);
- lights[4]=0;
- }
- }
-
- }
- if (a == 0 && b == 1)
- {
- int j;
- while(1)
- for (j=4; j>0; j--)
- {
- lights[j]=1;
- lights[j+1]=0;
- wait(.5);
- if (j == 0)
- {
- wait(.5);
- lights[0]=0;
- }
- }
-
- }
-}
\ No newline at end of file
