我想摆脱Arduino项目中的循环。目前,我正在为数字手表编程,但一切正常,但是我想通过单击按钮来添加选项菜单,但是单击它之后,即使代码中有东西也不会弹出。看一看。我不知道如何写得更好。如果您有什么想法,请重写代码的某些部分并解释为什么这样做。谢谢。
请不要介意s = s + 1,我想要这样。
Sub Test()
Dim list() As Variant
Dim n As Long, i As Long, j As Long, endrow As Long, colnum As Long
ReDim list(0 To 0)
j = 0
colnum = 2 'Column B in this case
endrow = Cells(Rows.Count, colnum).End(xlUp).Row
For n = 1 To endrow
If IsError(Application.Match(Cells(n, colnum).Value, list, 0)) Then
ReDim Preserve list(0 To j)
list(j) = Cells(n, colnum).Value
j = j + 1
End If
Next n
For i = 0 To UBound(list)
Debug.Print list(i)
Next i
End Sub
答案 0 :(得分:0)
为此,您必须使用中断,请注意,您必须将按钮连接到中断引脚(并非每个引脚都是中断引脚),您可以在Google上搜索“'your_card_name'的中断引脚是什么”,代码必须更改,您可以按照以下步骤操作:
在设置功能中替换:
4.15.0-43-generic x86_64 GNU/Linux
作者:
pinMode(left, INPUT);
在setup(){...}之前添加此功能
attachInterrupt(digitalPinToInterrupt(left), switchMode, RISING);
并从代码中删除此部分:(loop()函数中的那一部分)
int lastPressTime=millis();
void switchMode(){ // function called when the button is pressed
if((millis()-lastPressTime)>60){ // for debouncing
clockShown = false;
menuShown = true;
lcd.clear();
lastPressTime=millis();
}
}