Matthew Sims
/
Lab1A
Lab 1 Program A
main.cpp@0:0db95f8cd85f, 2015-09-29 (annotated)
- Committer:
- mattsims12
- Date:
- Tue Sep 29 00:52:41 2015 +0000
- Revision:
- 0:0db95f8cd85f
Version 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mattsims12 | 0:0db95f8cd85f | 1 | /*Lab 1 Program A |
mattsims12 | 0:0db95f8cd85f | 2 | Makes led's shift based on which input switches are on. |
mattsims12 | 0:0db95f8cd85f | 3 | Matthew Sims |
mattsims12 | 0:0db95f8cd85f | 4 | Section 1001 |
mattsims12 | 0:0db95f8cd85f | 5 | */ |
mattsims12 | 0:0db95f8cd85f | 6 | |
mattsims12 | 0:0db95f8cd85f | 7 | #include "mbed.h" |
mattsims12 | 0:0db95f8cd85f | 8 | |
mattsims12 | 0:0db95f8cd85f | 9 | DigitalOut out[]= {p30,p29,p28,p27,p26}; //sets 5 output pins connected to circut board led's |
mattsims12 | 0:0db95f8cd85f | 10 | DigitalIn in[]={p16,p17}; //sets 2 inputs to the pins the switches are connected to |
mattsims12 | 0:0db95f8cd85f | 11 | |
mattsims12 | 0:0db95f8cd85f | 12 | int main() |
mattsims12 | 0:0db95f8cd85f | 13 | { |
mattsims12 | 0:0db95f8cd85f | 14 | out[2]=1; //Initial postion led 2 lit |
mattsims12 | 0:0db95f8cd85f | 15 | int lit=2; //Records which led is lit |
mattsims12 | 0:0db95f8cd85f | 16 | |
mattsims12 | 0:0db95f8cd85f | 17 | /*Infinite loop that checks which inputts are on every cycle and changes led's bassed on inputs*/ |
mattsims12 | 0:0db95f8cd85f | 18 | |
mattsims12 | 0:0db95f8cd85f | 19 | while(1) { |
mattsims12 | 0:0db95f8cd85f | 20 | if(in[0]==1 && in[1]==1) { //Checks first instance |
mattsims12 | 0:0db95f8cd85f | 21 | out[lit]=0; //Turns off currently on led |
mattsims12 | 0:0db95f8cd85f | 22 | lit=2; //Picks middle led to be lit |
mattsims12 | 0:0db95f8cd85f | 23 | out[lit]=1; //Turns on the selected led |
mattsims12 | 0:0db95f8cd85f | 24 | wait(.5); //Turns on the selected led |
mattsims12 | 0:0db95f8cd85f | 25 | } else if(in[0]==1 && in[1]==0) { //Checks second instance |
mattsims12 | 0:0db95f8cd85f | 26 | if(lit<4) { //Makes sure it stops at end of array |
mattsims12 | 0:0db95f8cd85f | 27 | out[lit]=0; //Turns previously on led off |
mattsims12 | 0:0db95f8cd85f | 28 | lit++; //Picks led to right |
mattsims12 | 0:0db95f8cd85f | 29 | out[lit]=1; //Turns on led |
mattsims12 | 0:0db95f8cd85f | 30 | wait(.5); //Waits to start loop again |
mattsims12 | 0:0db95f8cd85f | 31 | } |
mattsims12 | 0:0db95f8cd85f | 32 | } else if(in[1]==1 && in[0]==0) { //Same as last loop, but moves led's to left instead of right. |
mattsims12 | 0:0db95f8cd85f | 33 | if(lit>0) { |
mattsims12 | 0:0db95f8cd85f | 34 | out[lit]=0; |
mattsims12 | 0:0db95f8cd85f | 35 | lit--; |
mattsims12 | 0:0db95f8cd85f | 36 | out[lit]=1; |
mattsims12 | 0:0db95f8cd85f | 37 | wait(.5); |
mattsims12 | 0:0db95f8cd85f | 38 | } |
mattsims12 | 0:0db95f8cd85f | 39 | } |
mattsims12 | 0:0db95f8cd85f | 40 | } |
mattsims12 | 0:0db95f8cd85f | 41 | } |