switches and lights

Dependencies:   mbed

Committer:
jkangwi
Date:
Wed Oct 15 19:13:59 2014 +0000
Revision:
0:a6003d0979bf
lab 3, switches and lights
;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jkangwi 0:a6003d0979bf 1 #include "mbed.h"
jkangwi 0:a6003d0979bf 2 // Lab 3
jkangwi 0:a6003d0979bf 3 // This program explores the basic capabilites of the digital I/O on the processor
jkangwi 0:a6003d0979bf 4 // Written by: MIDN 3/C N. Weinhardt, MIDN 3/C J. Kangwijaya, 09/22/14
jkangwi 0:a6003d0979bf 5 //Modified:
jkangwi 0:a6003d0979bf 6 // 9/23/14 MIDN 3/C. Weinhardt. Corrected last if else statement.
jkangwi 0:a6003d0979bf 7 BusOut zed(p5, p6, p7, p8, p11); //data bus for LEDs
jkangwi 0:a6003d0979bf 8 DigitalIn sw4(p16); // switch for control of LEDs
jkangwi 0:a6003d0979bf 9 DigitalIn sw5 (p17); // switch for control of LEDs
jkangwi 0:a6003d0979bf 10 int w1; // variable to store switch 4
jkangwi 0:a6003d0979bf 11 int w2; // variable to store switch 5
jkangwi 0:a6003d0979bf 12 main()
jkangwi 0:a6003d0979bf 13 {
jkangwi 0:a6003d0979bf 14 int x; // variable to store binary input
jkangwi 0:a6003d0979bf 15 w1=sw5; // variable to store switch 5
jkangwi 0:a6003d0979bf 16 w2=sw4; // variable to store switch 4
jkangwi 0:a6003d0979bf 17 x=4; // displays 0b0100 on LEDs
jkangwi 0:a6003d0979bf 18 zed=x; // read switch into variable
jkangwi 0:a6003d0979bf 19 while(1) { // infinite while loop
jkangwi 0:a6003d0979bf 20
jkangwi 0:a6003d0979bf 21 if(w1==1 && w2==1) { // if sw5 and sw4 are on
jkangwi 0:a6003d0979bf 22 x=4; // displays 0b0100 on LEDs
jkangwi 0:a6003d0979bf 23 zed=x; // read switch into variable
jkangwi 0:a6003d0979bf 24
jkangwi 0:a6003d0979bf 25 } else if (w1==1 &&w2==0) { // if sw5 is on and sw4 is off
jkangwi 0:a6003d0979bf 26 x=x/2; // x equals the variable divided by 2 to be displayed on the LEDs
jkangwi 0:a6003d0979bf 27 zed=x; // read switch into variable
jkangwi 0:a6003d0979bf 28 wait(0.5); // change the value every 0.5 seconds
jkangwi 0:a6003d0979bf 29 } else if (w1==0 && w2==1) { // if sw5 is off and sw4 is on
jkangwi 0:a6003d0979bf 30 x=x*2; // x equals the variable multiplied by 2 to be displayed on the LEDs
jkangwi 0:a6003d0979bf 31 zed=x; // read switch into variable
jkangwi 0:a6003d0979bf 32 wait(0.5); // change the value every 0.5 seconds
jkangwi 0:a6003d0979bf 33 }
jkangwi 0:a6003d0979bf 34 }
jkangwi 0:a6003d0979bf 35
jkangwi 0:a6003d0979bf 36 }