Coding Otherside from Minecraft in Arduino

I'm fairly new with Arduino coding, so don't expect me to understand everything you say. Anyway, arduino is responding to me trying to verify my code with these error messages.
/tmp/ccyVlHcG.ltrans0.ltrans.o: In function `main':

/home/builder/.arduino15/packages/arduino/hardware/avr/1.8.4/cores/arduino/main.cpp:43: undefined reference to setup' /home/builder/.arduino15/packages/arduino/hardware/avr/1.8.4/cores/arduino/main.cpp:46: undefined reference to loop'
collect2: error: ld returned 1 exit status
Error during build: exit status 1

I've been using the Arduino Web Editor, so that may be why, however I do not know. Any help would be appreciated.

My current code is this:
/*************************************************

  • Public Constants
    *************************************************/

#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978

int melody [] = {NOTE_C3, NOTE_G3, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_G3, NOTE_A3, NOTE_G3, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_G3, NOTE_F2, NOTE_G3, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_G3, NOTE_G2, NOTE_G3, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_G3};

An Arduino sketch needs a loop() function, even if it is empty.
And a setup() function.
Please remember to use code tags when posting code

The code you posted, even if it did compile, does nothing because there is no actual code. You must have a setup() and a loop() function to process the melody.

Thanks so much, now the code works; however, it doesn't play, or if it does, I cannot hear it.

I think you need to explain what "works" means.
And post the code as it looks now.

it doesn't play doesn't seem to fit the definition of work.

If we could see your code we might be able to help. Also what is your output device? Piezo or active speaker?

By works, I mean that the code says Successful and that it uploaded.
I tried using code tags but I don't really know how to use them
Code:



/*************************************************
 * Public Constants
 *************************************************/

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978
void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

int melody [] = {NOTE_C3, NOTE_G3, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_G3, NOTE_A3, NOTE_G3, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_G3, NOTE_F2, NOTE_G3, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_G3, NOTE_G2, NOTE_G3, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_G3}

Piezo buzzer, I could send you a picture of my wiring if you'd like?

When I said loop() can be empty, I didn't mean it has to be.

You have no code to produce the tones and I don't see where you specify the length of each note, unless you want them to all be the same length.

What pin is the piezo connected to?

Would you recommend I put the melody inside of loop?

setup() executes one time. loop() executes over and over again. Do you want the melody to play once or over and over again?

Piezo is connected to pin 8 and Ground; I'm not using a breadboard

Loop for sure

Start here: https://www.arduino.cc/reference/en/language/functions/advanced-io/tone/

and here: https://www.arduino.cc/en/Tutorial/BuiltInExamples/toneMelody

Hello, I'm currently doing trying to code Otherside from Minecraft in arduino, and whenever I upload my code to the arduino, the sound doesn't play. I'm using a passive buzzer with the Arduino web editor. I'm super new to coding with arduino, so don't expect me to understand everything. Here's the code:

`
pitches.h library, too long to type out
int piezo = 8;
void setup() {
// put your setup code here, to run once:
pinMode(piezo, OUTPUT);
for (int thisNote = 0; thisNote < 8; thisNote++) {
int noteDuration = 1000 / noteDurations[thisNote];

tone(8, melody[thisNote], noteDuration);

}

void loop() {
// put your main code here, to run repeatedly:
int melody [] = {NOTE_C3, NOTE_G3, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_G3, NOTE_A3, NOTE_G3, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_G3, NOTE_F2, NOTE_G3, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_G3, NOTE_G2, NOTE_G3, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_G3};
int noteDurations[] = {
4, 16, 16, 16, 8, 8, 4, 16, 16, 16, 8, 8, 4, 16, 16, 16, 8, 8, 4, 16, 16, 16, 8, 8, 4, 16, 16, 16, 8, 8, 4, 16, 16, 16, 8, 8, 4, 16, 16, 16, 8, 8, 4, 16, 16, 16, 8, 8, 4, 16, 16, 16, 8, 8
};
}`

I don't understand that phrase.

There is example code for the tone function.
Your code should look more like it - the code you posted has no hope of compiling for simple scope reasons.

Please remember to use code tags when posting code.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.