Pablo's TEAM LAB2 / Mbed 2 deprecated LAB2

Dependencies:   mbed

Committer:
m210198
Date:
Wed Sep 26 18:45:40 2018 +0000
Revision:
1:1fb5ff2554ca
Parent:
0:db1b39babf83
Part A

Who changed what in which revision?

UserRevisionLine numberNew contents of line
m210198 0:db1b39babf83 1 #include "mbed.h"
m210198 1:1fb5ff2554ca 2 #include <stdio.h>
m210198 1:1fb5ff2554ca 3 //Program A LAB2
m210198 1:1fb5ff2554ca 4 //This program turns the led lights of a protobaord on and off in a specific sequence
m210198 1:1fb5ff2554ca 5 //Written by 3/C ASHLEY and 3/C LOZA with help from 3/C Hendricks
m210198 1:1fb5ff2554ca 6 //Modified:
m210198 1:1fb5ff2554ca 7 // 9/25/18 3/C ASHLEY debugged
m210198 1:1fb5ff2554ca 8
m210198 1:1fb5ff2554ca 9
m210198 1:1fb5ff2554ca 10
m210198 0:db1b39babf83 11 int main() {
m210198 1:1fb5ff2554ca 12 DigitalOut tony[5]={p26,p27,p28,p29,p30};// pins for all the leds on the Protobaord
m210198 1:1fb5ff2554ca 13 tony[0]=0;//These next lines of code start the intial conditions of all leds off but the third
m210198 1:1fb5ff2554ca 14 tony[1]=0;
m210198 1:1fb5ff2554ca 15 tony[2]=1;
m210198 1:1fb5ff2554ca 16 tony[3]=0;
m210198 1:1fb5ff2554ca 17 tony[4]=0;
m210198 1:1fb5ff2554ca 18 int x, Sw1, Sw2; // varibales to store switches
m210198 1:1fb5ff2554ca 19 Digital sw1(p19); // location of switches on mbed pin
m210198 1:1fb5ff2554ca 20 Digital sw2(p20);// location of switches on mbed pin
m210198 1:1fb5ff2554ca 21
m210198 0:db1b39babf83 22 while(1) {
m210198 1:1fb5ff2554ca 23 Sw1=sw1;//designates varibales as the switches
m210198 1:1fb5ff2554ca 24 Sw2=sw2;//designates varibales as the switches
m210198 1:1fb5ff2554ca 25 if((Sw1== 1)&& (Sw2==1)){// if switch 1 and switch 2 are on then light the led three
m210198 1:1fb5ff2554ca 26 tony[0]=0;
m210198 1:1fb5ff2554ca 27 tony[1]=0;
m210198 1:1fb5ff2554ca 28 tony[2]=1;
m210198 1:1fb5ff2554ca 29 tony[3]=0;
m210198 1:1fb5ff2554ca 30 tony[4]=0;
m210198 0:db1b39babf83 31 }
m210198 0:db1b39babf83 32
m210198 1:1fb5ff2554ca 33 else if ((Sw1==1) && (Sw2==0)){//if switch 1 is on and switch 2 are off then
m210198 1:1fb5ff2554ca 34 tony[x]=0;//then cylce through leds turning the lights on in squential order by turning the previous led off and the next led on in the other way
m210198 1:1fb5ff2554ca 35 if(x<4);
m210198 0:db1b39babf83 36 x++;}
m210198 0:db1b39babf83 37 tony[x]=1;
m210198 1:1fb5ff2554ca 38 wait(0.5);// wait before exacting the next set of code
m210198 0:db1b39babf83 39 }
m210198 1:1fb5ff2554ca 40 else if ((Sw1==0) && (Sw2==1)){//if switch 1 is off and switch 2 are on then
m210198 1:1fb5ff2554ca 41 tony[x]=0;//then cylce through leds turning the lights on in squential order by turning the previous led off and the next led on
m210198 1:1fb5ff2554ca 42 if(x>0);
m210198 0:db1b39babf83 43 x--;}
m210198 0:db1b39babf83 44 tony[x]=1;
m210198 1:1fb5ff2554ca 45 wait(0.5);// wait before exacting the next set of code
m210198 0:db1b39babf83 46 }
m210198 0:db1b39babf83 47 }
m210198 0:db1b39babf83 48 }