The following information is for the EMANT300, EMANT380

Exercise 9 – Digital Input

Objective

  • Digital Input

In a car, an alarm light is turned on whenever a door is opened. This is implemented by using a switch to indicate whether is door is opened or closed. The Light Application Adaptor has one switch. We will modify our earlier exercise 7 replacing the light sensor with the switch to turn on and off the LED. We will also practice using the For Loop we learnt in the previous earlier.

  1. Open the Visual Basic solution VB_2010_Solution.sln.

  2. Set the ReadSwitch project as the startup project.

  3. View the project code by opening the project's Module1.vb

  4. If you are using the EMANT380 Bluetooth DAQ, change the parameter to False and COM5 to the COM port you are using, See exercise 1 step 4.

    DAQ.Open(False,"COM5")

  5. Click on Debug-> Start to run the program. The Console Window opens and then closes automatically after 10 seconds when the program ends. Start without Debugging is useful if the console displays some information as you are required to enter a key to close the window.

  6. Press and hold the switch to turn the Green LED on. Release to turn the Green LED off.

Program 9.1 Read Switch

Imports Emant  
Module Module1  
    Sub Main()  
        Dim i As Integer  
        Dim swstate As Boolean  
        Dim DAQ As Emant300 = New Emant300  
        DAQ.Open(True,"COM5")  
        For i = 0 To 9  
            swstate = DAQ.ReadDigitalBit(3)  
            DAQ.WriteDigitalBit(0, swstate)  
            Console.WriteLine(swstate)  
            DAQ.Delay(1000)  
        Next  
        DAQ.Close()  
    End Sub  
End Module

If you are writing this program from scratch, in order to use the Emant300 class, the class library Emant300.dll must be added to the references folder. See exercise 5.

Data Type Boolean

Dim swstate As Boolean

Boolean data types have 2 states, true or false. You assign a value as follows

swstate = True

Read Digital Input

swstate = DAQ.ReadDigitalBit(3)

The ReadDigitalBit method returns a boolean value reflecting the switch status (true/false)

End of Exercise 9