Go Down

Topic: Re: Getting Started with Arduino Create: Project Hub, Web Editor, Device Manager (Read 56 times) previous topic - next topic

neodali

Hello,

I am completely new to Arduino Uno R3.
I have  a  problem with a sketch which gives me errors (I'm french), as follow:

C:\Users\franck\Desktop\SketchesArduinoVol1\Project_8_Memory_game\Project_8_Memory_game.ino:13:31: warning: narrowing conversion of '2' from 'int' to 'boolean {aka bool}' inside { } [-Wnarrowing]

 boolean button[] = {2, 3, 4, 5}; // Pins connected to button inputs

                               ^

C:\Users\franck\Desktop\SketchesArduinoVol1\Project_8_Memory_game\Project_8_Memory_game.ino:13:31: warning: narrowing conversion of '3' from 'int' to 'boolean {aka bool}' inside { } [-Wnarrowing]

C:\Users\franck\Desktop\SketchesArduinoVol1\Project_8_Memory_game\Project_8_Memory_game.ino:13:31: warning: narrowing conversion of '4' from 'int' to 'boolean {aka bool}' inside { } [-Wnarrowing]

C:\Users\franck\Desktop\SketchesArduinoVol1\Project_8_Memory_game\Project_8_Memory_game.ino:13:31: warning: narrowing conversion of '5' from 'int' to 'boolean {aka bool}' inside { } [-Wnarrowing]

C:\Users\franck\Desktop\SketchesArduinoVol1\Project_8_Memory_game\Project_8_Memory_game.ino:14:33: warning: narrowing conversion of '8' from 'int' to 'boolean {aka bool}' inside { } [-Wnarrowing]

 boolean ledpin[] = {8, 9, 10, 11}; // Pins connected to LEDs

                                 ^

C:\Users\franck\Desktop\SketchesArduinoVol1\Project_8_Memory_game\Project_8_Memory_game.ino:14:33: warning: narrowing conversion of '9' from 'int' to 'boolean {aka bool}' inside { } [-Wnarrowing]

C:\Users\franck\Desktop\SketchesArduinoVol1\Project_8_Memory_game\Project_8_Memory_game.ino:14:33: warning: narrowing conversion of '10' from 'int' to 'boolean {aka bool}' inside { } [-Wnarrowing]

C:\Users\franck\Desktop\SketchesArduinoVol1\Project_8_Memory_game\Project_8_Memory_game.ino:14:33: warning: narrowing conversion of '11' from 'int' to 'boolean {aka bool}' inside { } [-Wnarrowing]

the beginning of th sketch is as follow:

#include <Tone.h>
Tone speakerpin;
int starttune[] = {NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_C4,
                   NOTE_F4, NOTE_C4, NOTE_F4, NOTE_G4, NOTE_F4,
                   NOTE_E4, NOTE_F4, NOTE_G4
                  };
int duration2[] = {100, 200, 100, 200, 100, 400, 100, 100, 100, 100,
                   200, 100, 500
                  };
int note[] = {NOTE_C4, NOTE_C4, NOTE_G4, NOTE_C5, NOTE_G4, NOTE_C5};
int duration[] = {100, 100, 100, 300, 100, 300};
boolean button[] = {2, 3, 4, 5}; // Pins connected to button inputs
boolean ledpin[] = {8, 9, 10, 11}; // Pins connected to LEDs
int turn = 0; // Turn counter
int buttonstate = 0; // Check button state
int randomArray[100]; // Array that can store up to 100 inputs
int inputArray[100];
void setup() {
  Serial.begin(9600);
  speakerpin.begin(12); // Pin connected to piezo sounder
  for (int x = 0; x < 4; x++) {
    pinMode(ledpin
  • , OUTPUT); // Set LED pins as output

  }
  for (int x = 0; x < 4; x++) {
    pinMode(button
  • , INPUT); // Set button pins as inputs

    digitalWrite(button
  • , HIGH); // Enable internal pullup;

    // buttons start in high position;
    // logic reversed
  }
  // Generate "more randomness" with randomArray for the output
  // function so pattern is different each time
  randomSeed(analogRead(0));
  for (int thisNote = 0; thisNote < 13; thisNote ++) {
    speakerpin.play(starttune[thisNote]); // Play the next note
    if (thisNote == 0 || thisNote == 2 || thisNote == 4 ||
        thisNote == 6) { // Hold the note
      digitalWrite(ledpin[0], HIGH);
    }
    if (thisNote == 1 || thisNote == 3 || thisNote == 5 ||
        thisNote == 7 || thisNote == 9 || thisNote == 11) {
      digitalWrite(ledpin[1], HIGH);
    }
    if (thisNote == 8 || thisNote == 12) {
      digitalWrite(ledpin[2], HIGH);
    }
    if (thisNote == 10) {
      digitalWrite(ledpin[3], HIGH);
    }
    delay(duration2[thisNote]);
    speakerpin.stop(); // Stop for the next note
    digitalWrite(ledpin[0], LOW);
    digitalWrite(ledpin[1], LOW);
    digitalWrite(ledpin[2], LOW);
    digitalWrite(ledpin[3], LOW);
    delay(25);
  }
  delay(1000);

What's wrong?
Kindest regards
Libertariennist, psychiatrist, psychoanalyst, freemason, & novel writer, the older i come the more people can F****off

supercc

Bonsoir,

remplace :

  boolean ledpin[] = {8, 9, 10, 11}; // Pins connected to LEDs

par

 int ledpin[] = {8, 9, 10, 11}; // Pins connected to LEDs

pareil pour les boutons (button).


Go Up