Welcome to the MIDI Sprout forum

Author Topic: Error while uploading midi sprout code  (Read 159 times)

Offline LoloB

  • Newbie
  • *
  • Posts: 1
    • View Profile
Error while uploading midi sprout code
« on: November 04, 2017, 09:38:51 AM »
Hi fellows,
I build my own midi sprout on a breadboard, following the video tutorials provided, since so far I had been unlucky with being able to order a ready-made sprout kit. I use a Atmega328p-pu chip that already has a bootloader. When I try to upload the psychogalvanometer code, i always get an error, which inhibits the uploading. I dont really understand how this is not declared in the sketch - should it be declared before the setup function?? the error message goes as follows:
(I provide the code after the error message)


In function 'void setup()':

MIDI_Psychogalv_328p_v021:89: error: 'checkBattery' was not declared in this scope

   checkBattery(); // shut off lightshow if power is too low

                ^

MIDI_Psychogalv_328p_v021:90: error: 'bootLightshow' was not declared in this scope

   if(noteLEDs) bootLightshow(); //a light show to display on system boot

                              ^

MIDI_Psychogalv_328p_v021:91: error: 'sample' was not declared in this scope

   attachInterrupt(interruptPin, sample, RISING);  //begin sampling from interrupt

                                 ^
In function 'void loop()':

MIDI_Psychogalv_328p_v021:98: error: 'checkBattery' was not declared in this scope

   checkBattery(); //on low power, shutoff lightShow, continue MIDI operation

                ^

MIDI_Psychogalv_328p_v021:99: error: 'checkKnob' was not declared in this scope

   checkKnob(); //check knob value

             ^

MIDI_Psychogalv_328p_v021:100: error: 'analyzeSample' was not declared in this scope

   if(index >= samplesize)  { analyzeSample(); }  //if samples array full, also checked in analyzeSample(), call sample analysis   

                                            ^

MIDI_Psychogalv_328p_v021:101: error: 'checkNote' was not declared in this scope

   checkNote();  //turn off expired notes

             ^

MIDI_Psychogalv_328p_v021:102: error: 'checkControl' was not declared in this scope

   checkControl();  //update control value

                ^

MIDI_Psychogalv_328p_v021:104: error: 'checkLED' was not declared in this scope

   checkLED();  //LED management without delay()

            ^

exit status 1
'checkBattery' was not declared in this scope


Code:

Code: [Select]
#include <LEDFader.h> //manage LEDs without delay() jgillick/arduino-LEDFader https://github.com/jgillick/arduino-LEDFader.git

//******************************
//set scaled values, sorted array, first element scale length
int scaleMajor[]  = {7,1, 3, 5, 6, 8, 10, 12};
int scaleDiaMinor[]  = {7,1, 3, 4, 6, 8, 9, 11};
int scaleIndian[]  = {7,1, 2, 2, 5, 6, 9, 11};
int scaleMinor[]  = {7,1, 3, 4, 6, 8, 9, 11};
int scaleChrom[] = {12,1,2,3,4,5,6,7,8,9,10,11,12};
int *scaleSelect = scaleChrom; //initialize scaling
int root = 0; //initialize for root
//*******************************

const byte interruptPin = INT0; //galvanometer input
const byte knobPin = A0; //knob analog input

const byte samplesize = 10; //set sample array size
const byte analysize = samplesize - 1;  //trim for analysis array

const byte polyphony = 5; //above 8 notes may run out of ram
byte channel = 1;  //setting channel to 11 or 12 often helps simply computer midi routing setups
int noteMin = 36; //C2  - keyboard note minimum
int noteMax = 96; //C7  - keyboard note maximum
byte QY8= 0;  //sends each note out chan 1-4, for use with General MIDI like Yamaha QY8 sequencer
byte controlNumber = 80; //set to mappable control, low values may interfere with other soft synth controls!!
byte controlVoltage = 1; //output PWM CV on controlLED, pin 17, PB3, digital 11 *lowpass filter
long batteryLimit = 3000; //voltage check minimum, 3.0~2.7V under load; causes lightshow to turn off (save power)
byte checkBat = 1;

volatile unsigned long microseconds; //sampling timer
volatile byte index = 0;
volatile unsigned long samples[samplesize];

float threshold = 2.3;  //change threshold multiplier
float threshMin = 1.61; //scaling threshold min
float threshMax = 3.71; //scaling threshold max
float knobMin = 1;
float knobMax = 1023;

unsigned long previousMillis = 0;
unsigned long currentMillis = 1;
unsigned long batteryCheck = 0; //battery check delay timer
 
#define LED_NUM 6
LEDFader leds[LED_NUM] = { // 6 LEDs (perhaps 2 RGB LEDs)
  LEDFader(3),
  LEDFader(5),
  LEDFader(6),
  LEDFader(9),
  LEDFader(10),
  LEDFader(11)  //Control Voltage output or controlLED
};
int ledNums[LED_NUM] = {3,5,6,9,10,11};
byte controlLED = 5; //array index of control LED (CV out)
byte noteLEDs = 1;  //performs lightshow set at noteOn event

typedef struct _MIDImessage { //build structure for Note and Control MIDImessages
  unsigned int type;
  int value;
  int velocity;
  long duration;
  long period;
  int channel;
}
MIDImessage;
MIDImessage noteArray[polyphony]; //manage MIDImessage data as an array with size polyphony
int noteIndex = 0;
MIDImessage controlMessage; //manage MIDImessage data for Control Message (CV out)


void setup()
{
  pinMode(knobPin, INPUT);
  randomSeed(analogRead(0)); //seed for QY8
  Serial.begin(31250);  //initialize at MIDI rate
  controlMessage.value = 0;  //begin CV at 0
  //MIDIpanic(); //dont panic, unless you are sure it is nessisary
  checkBattery(); // shut off lightshow if power is too low
  if(noteLEDs) bootLightshow(); //a light show to display on system boot
  attachInterrupt(interruptPin, sample, RISING);  //begin sampling from interrupt
 
}

void loop()
{
  currentMillis = millis();   //manage time
  checkBattery(); //on low power, shutoff lightShow, continue MIDI operation
  checkKnob(); //check knob value
  if(index >= samplesize)  { analyzeSample(); }  //if samples array full, also checked in analyzeSample(), call sample analysis   
  checkNote();  //turn off expired notes
  checkControl();  //update control value
  //checkButton();  //not implemented in this build
  checkLED();  //LED management without delay()
  previousMillis = currentMillis;   //manage time
}



Offline sam

  • Sam
  • Moderator
  • Full Member
  • *****
  • Posts: 147
  • Understand How Your Tools Work!
    • View Profile
    • Electricity for Progress
Re: Error while uploading midi sprout code
« Reply #1 on: November 08, 2017, 02:59:08 PM »
I'm very glad that you have 'rolled your own' biodata sonification system. 

Your compiling issue in the Arduino IDE can be easily solved by changing the 'board' to 'Arduino Uno'.  You likely have a board profile for a 'Naked 328p on a breadboard', which would need the battery code to appear above the setup() function.  Change the board and recompile!

-sam