Help! Getting an error message with a code language I have no idea how to speak

Hi All,

I'm taking an Audio Electronics course which involves an Arduino UNO. The problem is, the code for this project I'm building was made 5 years ago, and I have no idea how to fix the code to work for Arduino today. The project is a DIY MIDI controller called the SugarCube Synth (https://www.instructables.com/id/Sugarcube-MIDI-Controller/).

After completely copying all of the code that the original builder coded for the project, I still keep getting an error message of:

/var/folders/ly/t44swsyn56ldvv0_12hnp76h0000gn/T//cc44r57c.ltrans0.ltrans.o: In function main': /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/main.cpp:43: undefined reference to setup'
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/main.cpp:46: undefined reference to `loop'
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Uno.

Below is the code I'm trying to upload:
// /*
// StepSequencer.cpp
// Created by Amanda Ghassaei, Mar 2, 2013.
// */

#include "SugarCube.h"

StepSequencer::StepSequencer()
{
_tempoTimer = 0;
_maxTempo = this->maxTempoFromPotVal(_sugarcube->getPot2Val());
_xOffset = xOffsetFromPotVal(_sugarcube->getPot1Val());
_playhead = absolutePosition(15);//start at -1

_velocity = 100;
//change these to change available notes
_notes[3] = 72;
_notes[2] = 67;
_notes[1] = 63;
_notes[0] = 60;

this->clearAllStorage();
}

void StepSequencer::routine100kHz()
{
if (_tempoTimer++>_maxTempo){
_tempoTimer = 0;
this->incrementPlayhead();
}
}

void StepSequencer::buttonPressed(byte xPos, byte yPos)
{
byte colState = _seqStates[this->absolutePosition(xPos)];
if (colState & 1<<(3-yPos)){//if already on
colState &= ~(1<<(3-yPos));//turn off
_sugarcube->turnOffLED(xPos, yPos);
} else {
colState |= (1<<(3-yPos));//turn on
_sugarcube->turnOnLED(xPos, yPos);
}
_seqStates[this->absolutePosition(xPos)] = colState;
}

byte StepSequencer::absolutePosition(byte pos)
{
return (pos+_xOffset)&15;
}

byte StepSequencer::relativePosition()
{
return (_playhead+16-_xOffset)&15;
}

void StepSequencer::pot1HasChanged(int val)
{
_xOffset = xOffsetFromPotVal(val);
for (byte i=0;i<4;i++){
_sugarcube->setLEDCol(i, _seqStates[this->absolutePosition(i)]);
}
if (this->relativePosition()<4) _sugarcube->setLEDCol(this->relativePosition(), 15);//turn on column
}

void StepSequencer::pot2HasChanged(int val)
{
_maxTempo = this->maxTempoFromPotVal(val);
}

byte StepSequencer::maxTempoFromPotVal(int val)//10 bit val
{
return ((val>>6) + 1)*5;
}

void StepSequencer::incrementPlayhead()
{
if (this->relativePosition()<4)_sugarcube->setLEDCol(this->relativePosition(), _seqStates[_playhead]);//set col to original state
this->playNotesForStates(_seqStates[_playhead], false);
_playhead++;
if (_playhead>15) _playhead = 0;
if (this->relativePosition()<4) _sugarcube->setLEDCol(this->relativePosition(), 15);//turn on column
this->playNotesForStates(_seqStates[_playhead], true);
}

void StepSequencer::playNotesForStates(byte column, boolean noteOn)
{
for (byte i=0;i<4;i++){
if (column & 1<<i){
if (noteOn){
_sugarcube->noteOn(_notes*, _velocity);*

  • } else {*
    _sugarcube->noteOff(notes*);
    _
    }*

    * }*
    * }*
    * }*

* void StepSequencer::wasShaken()*
* {*
* this->clearAllStorage();*
* for (byte i=0;i<4;i++){*
sugarcube->noteOff(notes*);//turn off any notes that might be stuck on*
* }*

* sugarcube->clearLEDs();
if (this->relativePosition()<4) sugarcube->setLEDCol(this->relativePosition(), 15);//turn on column*
* }*

* void StepSequencer::clearAllStorage()*
* {*
* for (byte i=0;i<16;i++){*
seqStates = 0;
* }
}*

I've included all of the extra .h files I needed.
If anyone has time to look at this, I'd really appreciate the help. My project is due next week, and I'm beginning to panic. I've been trying to figure out how to fix this myself, but I have no idea how to even begin to read any computer code, let alone Arduino code.
Thanks so much in advance._

Please read the instructions for posting code. The forum software thinks some of your code is in italics.

I don't see loop() or setup() in that code. It looks like it is just one file from the project. There should be a .ino file. If it is really old, a .pde file.

I don't think this is an Arduino project file, but a library, this is sugarcube.cpp, there should be a sugarcube.h . the library probably works, but this is not a project file.

All the code is at the Git Hub page linked in the Instructable: GitHub - amandaghassaei/Sugarcube-Arduino-Library: A grid-based midi instrument, with accelerometer and gyroscope for playful interactions

It looks like a large project. On the bright side, it seems to be one of the more complete and well-written Instructable I've seen (but, I just did a quick scan). Many Instructables related to Arduino projects are complete crap.

However, It's not clear to me that pulling it all together by next week is a realistic goal given OP's apparent experience level.

Thanks for the responses. I am using the Arduino code given to me directly from the original creator and I'm still getting these error messages. :confused:

jessicacory21:
I am using the Arduino code given to me directly from the original creator

The compiler begs to differ. Your code is missing the required setup() and loop() functions. If the only code you have is what you posted, you only have one file out of the ~20 files that are on the Git Hub.

Don't panic! :slight_smile:

I have had a look at the code on Github and it looks like it was well done. The Instructable looks like it is good quality as well, so it is probably something that is not right in your development environment.

Starting with the obvious, the first thing to check is that you have downloaded all the files and have them in a subfolder off the Arduino Sketchbook folder. You should be able to download all the files as a zip and then unzip them into the folder (say SugarCube). Download the zip file from the browser button at the top right of the Github page. It would be worth doing this again even if you think you did it the first time as you may have missed some files - you need all the files on the Github site.

You use the IDE to open the .ino file in the SugarCube folder and compile that. The setup() and loop() functions are actually in this file. All the other files should be pulled in automatically. If you get no errors the problem is fixed.

If you still get errors, you should copy all the error output back into here and we can then start from a known base.

marco_c:
Don't panic! :slight_smile:

I have had a look at the code on Github and it looks like it was well done. The Instructable looks like it is good quality as well, so it is probably something that is not right in your development environment.

Starting with the obvious, the first thing to check is that you have downloaded all the files and have them in a subfolder off the Arduino Sketchbook folder. You should be able to download all the files as a zip and then unzip them into the folder (say SugarCube). Download the zip file from the browser button at the top right of the Github page. It would be worth doing this again even if you think you did it the first time as you may have missed some files - you need all the files on the GitHub site.

You use the IDE to open the .ino file in the SugarCube folder and compile that. The setup() and loop() functions are actually in this file. All the other files should be pulled in automatically. If you get no errors the problem is fixed.

If you still get errors, you should copy all the error output back into here and we can then start from a known base.

Marco, thank you so much! I did discover that I was missing the actual library file, and just had a bunch of .cpp files and .h files floating around. I believe I need to upload this whole file to my Arduino? I changed one code that appeared to be an outdated command and now my code uploads completely. However, I'm still not getting any control out of the actual device. I know the test codes work, but the actual programs are still not working. Any ideas here?

I changed one code that appeared to be an outdated command and now my code uploads completely

What was that?

Without some debug/additional information it will be hard for anyone else to determine what the issue might be. What do you expect to see and what is happening?

As I understand it, nothing happens when you fire up the software until you select the mode you want to run by pressing one of the cubes.

@marco_c

The command I changed had something to do with an outdated command for "Include." My professor helped me change it, so I don't quite remember what it was.

I also understand the program to run once you hit one of the cubes. The problem is, the code uploads to the Arduino now with no problems, but the cube isn't sending data to run the programs once a button is pressed. Nothing happens except sometimes when I upload the code, I get a random number of LEDs to turn on. Sometimes it's 6, sometimes all 16, and sometimes none.

My suggestion is that there is probably something not wired correctly in the hardware, so really give this a good check first. Make sure that all the intermediate 'test' programs run correctly.

If all that fails, then you will need to find someone who can help you with the hardware/software by working on it with you (ie, in the same room). This is not going to be something you can debug remotely. This is now in the debugging stage and it is hard to do on a forum, especially if you are still coming up a steep learning curve on this stuff, by yourself.

Yes, a large project. The examples shown in the instructable are all complex.

When you are wiring up new hardware, test every little piece with a short program. Can you make just one of the LEDs blink? Save that program. You are going to need it again.

Next, can you make all the LEDs blink? One might be wired backwards.

Test the buttons.

Test everything individually.