VB.NET 布尔型变量上升沿与下降沿检测函数封装
时间: 2023-12-09 20:02:38 浏览: 43
以下是 VB.NET 中布尔型变量上升沿与下降沿检测函数的封装:
```
Public Class BooleanEdgeDetector
Private m_previousValue As Boolean
Public Function RisingEdge(ByVal currentValue As Boolean) As Boolean
Dim edgeDetected As Boolean = False
If currentValue AndAlso Not m_previousValue Then
edgeDetected = True
End If
m_previousValue = currentValue
Return edgeDetected
End Function
Public Function FallingEdge(ByVal currentValue As Boolean) As Boolean
Dim edgeDetected As Boolean = False
If Not currentValue AndAlso m_previousValue Then
edgeDetected = True
End If
m_previousValue = currentValue
Return edgeDetected
End Function
End Class
```
使用示例:
```
Dim edgeDetector As New BooleanEdgeDetector()
Dim currentValue As Boolean = False
Dim previousValue As Boolean = False
' Check for rising edge
currentValue = True
If edgeDetector.RisingEdge(currentValue) Then
Console.WriteLine("Rising edge detected")
End If
' Check for falling edge
currentValue = False
If edgeDetector.FallingEdge(currentValue) Then
Console.WriteLine("Falling edge detected")
End If
' Save previous value for next iteration
previousValue = currentValue
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)