[Arduino c#应用指示灯led挡光板,已对c#编辑]]

问题描述 投票:1回答:1
// Im写一个程序,我要做的一件事就是用按钮点亮arduino上的第一个LED,然后用c#visual studio按钮停止。问题是为什么当我启动程序并按C#应用程序中的按钮时,arduiono led无法关闭?我不在arduino端或视觉工作室的问题所在。我应该怎么做才能改善它。

//这是我的arduino代码

const int BUTTON_SWITCH = 8; const int BUTTON_ALARM = 9; const int POT = A0; const int RED_LED = 4; const int BUZZER =3; int index = 0; double value; int state = 0; unsigned long time_now = 0; int period =1000; void setup() { Serial.begin(9600); pinMode(BUTTON_SWITCH, INPUT_PULLUP); pinMode(BUTTON_ALARM, INPUT_PULLUP); pinMode(RED_LED,OUTPUT); } void loop() { if(digitalRead(BUTTON_SWITCH)==LOW && state == 0){ digitalWrite(RED_LED,HIGH); digitalWrite(BUZZER,HIGH); } float reset; reset = Serial.parseFloat(); if(reset == 0){ digitalWrite(RED_LED,HIGH); digitalWrite(BUZZER,LOW); } // and here is the code from visual studio private void Button1_Click(object sender, EventArgs e) { serialPort1.WriteLine("0"); }

// Im写一个程序,我要做的一件事就是用按钮点亮arduino上的第一个LED,然后用c#visual studio按钮停止。问题是为什么当我...
c# arduino
1个回答
0
投票
void setup() { // put your setup code here, to run once: Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: if(Serial.available()>0) { String incomingByte=Serial.readString(); if(incomingByte=="0") { digitalWrite(RED_LED,HIGH); digitalWrite(BUZZER,LOW); } } }
© www.soinside.com 2019 - 2024. All rights reserved.