Hi C++ Devs and StackOverflow users!
The code following is what I did, but some reason, random function doesn't work, or output for a result always the same value which is '1', did I do anything wrong? How should I fix this issue?
void setup()
{
int randNumber;
int i;
randNumber = random(2);
Serial.println(randNumber);
pinMode(PIEZO, OUTPUT);
delay(3000);
if (randNumber == 0)
{
for (i = 0; i < 105; i++)
{
tone(PIEZO, notes[i], time[i]);
delay(time[i]);
}
}
else if (randNumber == 1)
for (i = 0; i < 116; i++)
{
tone(PIEZO, Snowman_Notes[i], Snowman_Rhythm[i]);
delay(Snowman_Rhythm[i]);
}
}
void loop()
{
}
Aucun commentaire:
Enregistrer un commentaire