Binary Switch
Dependents: MutiplexedDisplaysSocketServer mltiplexed_7_segment_displays_over_ethernet mltiplexed_7_segmt_displays_ethernet Multi_7_Seg
Revision 0:fc59b57d2477, committed 2018-08-14
- Comitter:
- shivanandgowdakr
- Date:
- Tue Aug 14 12:24:26 2018 +0000
- Child:
- 1:4d49fd0d1451
- Commit message:
- Binary Dip Switch
Changed in this revision
| Binary_Switch.cpp | Show annotated file Show diff for this revision Revisions of this file |
| Binary_Switch.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Binary_Switch.cpp Tue Aug 14 12:24:26 2018 +0000
@@ -0,0 +1,28 @@
+
+#include "Binary_Switch.h"
+#include "mbed.h"
+
+BinarySwitch::BinarySwitch(PinName B0, PinName B1, PinName B2, PinName B3, PinName B4, PinName B5,PinName B6, PinName B7) :
+s0(B0), s1(B1), s2(B2), s3(B3),s4(B4),s5(B5),s6(B6),s7(B7)
+{
+ printf("Switches Initialised \r\n");
+}
+
+int BinarySwitch::Read_Switch_State(void)
+{
+ int bit0,bit1,bit2,bit3,bit4,bit5,bit6,bit7;
+ int result;
+
+ if(s0==0) bit0=1; else bit0=0;
+ if(s1==0) bit1=1; else bit1=0;
+ if(s2==0) bit2=1; else bit2=0;
+ if(s3==0) bit3=1; else bit3=0;
+ if(s4==0) bit4=1; else bit4=0;
+ if(s5==0) bit5=1; else bit5=0;
+ if(s6==0) bit6=1; else bit6=0;
+ if(s7==0) bit7=1; else bit7=0;
+
+ result =bit7*128+bit6*64+ bit5*32+ bit4*16+ bit3*8+bit2*4+bit1*2+bit0*1;
+ return result;
+
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Binary_Switch.h Tue Aug 14 12:24:26 2018 +0000
@@ -0,0 +1,30 @@
+
+
+#ifndef Binary_Switch_H
+#define Binary_Switch_H
+
+#include "mbed.h"
+
+class BinarySwitch {
+ public:
+
+BinarySwitch(PinName B0,PinName B1,PinName B2,PinName B3, PinName B4,PinName B5,PinName B6,PinName B7);
+
+
+int Read_Switch_State(void);
+
+
+
+private:
+
+DigitalIn s0;
+DigitalIn s1;
+DigitalIn s2;
+DigitalIn s3;
+DigitalIn s4;
+DigitalIn s5;
+DigitalIn s6;
+DigitalIn s7;
+};
+
+#endif
\ No newline at end of file