The following information is for the EMANT300, EMANT380
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.
Open the Visual Basic solution VB_2010_Solution.sln.
Set the ReadSwitch project as the startup project.
View the project code by opening the project's Module1.vb
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")
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.
Press and hold the switch to turn the Green LED on. Release to turn the Green LED off.
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.
Dim swstate As Boolean
Boolean data types have 2 states, true or false. You assign a value as follows
swstate = True
swstate = DAQ.ReadDigitalBit(3)
The ReadDigitalBit method returns a boolean value reflecting the switch status (true/false)