我目前正在开展一个小型的Arduino项目,我有点卡住了。到目前为止,这是我的代码:
#include "_init.h"
void setup() {
ds_init();
Serial.begin(9600);
randomSeed(analogRead(LIGHT_SENSOR_PIN));
int rol1[] = {1, 2, 3, 4, 5};
int rol2[] = {3, 5, 1, 2, 4};
int rol3[] = {5, 1, 4, 3, 2};
int rol1Mid = random(0, 5);
int rol1Bov = rol1Mid + 1;
int rol1Ond = rol1Mid - 1;
if (rol1Bov == 5){
rol1Bov = 0;
}
if (rol1Ond == -1){
rol1Ond = 4;
}
int rol2Mid = random(0, 5);
int rol2Bov = rol2Mid + 1;
int rol2Ond = rol2Mid - 1;
if (rol2Bov == 5){
rol2Bov = 0;
}
if (rol2Ond == -1){
rol2Ond = 4;
}
int rol3Mid = random(0, 5);
int rol3Bov = rol3Mid + 1;
int rol3Ond = rol3Mid - 1;
if (rol3Bov == 5){
rol3Bov = 0;
}
if (rol3Ond == -1){
rol3Ond = 4;
}
Serial.println(rol1[rol1Bov]);
Serial.println(rol1[rol1Mid]);
Serial.println(rol1[rol1Ond]);
Serial.println("----");
Serial.println(rol2[rol2Bov]);
Serial.println(rol2[rol2Mid]);
Serial.println(rol2[rol2Ond]);
Serial.println("----");
Serial.println(rol3[rol3Bov]);
Serial.println(rol3[rol3Mid]);
Serial.println(rol3[rol3Ond]);
if(rol1[rol1Mid] && rol2[rol2Mid] == rol3[rol3Mid]){
Serial.println("Yaay!");
} else {
Serial.println("Jammer, probeer het nogmaals.");
}
/*
if(rol1[positieBov] && rol2[positieBov] == rol3[positieBov]){
Serial.println("Yaay!");
} else {
Serial.println("Jammer, probeer het nogmaals.");
}
if(rol1[positieOnd] && rol2[positieOnd] == rol3[positieOnd]){
Serial.println("Yaay!");
} else {
Serial.println("Jammer, probeer het nogmaals.");
}
*/
}
void loop() {
// put your main code here, to run repeatedly:
}
基本上,我正在尝试创建一台老虎机。我的代码可能有很多问题,但目前我仍然坚持使用if语句检查用户是否获胜。
我知道我不应该在Arduino的setup()部分编码,但是一旦这一切都有效,我将把它放在loop()中的一个函数中,我将使用我的dangershield的按钮来分别操作三卷。
答案 0 :(得分:1)
好的,设法解决它......我现在感到愚蠢
if(rol1[rol1Mid] == rol2[rol2Mid] && rol2[rol2Mid] == rol3[rol3Mid])