我有我的代碼設置,以便當我按下某個按鈕時,具體的值被添加到:int finalVal = 0;但是當我看看Seral Monitor時,它將finalVal表示爲0.我的目標是創建一種類似密碼的系統,如果按正確順序按下右按鈕,則按鈕將點亮。int對Arduino的值不變
我的代碼:
const int button1 = 2;
const int button2 = 3;
const int button3 = 4;
const int led = 13;
int button1Val = 5.43678;
int button2Val = 1.287953156;
int button3Val = 3.141592;
int finalVal = 0;
void setup()
{
Serial.begin(9600);
pinMode(button1, INPUT);
pinMode(button2, INPUT);
pinMode(button3, INPUT);
pinMode(led, OUTPUT);
}
void loop()
{
Serial.println(finalVal);
int button1St, button2St, button3St;
button1St = digitalRead(button1);
button2St = digitalRead(button2);
button3St = digitalRead(button3);
if ((button1St == LOW))
{
finalVal + button1Val;
}
else
{
digitalWrite(led, HIGH);
delay(300);
}
if ((button1St == LOW))
{
finalVal + button2Val;
}
else
{
digitalWrite(led, HIGH);
delay(300);
}
if ((button1St == LOW))
{
finalVal + button3Val;
}
else
{
digitalWrite(led, HIGH);
delay(300);
}
if ((finalVal == 25.169430312))
{
digitalWrite(led, LOW);
}
else
{
digitalWrite(led, HIGH);
delay(300);
}
}